summaryrefslogtreecommitdiffabout
path: root/content/fireflix.js
Unidiff
Diffstat (limited to 'content/fireflix.js') (more/less context) (ignore whitespace changes)
-rw-r--r--content/fireflix.js12
1 files changed, 8 insertions, 4 deletions
diff --git a/content/fireflix.js b/content/fireflix.js
index 24894df..48053c5 100644
--- a/content/fireflix.js
+++ b/content/fireflix.js
@@ -1,622 +1,626 @@
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 this.selection.clearSelection();
136 }, 136 },
137 load_photos: function(psid) { 137 load_photos: function(psid) {
138 var _this = this; 138 var _this = this;
139 this.fireflix.flickr.api_call( 139 this.fireflix.flickr.api_call(
140 { 140 {
141 method: 'flickr.photosets.getPhotos', 141 method: 'flickr.photosets.getPhotos',
142 auth_token: 'default', 142 auth_token: 'default',
143 photoset_id: psid, 143 photoset_id: psid,
144 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'
145 }, function(xr) { 145 }, function(xr) {
146 var x = xr.responseXML; 146 var x = xr.responseXML;
147 var xp = x.evaluate( 147 var xp = x.evaluate(
148 '/rsp/photoset/photo', x, null, 148 '/rsp/photoset/photo', x, null,
149 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 149 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
150 _this.importXPR(xp); 150 _this.importXPR(xp);
151 }, function(x,s,c,m) { 151 }, function(x,s,c,m) {
152 _this.fireflix.flickr_failure(x,s,c,m); 152 _this.fireflix.flickr_failure(x,s,c,m);
153 } 153 }
154 ); 154 );
155 }, 155 },
156 on_select: function() { 156 on_select: function() {
157 if(this.selection.count==1) { 157 if(this.selection.count==1) {
158 var p = this.photos[this.selection.currentIndex]; 158 var p = this.photos[this.selection.currentIndex];
159 this.set_photo.src = 159 this.set_photo.src =
160 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');
161 this.set_photo.hidden = false; 161 this.set_photo.hidden = false;
162 }else{ 162 }else{
163 this.set_photo.hidden = true; 163 this.set_photo.hidden = true;
164 } 164 }
165 }, 165 },
166 on_cmd_open: function(ev) { 166 on_cmd_open: function(ev) {
167 if(this.selection.currentIndex<0) 167 if(this.selection.currentIndex<0) return;
168 return;
169 var p = this.photos[this.selection.currentIndex]; 168 var p = this.photos[this.selection.currentIndex];
170 if(!p.id) 169 if(!p.id) return;
171 return;
172 this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); 170 this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p'));
173 } 171 }
174 }, 172 },
175 173
176 /* photosets treeview */ 174 /* photosets treeview */
177 photosets: { 175 photosets: {
178 sets: new Array(), 176 sets: new Array(),
179 fireflix: null, 177 fireflix: null,
180 init: function(f) { 178 init: function(f) {
181 this.fireflix = f; 179 this.fireflix = f;
182 document.getElementById('setslist').view = this; 180 document.getElementById('setslist').view = this;
183 }, 181 },
184 rowCount: 0, 182 rowCount: 0,
185 getCellText: function(r,c) { 183 getCellText: function(r,c) {
186 var s = this.sets[r]; 184 var s = this.sets[r];
187 if(c.id=='sl_name') return s.title; 185 if(c.id=='sl_name') return s.title;
188 if(c.id=='sl_photos') return s.photos; 186 if(c.id=='sl_photos') return s.photos;
189 return c.id; 187 return c.id;
190 }, 188 },
191 setTree: function(t) { this.tree = t }, 189 setTree: function(t) { this.tree = t },
192 isContainer: function(r) { return false; }, 190 isContainer: function(r) { return false; },
193 isSeparator: function(r) { return false; }, 191 isSeparator: function(r) { return false; },
194 isSorted: function() { return false; }, 192 isSorted: function() { return false; },
195 getLevel: function(r) { return 0; }, 193 getLevel: function(r) { return 0; },
196 getImageSrc: function(r,c) { return null }, 194 getImageSrc: function(r,c) { return null },
197 getRowProperties: function(r,p) {}, 195 getRowProperties: function(r,p) {},
198 getCellProperties: function(cid,cel,p) { }, 196 getCellProperties: function(cid,cel,p) { },
199 getColumnProperties: function(cid,cel,p) { }, 197 getColumnProperties: function(cid,cel,p) { },
200 cycleHeader: function(cid,e) { }, 198 cycleHeader: function(cid,e) { },
201 getParentIndex: function(r) { return -1; }, 199 getParentIndex: function(r) { return -1; },
202 drop: function(r,o) { }, 200 drop: function(r,o) { },
203 canDropBeforeAfter: function(r,b) { return false }, 201 canDropBeforeAfter: function(r,b) { return false },
204 202
205 importXPR: function(xp) { 203 importXPR: function(xp) {
206 this.tree.beginUpdateBatch(); 204 this.tree.beginUpdateBatch();
207 this.sets = new Array(); 205 this.sets = new Array();
208 var n; while(n=xp.iterateNext()) { 206 var n; while(n=xp.iterateNext()) {
209 this.sets.push(new Photoset(n)); 207 this.sets.push(new Photoset(n));
210 } 208 }
211 this.rowCount = this.sets.length; 209 this.rowCount = this.sets.length;
212 this.tree.endUpdateBatch(); 210 this.tree.endUpdateBatch();
213 }, 211 },
214 refresh_sets: function() { 212 refresh_sets: function() {
215 var _this = this; 213 var _this = this;
216 this.fireflix.flickr.api_call( 214 this.fireflix.flickr.api_call(
217 { 215 {
218 method: 'flickr.photosets.getList', 216 method: 'flickr.photosets.getList',
219 auth_token: 'default' 217 auth_token: 'default'
220 }, function(xr) { 218 }, function(xr) {
221 var x = xr.responseXML; 219 var x = xr.responseXML;
222 var xp = x.evaluate( 220 var xp = x.evaluate(
223 '/rsp/photosets/photoset', x, null, 221 '/rsp/photosets/photoset', x, null,
224 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 222 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
225 _this.importXPR(xp); 223 _this.importXPR(xp);
226 }, function(x,s,c,m) { 224 }, function(x,s,c,m) {
227 _this.fireflix.flickr_failure(x,s,c,m); 225 _this.fireflix.flickr_failure(x,s,c,m);
228 } 226 }
229 ); 227 );
230 }, 228 },
231 on_select: function() { 229 on_select: function() {
232 if(this.selection.count==1) { 230 if(this.selection.count==1) {
233 this.fireflix.cmd_set_props.setAttribute('disabled','false'); 231 this.fireflix.cmd_set_props.setAttribute('disabled','false');
234 var s = this.sets[this.selection.currentIndex]; 232 var s = this.sets[this.selection.currentIndex];
235 this.fireflix.photoset.load_photos(s.id); 233 this.fireflix.photoset.load_photos(s.id);
236 }else{ 234 }else{
237 this.fireflix.cmd_set_props.setAttribute('disabled','true'); 235 this.fireflix.cmd_set_props.setAttribute('disabled','true');
238 } 236 }
237 },
238 on_cmd_open_in_flickr: function(ev) {
239 if(this.selection.currentIndex<0) return;
240 var p = this.sets[this.selection.currentIndex];
241 if(!p.id) return;
242 this.fireflix.openTab(this.fireflix.flickr.make_photoset_url(p));
239 } 243 }
240 }, 244 },
241 245
242 refresh_user_tags: function() { 246 refresh_user_tags: function() {
243 var lb = document.getElementById('tagslist'); 247 var lb = document.getElementById('tagslist');
244 var _this = this; 248 var _this = this;
245 this.flickr.api_call( 249 this.flickr.api_call(
246 { 250 {
247 method: 'flickr.tags.getListUser', 251 method: 'flickr.tags.getListUser',
248 auth_token: 'default', 252 auth_token: 'default',
249 }, function(xr) { 253 }, function(xr) {
250 var x = xr.responseXML; 254 var x = xr.responseXML;
251 var xp = x.evaluate( 255 var xp = x.evaluate(
252 '/rsp/who/tags/tag', x, null, 256 '/rsp/who/tags/tag', x, null,
253 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 257 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
254 // TODO: clear list 258 // TODO: clear list
255 var n; while(n=xp.iterateNext()) { 259 var n; while(n=xp.iterateNext()) {
256 lb.appendItem(n.firstChild.nodeValue); 260 lb.appendItem(n.firstChild.nodeValue);
257 } 261 }
258 }, function(x,s,c,m) { 262 }, function(x,s,c,m) {
259 _this.flickr_failure(x,s,c,m); 263 _this.flickr_failure(x,s,c,m);
260 } 264 }
261 ); 265 );
262 }, 266 },
263 267
264 uploadObserver: { 268 uploadObserver: {
265 fireflix: null, 269 fireflix: null,
266 init: function(f) { 270 init: function(f) {
267 this.fireflix = f; 271 this.fireflix = f;
268 }, 272 },
269 getSupportedFlavours: function() { 273 getSupportedFlavours: function() {
270 var rv = new FlavourSet(); 274 var rv = new FlavourSet();
271 rv.appendFlavour('application/x-moz-file','nsIFile'); 275 rv.appendFlavour('application/x-moz-file','nsIFile');
272 rv.appendFlavour('application/x-moz-url'); 276 rv.appendFlavour('application/x-moz-url');
273 rv.appendFlavour('text/uri-list'); 277 rv.appendFlavour('text/uri-list');
274 rv.appendFlavour('text/unicode'); 278 rv.appendFlavour('text/unicode');
275 return rv; 279 return rv;
276 }, 280 },
277 canHandleMultipleItems: true, 281 canHandleMultipleItems: true,
278 onDragOver: function(ev,fl,sess) { 282 onDragOver: function(ev,fl,sess) {
279 return true; 283 return true;
280 }, 284 },
281 onDrop: function(ev,dd,s) { 285 onDrop: function(ev,dd,s) {
282 var ldf = null; 286 var ldf = null;
283 for(var i in dd.dataList) { 287 for(var i in dd.dataList) {
284 var di = dd.dataList[i]; 288 var di = dd.dataList[i];
285 var dif = di.first; 289 var dif = di.first;
286 if( 290 if(
287 ldf==null 291 ldf==null
288 || ldf.flavour.contentType!=dif.flavour.contentType 292 || ldf.flavour.contentType!=dif.flavour.contentType
289 || ldf.contentLength!=dif.contentLength 293 || ldf.contentLength!=dif.contentLength
290 || ldf.data!=dif.data ) 294 || ldf.data!=dif.data )
291 this.drop_item(ev,di,s); 295 this.drop_item(ev,di,s);
292 ldf = dif; 296 ldf = dif;
293 } 297 }
294 }, 298 },
295 drop_item: function(ev,di,s) { 299 drop_item: function(ev,di,s) {
296 var d = di.first; 300 var d = di.first;
297 switch(d.flavour.contentType) { 301 switch(d.flavour.contentType) {
298 case 'text/unicode': 302 case 'text/unicode':
299 this.drop_urilist(ev,d.data,s); 303 this.drop_urilist(ev,d.data,s);
300 break; 304 break;
301 case 'application/x-moz-file': 305 case 'application/x-moz-file':
302 this.fireflix.uploads.add(d.data.path); 306 this.fireflix.uploads.add(d.data.path);
303 document.getElementById('fireflix_tabs').selectedTab 307 document.getElementById('fireflix_tabs').selectedTab
304 = document.getElementById('tab_upload'); 308 = document.getElementById('tab_upload');
305 break; 309 break;
306 case 'text/uri-list': 310 case 'text/uri-list':
307 // is it ascii or could it be utf8? 311 // is it ascii or could it be utf8?
308 this.drop_urilist(ev,splitascii(d.data),s); 312 this.drop_urilist(ev,splitascii(d.data),s);
309 break; 313 break;
310 default: alert(d.flavour.contentType+':'+d.data); break; 314 default: alert(d.flavour.contentType+':'+d.data); break;
311 }; 315 };
312 }, 316 },
313 drop_urilist: function(ev,ul,s) { 317 drop_urilist: function(ev,ul,s) {
314 // TODO: check for being a file? 318 // TODO: check for being a file?
315 var us = decodeURIComponent(ul).split(/[\r\n]/); 319 var us = decodeURIComponent(ul).split(/[\r\n]/);
316 for(var ui in us) 320 for(var ui in us)
317 if(/\S/.test(us[ui])) 321 if(/\S/.test(us[ui]))
318 this.fireflix.uploads.add(us[ui]); 322 this.fireflix.uploads.add(us[ui]);
319 document.getElementById('fireflix_tabs').selectedTab 323 document.getElementById('fireflix_tabs').selectedTab
320 = document.getElementById('tab_upload'); 324 = document.getElementById('tab_upload');
321 } 325 }
322 }, 326 },
323 327
324 uploads: { 328 uploads: {
325 fireflix: null, 329 fireflix: null,
326 init: function(f) { 330 init: function(f) {
327 this.fireflix=f; 331 this.fireflix=f;
328 pull_elements(this,document,[ 332 pull_elements(this,document,[
329 'upload_filename','upload_title','upload_file_preview', 333 'upload_filename','upload_title','upload_file_preview',
330 'upload_file_props','upload_progress','upload_tags', 334 'upload_file_props','upload_progress','upload_tags',
331 'cmd_uploads_upload' 335 'cmd_uploads_upload'
332 ]); 336 ]);
333 document.getElementById('uploadlist').view = this; 337 document.getElementById('uploadlist').view = this;
334 }, 338 },
335 files: new Array(), 339 files: new Array(),
336 rowCount: 0, 340 rowCount: 0,
337 getCellText: function(r,c) { 341 getCellText: function(r,c) {
338 var f = this.files[r]; 342 var f = this.files[r];
339 if(c.id=='up_file') return f.file; 343 if(c.id=='up_file') return f.file;
340 if(c.id=='up_title') return f.title; 344 if(c.id=='up_title') return f.title;
341 if(c.id=='up_status') return f.state; 345 if(c.id=='up_status') return f.state;
342 return c.id; 346 return c.id;
343 }, 347 },
344 setTree: function(t) { this.tree = t }, 348 setTree: function(t) { this.tree = t },
345 isContainer: function(r) { return false; }, 349 isContainer: function(r) { return false; },
346 isSeparator: function(r) { return false; }, 350 isSeparator: function(r) { return false; },
347 isSorted: function(r) { return false; }, 351 isSorted: function(r) { return false; },
348 getLevel: function(r) { return 0; }, 352 getLevel: function(r) { return 0; },
349 getImageSrc: function(r,c) { return null }, 353 getImageSrc: function(r,c) { return null },
350 getRowProperties: function(r,p) { 354 getRowProperties: function(r,p) {
351 try { 355 try {
352 if(!Components) return; 356 if(!Components) return;
353 }catch(e) { return } 357 }catch(e) { return }
354 var f = this.files[r]; 358 var f = this.files[r];
355 var as = Components.classes['@mozilla.org/atom-service;1']. 359 var as = Components.classes['@mozilla.org/atom-service;1'].
356 getService(Components.interfaces.nsIAtomService); 360 getService(Components.interfaces.nsIAtomService);
357 p.AppendElement(as.getAtom(f.state)); 361 p.AppendElement(as.getAtom(f.state));
358 }, 362 },
359 getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, 363 getCellProperties: function(r,c,p) { this.getRowProperties(r,p); },
360 getColumnProperties: function(c,p) { }, 364 getColumnProperties: function(c,p) { },
361 cycleHeader: function(cid,e) { }, 365 cycleHeader: function(cid,e) { },
362 getParentIndex: function(r) { return -1; }, 366 getParentIndex: function(r) { return -1; },
363 drop: function(r,o) { }, 367 drop: function(r,o) { },
364 canDropBeforeAfter: function(r,b) { return false }, 368 canDropBeforeAfter: function(r,b) { return false },
365 369
366 add: function(f) { 370 add: function(f) {
367 if(f.indexOf('file:/')==0) { 371 if(f.indexOf('file:/')==0) {
368 f = f.substr(5); 372 f = f.substr(5);
369 while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) 373 while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-)
370 f = f.substr(1); 374 f = f.substr(1);
371 } 375 }
372 } 376 }
373 var t = f; 377 var t = f;
374 var ls = t.lastIndexOf('/'); 378 var ls = t.lastIndexOf('/');
375 if(ls>0) t = t.substr(ls+1); 379 if(ls>0) t = t.substr(ls+1);
376 ls = t.lastIndexOf('\\'); 380 ls = t.lastIndexOf('\\');
377 if(ls>0) t = t.substr(ls+1); 381 if(ls>0) t = t.substr(ls+1);
378 var ld = t.lastIndexOf('.'); 382 var ld = t.lastIndexOf('.');
379 if(ld>0) t = t.substr(0,ld); 383 if(ld>0) t = t.substr(0,ld);
380 this.files.push( { 384 this.files.push( {
381 file: f, 385 file: f,
382 title: t, 386 title: t,
383 tags: '', 387 tags: '',
384 state: 'pending' 388 state: 'pending'
385 } ); 389 } );
386 this.rowCount = this.files.length; 390 this.rowCount = this.files.length;
387 this.tree.rowCountChanged(this.rowCount-1,1); 391 this.tree.rowCountChanged(this.rowCount-1,1);
388 }, 392 },
389 393
390 upload_worker: function() { 394 upload_worker: function() {
391 for(var f in this.files) { 395 for(var f in this.files) {
392 if(this.files[f].state=='pending') { 396 if(this.files[f].state=='pending') {
393 var ff = this.files[f]; 397 var ff = this.files[f];
394 this.on_file_upload(ff); 398 this.on_file_upload(ff);
395 ff.state='uploading'; 399 ff.state='uploading';
396 this.tree.invalidate(); 400 this.tree.invalidate();
397 var _this = this; 401 var _this = this;
398 this.fireflix.flickr.upload_file( 402 this.fireflix.flickr.upload_file(
399 ff.file, { title: ff.title, tags: ff.tags }, 403 ff.file, { title: ff.title, tags: ff.tags },
400 function(x,p) { 404 function(x,p) {
401 ff.photoid = p; 405 ff.photoid = p;
402 _this.batch_ids.push(p); 406 _this.batch_ids.push(p);
403 ff.state='completed'; 407 ff.state='completed';
404 _this.tree.invalidate(); 408 _this.tree.invalidate();
405 window.setTimeout(_this.upload_to,0,_this); 409 window.setTimeout(_this.upload_to,0,_this);
406 }, function(x,s,c,m) { 410 }, function(x,s,c,m) {
407 ff.state='failed'; 411 ff.state='failed';
408 ff.flickr_errcode = c; 412 ff.flickr_errcode = c;
409 ff.flickr_errmsg = m; 413 ff.flickr_errmsg = m;
410 _this.tree.invalidate(); 414 _this.tree.invalidate();
411 window.setTimeout(_this.upload_to,0,_this); 415 window.setTimeout(_this.upload_to,0,_this);
412 } 416 }
413 ); 417 );
414 return; 418 return;
415 } 419 }
416 } 420 }
417 this.on_finish_upload(); 421 this.on_finish_upload();
418 }, 422 },
419 upload_to: function(_this) { _this.upload_worker(); }, 423 upload_to: function(_this) { _this.upload_worker(); },
420 on_file_upload: function(f) { 424 on_file_upload: function(f) {
421 this.cmd_uploads_upload.setAttribute('disabled','true'); 425 this.cmd_uploads_upload.setAttribute('disabled','true');
422 for(var fi in this.files) { 426 for(var fi in this.files) {
423 if(this.files[fi].file==f.file) { 427 if(this.files[fi].file==f.file) {
424 this.tree.ensureRowIsVisible(fi); 428 this.tree.ensureRowIsVisible(fi);
425 this.selection.rangedSelect(fi,fi,false); 429 this.selection.rangedSelect(fi,fi,false);
426 this.selection.currentIndex = fi; 430 this.selection.currentIndex = fi;
427 this.selToProps(); 431 this.selToProps();
428 break; 432 break;
429 } 433 }
430 } 434 }
431 }, 435 },
432 on_finish_upload: function() { 436 on_finish_upload: function() {
433 if(this.batch_ids.length) { 437 if(this.batch_ids.length) {
434 var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); 438 var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset'));
435 if(psn!=null) { 439 if(psn!=null) {
436 var pids = this.batch_ids.join(','); 440 var pids = this.batch_ids.join(',');
437 var ppid = this.batch_ids[0]; 441 var ppid = this.batch_ids[0];
438 var _this = this; 442 var _this = this;
439 this.fireflix.flickr.api_call( 443 this.fireflix.flickr.api_call(
440 { 444 {
441 method: 'flickr.photosets.create', 445 method: 'flickr.photosets.create',
442 auth_token: 'default', 446 auth_token: 'default',
443 title: psn, 447 title: psn,
444 primary_photo_id: ppid 448 primary_photo_id: ppid
445 }, function(x) { 449 }, function(x) {
446 var npid = 450 var npid =
447 x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id'); 451 x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id');
448 _this.fireflix.flickr.api_call( 452 _this.fireflix.flickr.api_call(
449 { 453 {
450 method: 'flickr.photosets.editPhotos', 454 method: 'flickr.photosets.editPhotos',
451 auth_token: 'default', 455 auth_token: 'default',
452 photoset_id: npid, 456 photoset_id: npid,
453 primary_photo_id: ppid, 457 primary_photo_id: ppid,
454 photo_ids: pids 458 photo_ids: pids
455 }, function(x) { 459 }, function(x) {
456 _this.fireflix.refresh_sets(); 460 _this.fireflix.refresh_sets();
457 }, function(x,s,c,m) { 461 }, function(x,s,c,m) {
458 _this.fireflix.flickr_failure(x,s,c,m); 462 _this.fireflix.flickr_failure(x,s,c,m);
459 } 463 }
460 ); 464 );
461 }, function(x,s,c,m) { 465 }, function(x,s,c,m) {
462 _this.fireflix.flickr_failure(x,s,c,m); 466 _this.fireflix.flickr_failure(x,s,c,m);
463 } 467 }
464 ); 468 );
465 } 469 }
466 } 470 }
467 this.selection.clearSelection(); 471 this.selection.clearSelection();
468 this.cmd_uploads_upload.setAttribute('disabled','false'); 472 this.cmd_uploads_upload.setAttribute('disabled','false');
469 this.upload_progress.setAttribute('hidden','true'); 473 this.upload_progress.setAttribute('hidden','true');
470 }, 474 },
471 475
472 clear_list: function() { 476 clear_list: function() {
473 this.tree.beginUpdateBatch(); 477 this.tree.beginUpdateBatch();
474 this.rowCount = 0; 478 this.rowCount = 0;
475 this.files = new Array(); 479 this.files = new Array();
476 this.tree.endUpdateBatch(); 480 this.tree.endUpdateBatch();
477 this.selToProps(); 481 this.selToProps();
478 }, 482 },
479 selectionChanged: function() { 483 selectionChanged: function() {
480 this.selToProps(); 484 this.selToProps();
481 }, 485 },
482 disableProps: function() { 486 disableProps: function() {
483 this.upload_filename.value=''; 487 this.upload_filename.value='';
484 this.upload_filename.disabled = true; 488 this.upload_filename.disabled = true;
485 this.upload_title.value=''; 489 this.upload_title.value='';
486 this.upload_title.disabled = true; 490 this.upload_title.disabled = true;
487 this.upload_file_preview.src = null; 491 this.upload_file_preview.src = null;
488 this.upload_file_props.hidden = true; 492 this.upload_file_props.hidden = true;
489 this.upload_tags.value=''; 493 this.upload_tags.value='';
490 this.upload_tags.disabled = true; 494 this.upload_tags.disabled = true;
491 }, 495 },
492 selToProps: function() { 496 selToProps: function() {
493 if(!this.selection.count) { 497 if(!this.selection.count) {
494 this.disableProps(); 498 this.disableProps();
495 }else if(this.selection.count==1) { 499 }else if(this.selection.count==1) {
496 var f=this.files[this.selection.currentIndex]; 500 var f=this.files[this.selection.currentIndex];
497 if(f==null || f.state!='pending') { 501 if(f==null || f.state!='pending') {
498 this.disableProps(); 502 this.disableProps();
499 }else{ 503 }else{
500 this.upload_filename.value = f.file; 504 this.upload_filename.value = f.file;
501 this.upload_filename.disabled = false; 505 this.upload_filename.disabled = false;
502 this.upload_title.value = f.title; 506 this.upload_title.value = f.title;
503 this.upload_title.disabled = false; 507 this.upload_title.disabled = false;
504 this.upload_file_preview.src = 'file:///'+f.file; 508 this.upload_file_preview.src = 'file:///'+f.file;
505 this.upload_file_props.hidden = false; 509 this.upload_file_props.hidden = false;
506 this.upload_tags.value = f.tags; 510 this.upload_tags.value = f.tags;
507 this.upload_tags.disabled = false; 511 this.upload_tags.disabled = false;
508 } 512 }
509 }else{ 513 }else{
510 var ftitle = null; var onetitle = true; 514 var ftitle = null; var onetitle = true;
511 var ftags = null; var onetag = true; 515 var ftags = null; var onetag = true;
512 var fs = 0; 516 var fs = 0;
513 for(var ff in this.files) { 517 for(var ff in this.files) {
514 if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { 518 if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) {
515 ++fs; 519 ++fs;
516 if(ftitle==null) { 520 if(ftitle==null) {
517 ftitle = this.files[ff].title; 521 ftitle = this.files[ff].title;
518 }else if(ftitle!=this.files[ff].title) { 522 }else if(ftitle!=this.files[ff].title) {
519 onetitle = false; 523 onetitle = false;
520 } 524 }
521 if(ftags==null) { 525 if(ftags==null) {
522 ftags = this.files[ff].tags; 526 ftags = this.files[ff].tags;
523 }else if(ftags!=this.files[ff].tags) { 527 }else if(ftags!=this.files[ff].tags) {
524 onetag = false; 528 onetag = false;
525 } 529 }
526 } 530 }
527 } 531 }
528 if(fs) { 532 if(fs) {
529 this.upload_filename.value=''; 533 this.upload_filename.value='';
530 this.upload_filename.disabled = true; 534 this.upload_filename.disabled = true;
531 if(onetitle) 535 if(onetitle)
532 this.upload_title.value = ftitle; 536 this.upload_title.value = ftitle;
533 this.upload_title.disabled = false; 537 this.upload_title.disabled = false;
534 if(onetag) 538 if(onetag)
535 this.upload_tags.value = ftags; 539 this.upload_tags.value = ftags;
536 this.upload_tags.disabled = false; 540 this.upload_tags.disabled = false;
537 this.upload_file_preview.src = null; 541 this.upload_file_preview.src = null;
538 this.upload_file_props.hidden = false; 542 this.upload_file_props.hidden = false;
539 }else 543 }else
540 this.disableProps(); 544 this.disableProps();
541 } 545 }
542 }, 546 },
543 propsToSel: function(prop) { 547 propsToSel: function(prop) {
544 if(this.selection.count<=0) return; 548 if(this.selection.count<=0) return;
545 for(var ff in this.files) { 549 for(var ff in this.files) {
546 if(this.selection.isSelected(ff) && this.files[ff].state=='pending') { 550 if(this.selection.isSelected(ff) && this.files[ff].state=='pending') {
547 if(prop=='filename') 551 if(prop=='filename')
548 this.files[ff].file = this.upload_filename.value; 552 this.files[ff].file = this.upload_filename.value;
549 if(prop=='title') 553 if(prop=='title')
550 this.files[ff].title = this.upload_title.value; 554 this.files[ff].title = this.upload_title.value;
551 if(prop=='tags') 555 if(prop=='tags')
552 this.files[ff].tags = this.upload_tags.value; 556 this.files[ff].tags = this.upload_tags.value;
553 this.tree.invalidateRow(ff); 557 this.tree.invalidateRow(ff);
554 } 558 }
555 } 559 }
556 }, 560 },
557 561
558 on_upload: function() { 562 on_upload: function() {
559 this.selToProps(); 563 this.selToProps();
560 this.batch_ids = new Array(); 564 this.batch_ids = new Array();
561 this.upload_progress.value=0; 565 this.upload_progress.value=0;
562 this.upload_progress.setAttribute('hidden','false'); 566 this.upload_progress.setAttribute('hidden','false');
563 this.upload_worker(); 567 this.upload_worker();
564 }, 568 },
565 on_clear: function() { 569 on_clear: function() {
566 this.clear_list(); 570 this.clear_list();
567 }, 571 },
568 on_remove: function() { 572 on_remove: function() {
569 if(this.selection.count) { 573 if(this.selection.count) {
570 this.tree.beginUpdateBatch(); 574 this.tree.beginUpdateBatch();
571 for(var i=this.files.length-1;i>=0;--i) { 575 for(var i=this.files.length-1;i>=0;--i) {
572 if(this.selection.isSelected(i)) { 576 if(this.selection.isSelected(i)) {
573 this.files.splice(i,1); 577 this.files.splice(i,1);
574 this.rowCount--; 578 this.rowCount--;
575 } 579 }
576 } 580 }
577 this.tree.endUpdateBatch(); 581 this.tree.endUpdateBatch();
578 this.selection.clearSelection(); 582 this.selection.clearSelection();
579 } 583 }
580 }, 584 },
581 on_add: function() { 585 on_add: function() {
582 var ifp = Components.interfaces.nsIFilePicker; 586 var ifp = Components.interfaces.nsIFilePicker;
583 var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp); 587 var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp);
584 fp.init(window, "Select a File", ifp.modeOpenMultiple); 588 fp.init(window, "Select a File", ifp.modeOpenMultiple);
585 fp.appendFilters(ifp.filterImages); 589 fp.appendFilters(ifp.filterImages);
586 var rv = fp.show(); 590 var rv = fp.show();
587 if(rv==ifp.returnOK) { 591 if(rv==ifp.returnOK) {
588 var ff = fp.files; 592 var ff = fp.files;
589 while(ff.hasMoreElements()) { 593 while(ff.hasMoreElements()) {
590 var f = ff.getNext(); 594 var f = ff.getNext();
591 f.QueryInterface(Components.interfaces.nsIFile); 595 f.QueryInterface(Components.interfaces.nsIFile);
592 this.add(f.path); 596 this.add(f.path);
593 } 597 }
594 } 598 }
595 } 599 }
596 }, 600 },
597 601
598 on_set_props: function() { 602 on_set_props: function() {
599 var pset = this.photosets.sets[this.photosets.selection.currentIndex]; 603 var pset = this.photosets.sets[this.photosets.selection.currentIndex];
600 window.openDialog( 604 window.openDialog(
601 "chrome://fireflix/content/photoset-props.xul", 605 "chrome://fireflix/content/photoset-props.xul",
602 null, "dependent,modal,dialog,chrome", this, 606 null, "dependent,modal,dialog,chrome", this,
603 pset ); 607 pset );
604 if(pset.dirty) { 608 if(pset.dirty) {
605 var _this = this; 609 var _this = this;
606 this.flickr.api_call( 610 this.flickr.api_call(
607 { 611 {
608 method: 'flickr.photosets.editMeta', 612 method: 'flickr.photosets.editMeta',
609 auth_token: 'default', 613 auth_token: 'default',
610 photoset_id: pset.id, 614 photoset_id: pset.id,
611 title: pset.title, 615 title: pset.title,
612 description: pset.description 616 description: pset.description
613 }, function(xr) { 617 }, function(xr) {
614 pset.dirty = false; 618 pset.dirty = false;
615 _this.flickr.api_call( 619 _this.flickr.api_call(
616 { 620 {
617 method: 'flickr.photosets.getPhotos', 621 method: 'flickr.photosets.getPhotos',
618 auth_token: 'default', 622 auth_token: 'default',
619 photoset_id: pset.id 623 photoset_id: pset.id
620 }, function(xr) { 624 }, function(xr) {
621 var x = xr.responseXML; 625 var x = xr.responseXML;
622 var xp = x.evaluate( 626 var xp = x.evaluate(