summaryrefslogtreecommitdiffabout
path: root/content/fireflix.js
Unidiff
Diffstat (limited to 'content/fireflix.js') (more/less context) (ignore whitespace changes)
-rw-r--r--content/fireflix.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/content/fireflix.js b/content/fireflix.js
index 85b4d39..a4f13b6 100644
--- a/content/fireflix.js
+++ b/content/fireflix.js
@@ -1,872 +1,878 @@
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') return p.dateupload; /* TODO: unixtime conversion */ 104 if(c.id=='sp_upload') {
105 var du = new Date(p.dateupload*1000);
106 var rv = du.getFullYear()+'-'+(du.getMonth()+1)+'-'+du.getDate()
107 +' '+
108 du.getHours()+':'+du.getMinutes()+':'+du.getSeconds();
109 return rv.replace(/(\D)(\d)(\D)/,'$10$2$3');
110 }
105 return c.id; 111 return c.id;
106 }, 112 },
107 setTree: function(t) { this.tree = t }, 113 setTree: function(t) { this.tree = t },
108 isContainer: function(r) { return false; }, 114 isContainer: function(r) { return false; },
109 isSeparator: function(r) { return false; }, 115 isSeparator: function(r) { return false; },
110 isSorted: function(r) { return false; }, 116 isSorted: function(r) { return false; },
111 getLevel: function(r) { return 0; }, 117 getLevel: function(r) { return 0; },
112 getImageSrc: function(r,c) { return null }, 118 getImageSrc: function(r,c) { return null },
113 getRowProperties: function(r,p) {}, 119 getRowProperties: function(r,p) {},
114 getCellProperties: function(cid,cel,p) {}, 120 getCellProperties: function(cid,cel,p) {},
115 getColumnProperties: function(cid,cel,p) { }, 121 getColumnProperties: function(cid,cel,p) { },
116 cycleHeader: function(cid,e) { }, 122 cycleHeader: function(cid,e) { },
117 getParentIndex: function(r) { return -1; }, 123 getParentIndex: function(r) { return -1; },
118 drop: function(r,o) { }, 124 drop: function(r,o) { },
119 canDropBeforeAfter: function(r,b) { return false }, 125 canDropBeforeAfter: function(r,b) { return false },
120 126
121 importXPR: function(xp) { 127 importXPR: function(xp) {
122 this.tree.beginUpdateBatch(); 128 this.tree.beginUpdateBatch();
123 this.photos = new Array(); 129 this.photos = new Array();
124 var n; while(n=xp.iterateNext()) { 130 var n; while(n=xp.iterateNext()) {
125 this.photos.push(new Photo(n)); 131 this.photos.push(new Photo(n));
126 } 132 }
127 this.rowCount = this.photos.length; 133 this.rowCount = this.photos.length;
128 this.tree.endUpdateBatch(); 134 this.tree.endUpdateBatch();
129 }, 135 },
130 load_photos: function(psid) { 136 load_photos: function(psid) {
131 var _this = this; 137 var _this = this;
132 this.fireflix.flickr.api_call( 138 this.fireflix.flickr.api_call(
133 { 139 {
134 method: 'flickr.photosets.getPhotos', 140 method: 'flickr.photosets.getPhotos',
135 auth_token: 'default', 141 auth_token: 'default',
136 photoset_id: psid, 142 photoset_id: psid,
137 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' 143 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update'
138 }, function(xr) { 144 }, function(xr) {
139 var x = xr.responseXML; 145 var x = xr.responseXML;
140 var xp = x.evaluate( 146 var xp = x.evaluate(
141 '/rsp/photoset/photo', x, null, 147 '/rsp/photoset/photo', x, null,
142 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 148 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
143 _this.importXPR(xp); 149 _this.importXPR(xp);
144 }, function(x,s,c,m) { 150 }, function(x,s,c,m) {
145 _this.fireflix.flickr_failure(x,s,c,m); 151 _this.fireflix.flickr_failure(x,s,c,m);
146 } 152 }
147 ); 153 );
148 }, 154 },
149 on_select: function() { 155 on_select: function() {
150 if(this.selection.count==1) { 156 if(this.selection.count==1) {
151 var p = this.photos[this.selection.currentIndex]; 157 var p = this.photos[this.selection.currentIndex];
152 this.set_photo.src = 158 this.set_photo.src =
153 this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t'); 159 this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t');
154 this.set_photo.hidden = false; 160 this.set_photo.hidden = false;
155 }else{ 161 }else{
156 this.set_photo.hidden = true; 162 this.set_photo.hidden = true;
157 } 163 }
158 } 164 }
159 }, 165 },
160 166
161 /* photosets treeview */ 167 /* photosets treeview */
162 photosets: { 168 photosets: {
163 sets: new Array(), 169 sets: new Array(),
164 fireflix: null, 170 fireflix: null,
165 init: function(f) { 171 init: function(f) {
166 this.fireflix = f; 172 this.fireflix = f;
167 document.getElementById('setslist').view = this; 173 document.getElementById('setslist').view = this;
168 }, 174 },
169 rowCount: 0, 175 rowCount: 0,
170 getCellText: function(r,c) { 176 getCellText: function(r,c) {
171 var s = this.sets[r]; 177 var s = this.sets[r];
172 if(c.id=='sl_name') return s.title; 178 if(c.id=='sl_name') return s.title;
173 if(c.id=='sl_photos') return s.photos; 179 if(c.id=='sl_photos') return s.photos;
174 return c.id; 180 return c.id;
175 }, 181 },
176 setTree: function(t) { this.tree = t }, 182 setTree: function(t) { this.tree = t },
177 isContainer: function(r) { return false; }, 183 isContainer: function(r) { return false; },
178 isSeparator: function(r) { return false; }, 184 isSeparator: function(r) { return false; },
179 isSorted: function() { return false; }, 185 isSorted: function() { return false; },
180 getLevel: function(r) { return 0; }, 186 getLevel: function(r) { return 0; },
181 getImageSrc: function(r,c) { return null }, 187 getImageSrc: function(r,c) { return null },
182 getRowProperties: function(r,p) {}, 188 getRowProperties: function(r,p) {},
183 getCellProperties: function(cid,cel,p) { }, 189 getCellProperties: function(cid,cel,p) { },
184 getColumnProperties: function(cid,cel,p) { }, 190 getColumnProperties: function(cid,cel,p) { },
185 cycleHeader: function(cid,e) { }, 191 cycleHeader: function(cid,e) { },
186 getParentIndex: function(r) { return -1; }, 192 getParentIndex: function(r) { return -1; },
187 drop: function(r,o) { }, 193 drop: function(r,o) { },
188 canDropBeforeAfter: function(r,b) { return false }, 194 canDropBeforeAfter: function(r,b) { return false },
189 195
190 importXPR: function(xp) { 196 importXPR: function(xp) {
191 this.tree.beginUpdateBatch(); 197 this.tree.beginUpdateBatch();
192 this.sets = new Array(); 198 this.sets = new Array();
193 var n; while(n=xp.iterateNext()) { 199 var n; while(n=xp.iterateNext()) {
194 this.sets.push(new Photoset(n)); 200 this.sets.push(new Photoset(n));
195 } 201 }
196 this.rowCount = this.sets.length; 202 this.rowCount = this.sets.length;
197 this.tree.endUpdateBatch(); 203 this.tree.endUpdateBatch();
198 }, 204 },
199 refresh_sets: function() { 205 refresh_sets: function() {
200 var _this = this; 206 var _this = this;
201 this.fireflix.flickr.api_call( 207 this.fireflix.flickr.api_call(
202 { 208 {
203 method: 'flickr.photosets.getList', 209 method: 'flickr.photosets.getList',
204 auth_token: 'default' 210 auth_token: 'default'
205 }, function(xr) { 211 }, function(xr) {
206 var x = xr.responseXML; 212 var x = xr.responseXML;
207 var xp = x.evaluate( 213 var xp = x.evaluate(
208 '/rsp/photosets/photoset', x, null, 214 '/rsp/photosets/photoset', x, null,
209 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 215 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
210 _this.importXPR(xp); 216 _this.importXPR(xp);
211 }, function(x,s,c,m) { 217 }, function(x,s,c,m) {
212 _this.fireflix.flickr_failure(x,s,c,m); 218 _this.fireflix.flickr_failure(x,s,c,m);
213 } 219 }
214 ); 220 );
215 }, 221 },
216 on_select: function() { 222 on_select: function() {
217 if(this.selection.count==1) { 223 if(this.selection.count==1) {
218 this.fireflix.cmd_set_props.setAttribute('disabled','false'); 224 this.fireflix.cmd_set_props.setAttribute('disabled','false');
219 var s = this.sets[this.selection.currentIndex]; 225 var s = this.sets[this.selection.currentIndex];
220 this.fireflix.photoset.load_photos(s.id); 226 this.fireflix.photoset.load_photos(s.id);
221 }else{ 227 }else{
222 this.fireflix.cmd_set_props.setAttribute('disabled','true'); 228 this.fireflix.cmd_set_props.setAttribute('disabled','true');
223 } 229 }
224 } 230 }
225 }, 231 },
226 232
227 refresh_user_tags: function() { 233 refresh_user_tags: function() {
228 var lb = document.getElementById('tagslist'); 234 var lb = document.getElementById('tagslist');
229 var _this = this; 235 var _this = this;
230 this.flickr.api_call( 236 this.flickr.api_call(
231 { 237 {
232 method: 'flickr.tags.getListUser', 238 method: 'flickr.tags.getListUser',
233 auth_token: 'default', 239 auth_token: 'default',
234 }, function(xr) { 240 }, function(xr) {
235 var x = xr.responseXML; 241 var x = xr.responseXML;
236 var xp = x.evaluate( 242 var xp = x.evaluate(
237 '/rsp/who/tags/tag', x, null, 243 '/rsp/who/tags/tag', x, null,
238 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 244 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
239 // TODO: clear list 245 // TODO: clear list
240 var n; while(n=xp.iterateNext()) { 246 var n; while(n=xp.iterateNext()) {
241 lb.appendItem(n.firstChild.nodeValue); 247 lb.appendItem(n.firstChild.nodeValue);
242 } 248 }
243 }, function(x,s,c,m) { 249 }, function(x,s,c,m) {
244 _this.flickr_failure(x,s,c,m); 250 _this.flickr_failure(x,s,c,m);
245 } 251 }
246 ); 252 );
247 }, 253 },
248 254
249 uploadObserver: { 255 uploadObserver: {
250 fireflix: null, 256 fireflix: null,
251 init: function(f) { 257 init: function(f) {
252 this.fireflix = f; 258 this.fireflix = f;
253 }, 259 },
254 getSupportedFlavours: function() { 260 getSupportedFlavours: function() {
255 var rv = new FlavourSet(); 261 var rv = new FlavourSet();
256 rv.appendFlavour('application/x-moz-file','nsIFile'); 262 rv.appendFlavour('application/x-moz-file','nsIFile');
257 rv.appendFlavour('application/x-moz-url'); 263 rv.appendFlavour('application/x-moz-url');
258 rv.appendFlavour('text/uri-list'); 264 rv.appendFlavour('text/uri-list');
259 rv.appendFlavour('text/unicode'); 265 rv.appendFlavour('text/unicode');
260 return rv; 266 return rv;
261 }, 267 },
262 canHandleMultipleItems: true, 268 canHandleMultipleItems: true,
263 onDragOver: function(ev,fl,sess) { 269 onDragOver: function(ev,fl,sess) {
264 return true; 270 return true;
265 }, 271 },
266 onDrop: function(ev,dd,s) { 272 onDrop: function(ev,dd,s) {
267 var ldf = null; 273 var ldf = null;
268 for(var i in dd.dataList) { 274 for(var i in dd.dataList) {
269 var di = dd.dataList[i]; 275 var di = dd.dataList[i];
270 var dif = di.first; 276 var dif = di.first;
271 if( 277 if(
272 ldf==null 278 ldf==null
273 || ldf.flavour.contentType!=dif.flavour.contentType 279 || ldf.flavour.contentType!=dif.flavour.contentType
274 || ldf.contentLength!=dif.contentLength 280 || ldf.contentLength!=dif.contentLength
275 || ldf.data!=dif.data ) 281 || ldf.data!=dif.data )
276 this.drop_item(ev,di,s); 282 this.drop_item(ev,di,s);
277 ldf = dif; 283 ldf = dif;
278 } 284 }
279 }, 285 },
280 drop_item: function(ev,di,s) { 286 drop_item: function(ev,di,s) {
281 var d = di.first; 287 var d = di.first;
282 switch(d.flavour.contentType) { 288 switch(d.flavour.contentType) {
283 case 'text/unicode': 289 case 'text/unicode':
284 this.drop_urilist(ev,d.data,s); 290 this.drop_urilist(ev,d.data,s);
285 break; 291 break;
286 case 'application/x-moz-file': 292 case 'application/x-moz-file':
287 this.fireflix.uploads.add(d.data.path); 293 this.fireflix.uploads.add(d.data.path);
288 document.getElementById('fireflix_tabs').selectedTab 294 document.getElementById('fireflix_tabs').selectedTab
289 = document.getElementById('tab_upload'); 295 = document.getElementById('tab_upload');
290 break; 296 break;
291 case 'text/uri-list': 297 case 'text/uri-list':
292 // is it ascii or could it be utf8? 298 // is it ascii or could it be utf8?
293 this.drop_urilist(ev,splitascii(d.data),s); 299 this.drop_urilist(ev,splitascii(d.data),s);
294 break; 300 break;
295 default: alert(d.flavour.contentType+':'+d.data); break; 301 default: alert(d.flavour.contentType+':'+d.data); break;
296 }; 302 };
297 }, 303 },
298 drop_urilist: function(ev,ul,s) { 304 drop_urilist: function(ev,ul,s) {
299 // TODO: check for being a file? 305 // TODO: check for being a file?
300 var us = decodeURIComponent(ul).split(/[\r\n]/); 306 var us = decodeURIComponent(ul).split(/[\r\n]/);
301 for(var ui in us) 307 for(var ui in us)
302 if(/\S/.test(us[ui])) 308 if(/\S/.test(us[ui]))
303 this.fireflix.uploads.add(us[ui]); 309 this.fireflix.uploads.add(us[ui]);
304 document.getElementById('fireflix_tabs').selectedTab 310 document.getElementById('fireflix_tabs').selectedTab
305 = document.getElementById('tab_upload'); 311 = document.getElementById('tab_upload');
306 } 312 }
307 }, 313 },
308 314
309 uploads: { 315 uploads: {
310 fireflix: null, 316 fireflix: null,
311 init: function(f) { 317 init: function(f) {
312 this.fireflix=f; 318 this.fireflix=f;
313 pull_elements(this,document,[ 319 pull_elements(this,document,[
314 'upload_filename','upload_title','upload_file_preview', 320 'upload_filename','upload_title','upload_file_preview',
315 'upload_file_props','upload_progress','upload_tags', 321 'upload_file_props','upload_progress','upload_tags',
316 'cmd_uploads_upload' 322 'cmd_uploads_upload'
317 ]); 323 ]);
318 document.getElementById('uploadlist').view = this; 324 document.getElementById('uploadlist').view = this;
319 }, 325 },
320 files: new Array(), 326 files: new Array(),
321 rowCount: 0, 327 rowCount: 0,
322 getCellText: function(r,c) { 328 getCellText: function(r,c) {
323 var f = this.files[r]; 329 var f = this.files[r];
324 if(c.id=='up_file') return f.file; 330 if(c.id=='up_file') return f.file;
325 if(c.id=='up_title') return f.title; 331 if(c.id=='up_title') return f.title;
326 if(c.id=='up_status') return f.state; 332 if(c.id=='up_status') return f.state;
327 return c.id; 333 return c.id;
328 }, 334 },
329 setTree: function(t) { this.tree = t }, 335 setTree: function(t) { this.tree = t },
330 isContainer: function(r) { return false; }, 336 isContainer: function(r) { return false; },
331 isSeparator: function(r) { return false; }, 337 isSeparator: function(r) { return false; },
332 isSorted: function(r) { return false; }, 338 isSorted: function(r) { return false; },
333 getLevel: function(r) { return 0; }, 339 getLevel: function(r) { return 0; },
334 getImageSrc: function(r,c) { return null }, 340 getImageSrc: function(r,c) { return null },
335 getRowProperties: function(r,p) { 341 getRowProperties: function(r,p) {
336 try { 342 try {
337 if(!Components) return; 343 if(!Components) return;
338 }catch(e) { return } 344 }catch(e) { return }
339 var f = this.files[r]; 345 var f = this.files[r];
340 var as = Components.classes['@mozilla.org/atom-service;1']. 346 var as = Components.classes['@mozilla.org/atom-service;1'].
341 getService(Components.interfaces.nsIAtomService); 347 getService(Components.interfaces.nsIAtomService);
342 p.AppendElement(as.getAtom(f.state)); 348 p.AppendElement(as.getAtom(f.state));
343 }, 349 },
344 getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, 350 getCellProperties: function(r,c,p) { this.getRowProperties(r,p); },
345 getColumnProperties: function(c,p) { }, 351 getColumnProperties: function(c,p) { },
346 cycleHeader: function(cid,e) { }, 352 cycleHeader: function(cid,e) { },
347 getParentIndex: function(r) { return -1; }, 353 getParentIndex: function(r) { return -1; },
348 drop: function(r,o) { }, 354 drop: function(r,o) { },
349 canDropBeforeAfter: function(r,b) { return false }, 355 canDropBeforeAfter: function(r,b) { return false },
350 356
351 add: function(f) { 357 add: function(f) {
352 if(f.indexOf('file:/')==0) { 358 if(f.indexOf('file:/')==0) {
353 f = f.substr(5); 359 f = f.substr(5);
354 while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) 360 while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-)
355 f = f.substr(1); 361 f = f.substr(1);
356 } 362 }
357 } 363 }
358 var t = f; 364 var t = f;
359 var ls = t.lastIndexOf('/'); 365 var ls = t.lastIndexOf('/');
360 if(ls>0) t = t.substr(ls+1); 366 if(ls>0) t = t.substr(ls+1);
361 ls = t.lastIndexOf('\\'); 367 ls = t.lastIndexOf('\\');
362 if(ls>0) t = t.substr(ls+1); 368 if(ls>0) t = t.substr(ls+1);
363 var ld = t.lastIndexOf('.'); 369 var ld = t.lastIndexOf('.');
364 if(ld>0) t = t.substr(0,ld); 370 if(ld>0) t = t.substr(0,ld);
365 this.files.push( { 371 this.files.push( {
366 file: f, 372 file: f,
367 title: t, 373 title: t,
368 tags: '', 374 tags: '',
369 state: 'pending' 375 state: 'pending'
370 } ); 376 } );
371 this.rowCount = this.files.length; 377 this.rowCount = this.files.length;
372 this.tree.rowCountChanged(this.rowCount-1,1); 378 this.tree.rowCountChanged(this.rowCount-1,1);
373 }, 379 },
374 380
375 upload_worker: function() { 381 upload_worker: function() {
376 for(var f in this.files) { 382 for(var f in this.files) {
377 if(this.files[f].state=='pending') { 383 if(this.files[f].state=='pending') {
378 var ff = this.files[f]; 384 var ff = this.files[f];
379 dump('upload '+ff.file+'\n'); 385 dump('upload '+ff.file+'\n');
380 this.on_file_upload(ff); 386 this.on_file_upload(ff);
381 ff.state='uploading'; 387 ff.state='uploading';
382 this.tree.invalidate(); 388 this.tree.invalidate();
383 var _this = this; 389 var _this = this;
384 this.fireflix.flickr.upload_file( 390 this.fireflix.flickr.upload_file(
385 ff.file, { title: ff.title, tags: ff.tags }, 391 ff.file, { title: ff.title, tags: ff.tags },
386 function(x,p) { 392 function(x,p) {
387 ff.photoid = p; 393 ff.photoid = p;
388 _this.batch_ids.push(p); 394 _this.batch_ids.push(p);
389 ff.state='completed'; 395 ff.state='completed';
390 _this.tree.invalidate(); 396 _this.tree.invalidate();
391 window.setTimeout(_this.upload_to,0,_this); 397 window.setTimeout(_this.upload_to,0,_this);
392 }, function(x,s,c,m) { 398 }, function(x,s,c,m) {
393 ff.state='failed'; 399 ff.state='failed';
394 ff.flickr_errcode = c; 400 ff.flickr_errcode = c;
395 ff.flickr_errmsg = m; 401 ff.flickr_errmsg = m;
396 _this.tree.invalidate(); 402 _this.tree.invalidate();
397 window.setTimeout(_this.upload_to,0,_this); 403 window.setTimeout(_this.upload_to,0,_this);
398 } 404 }
399 ); 405 );
400 return; 406 return;
401 } 407 }
402 } 408 }
403 dump('uploading done\n'); 409 dump('uploading done\n');
404 this.on_finish_upload(); 410 this.on_finish_upload();
405 }, 411 },
406 upload_to: function(_this) { _this.upload_worker(); }, 412 upload_to: function(_this) { _this.upload_worker(); },
407 on_file_upload: function(f) { 413 on_file_upload: function(f) {
408 this.cmd_uploads_upload.setAttribute('disabled','true'); 414 this.cmd_uploads_upload.setAttribute('disabled','true');
409 for(var fi in this.files) { 415 for(var fi in this.files) {
410 if(this.files[fi].file==f.file) { 416 if(this.files[fi].file==f.file) {
411 this.tree.ensureRowIsVisible(fi); 417 this.tree.ensureRowIsVisible(fi);
412 this.selection.rangedSelect(fi,fi,false); 418 this.selection.rangedSelect(fi,fi,false);
413 this.selection.currentIndex = fi; 419 this.selection.currentIndex = fi;
414 this.selToProps(); 420 this.selToProps();
415 break; 421 break;
416 } 422 }
417 } 423 }
418 }, 424 },
419 on_finish_upload: function() { 425 on_finish_upload: function() {
420 if(this.batch_ids.length) { 426 if(this.batch_ids.length) {
421 var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); 427 var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset'));
422 if(psn!=null) { 428 if(psn!=null) {
423 var pids = this.batch_ids.join(','); 429 var pids = this.batch_ids.join(',');
424 var ppid = this.batch_ids[0]; 430 var ppid = this.batch_ids[0];
425 var _this = this; 431 var _this = this;
426 this.fireflix.flickr.api_call( 432 this.fireflix.flickr.api_call(
427 { 433 {
428 method: 'flickr.photosets.create', 434 method: 'flickr.photosets.create',
429 auth_token: 'default', 435 auth_token: 'default',
430 title: psn, 436 title: psn,
431 primary_photo_id: ppid 437 primary_photo_id: ppid
432 }, function(x) { 438 }, function(x) {
433 var npid = 439 var npid =
434 x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id'); 440 x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id');
435 _this.fireflix.flickr.api_call( 441 _this.fireflix.flickr.api_call(
436 { 442 {
437 method: 'flickr.photosets.editPhotos', 443 method: 'flickr.photosets.editPhotos',
438 auth_token: 'default', 444 auth_token: 'default',
439 photoset_id: npid, 445 photoset_id: npid,
440 primary_photo_id: ppid, 446 primary_photo_id: ppid,
441 photo_ids: pids 447 photo_ids: pids
442 }, function(x) { 448 }, function(x) {
443 _this.fireflix.refresh_sets(); 449 _this.fireflix.refresh_sets();
444 }, function(x,s,c,m) { 450 }, function(x,s,c,m) {
445 _this.fireflix.flickr_failure(x,s,c,m); 451 _this.fireflix.flickr_failure(x,s,c,m);
446 } 452 }
447 ); 453 );
448 }, function(x,s,c,m) { 454 }, function(x,s,c,m) {
449 _this.fireflix.flickr_failure(x,s,c,m); 455 _this.fireflix.flickr_failure(x,s,c,m);
450 } 456 }
451 ); 457 );
452 } 458 }
453 } 459 }
454 this.selection.clearSelection(); 460 this.selection.clearSelection();
455 this.cmd_uploads_upload.setAttribute('disabled','false'); 461 this.cmd_uploads_upload.setAttribute('disabled','false');
456 this.upload_progress.setAttribute('hidden','true'); 462 this.upload_progress.setAttribute('hidden','true');
457 }, 463 },
458 464
459 clear_list: function() { 465 clear_list: function() {
460 this.tree.beginUpdateBatch(); 466 this.tree.beginUpdateBatch();
461 this.rowCount = 0; 467 this.rowCount = 0;
462 this.files = new Array(); 468 this.files = new Array();
463 this.tree.endUpdateBatch(); 469 this.tree.endUpdateBatch();
464 this.selToProps(); 470 this.selToProps();
465 }, 471 },
466 selectionChanged: function() { 472 selectionChanged: function() {
467 this.selToProps(); 473 this.selToProps();
468 }, 474 },
469 disableProps: function() { 475 disableProps: function() {
470 this.upload_filename.value=''; 476 this.upload_filename.value='';
471 this.upload_filename.disabled = true; 477 this.upload_filename.disabled = true;
472 this.upload_title.value=''; 478 this.upload_title.value='';
473 this.upload_title.disabled = true; 479 this.upload_title.disabled = true;
474 this.upload_file_preview.src = null; 480 this.upload_file_preview.src = null;
475 this.upload_file_props.hidden = true; 481 this.upload_file_props.hidden = true;
476 this.upload_tags.value=''; 482 this.upload_tags.value='';
477 this.upload_tags.disabled = true; 483 this.upload_tags.disabled = true;
478 }, 484 },
479 selToProps: function() { 485 selToProps: function() {
480 if(!this.selection.count) { 486 if(!this.selection.count) {
481 this.disableProps(); 487 this.disableProps();
482 }else if(this.selection.count==1) { 488 }else if(this.selection.count==1) {
483 var f=this.files[this.selection.currentIndex]; 489 var f=this.files[this.selection.currentIndex];
484 if(f==null || f.state!='pending') { 490 if(f==null || f.state!='pending') {
485 this.disableProps(); 491 this.disableProps();
486 }else{ 492 }else{
487 this.upload_filename.value = f.file; 493 this.upload_filename.value = f.file;
488 this.upload_filename.disabled = false; 494 this.upload_filename.disabled = false;
489 this.upload_title.value = f.title; 495 this.upload_title.value = f.title;
490 this.upload_title.disabled = false; 496 this.upload_title.disabled = false;
491 this.upload_file_preview.src = 'file:///'+f.file; 497 this.upload_file_preview.src = 'file:///'+f.file;
492 this.upload_file_props.hidden = false; 498 this.upload_file_props.hidden = false;
493 this.upload_tags.value = f.tags; 499 this.upload_tags.value = f.tags;
494 this.upload_tags.disabled = false; 500 this.upload_tags.disabled = false;
495 } 501 }
496 }else{ 502 }else{
497 var ftitle = null; var onetitle = true; 503 var ftitle = null; var onetitle = true;
498 var ftags = null; var onetag = true; 504 var ftags = null; var onetag = true;
499 var fs = 0; 505 var fs = 0;
500 for(var ff in this.files) { 506 for(var ff in this.files) {
501 if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { 507 if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) {
502 ++fs; 508 ++fs;
503 if(ftitle==null) { 509 if(ftitle==null) {
504 ftitle = this.files[ff].title; 510 ftitle = this.files[ff].title;
505 }else if(ftitle!=this.files[ff].title) { 511 }else if(ftitle!=this.files[ff].title) {
506 onetitle = false; 512 onetitle = false;
507 } 513 }
508 if(ftags==null) { 514 if(ftags==null) {
509 ftags = this.files[ff].tags; 515 ftags = this.files[ff].tags;
510 }else if(ftags!=this.files[ff].tags) { 516 }else if(ftags!=this.files[ff].tags) {
511 onetag = false; 517 onetag = false;
512 } 518 }
513 } 519 }
514 } 520 }
515 if(fs) { 521 if(fs) {
516 this.upload_filename.value=''; 522 this.upload_filename.value='';
517 this.upload_filename.disabled = true; 523 this.upload_filename.disabled = true;
518 if(onetitle) 524 if(onetitle)
519 this.upload_title.value = ftitle; 525 this.upload_title.value = ftitle;
520 this.upload_title.disabled = false; 526 this.upload_title.disabled = false;
521 if(onetag) 527 if(onetag)
522 this.upload_tags.value = ftags; 528 this.upload_tags.value = ftags;
523 this.upload_tags.disabled = false; 529 this.upload_tags.disabled = false;
524 this.upload_file_preview.src = null; 530 this.upload_file_preview.src = null;
525 this.upload_file_props.hidden = false; 531 this.upload_file_props.hidden = false;
526 }else 532 }else
527 this.disableProps(); 533 this.disableProps();
528 } 534 }
529 }, 535 },
530 propsToSel: function(prop) { 536 propsToSel: function(prop) {
531 if(this.selection.count<=0) return; 537 if(this.selection.count<=0) return;
532 for(var ff in this.files) { 538 for(var ff in this.files) {
533 if(this.selection.isSelected(ff) && this.files[ff].state=='pending') { 539 if(this.selection.isSelected(ff) && this.files[ff].state=='pending') {
534 if(prop=='filename') 540 if(prop=='filename')
535 this.files[ff].file = this.upload_filename.value; 541 this.files[ff].file = this.upload_filename.value;
536 if(prop=='title') 542 if(prop=='title')
537 this.files[ff].title = this.upload_title.value; 543 this.files[ff].title = this.upload_title.value;
538 if(prop=='tags') 544 if(prop=='tags')
539 this.files[ff].tags = this.upload_tags.value; 545 this.files[ff].tags = this.upload_tags.value;
540 this.tree.invalidateRow(ff); 546 this.tree.invalidateRow(ff);
541 } 547 }
542 } 548 }
543 }, 549 },
544 550
545 on_upload: function() { 551 on_upload: function() {
546 this.selToProps(); 552 this.selToProps();
547 this.batch_ids = new Array(); 553 this.batch_ids = new Array();
548 this.upload_progress.value=0; 554 this.upload_progress.value=0;
549 this.upload_progress.setAttribute('hidden','false'); 555 this.upload_progress.setAttribute('hidden','false');
550 this.upload_worker(); 556 this.upload_worker();
551 }, 557 },
552 on_clear: function() { 558 on_clear: function() {
553 this.clear_list(); 559 this.clear_list();
554 }, 560 },
555 on_remove: function() { 561 on_remove: function() {
556 if(this.selection.count) { 562 if(this.selection.count) {
557 this.tree.beginUpdateBatch(); 563 this.tree.beginUpdateBatch();
558 for(var i=this.files.length-1;i>=0;--i) { 564 for(var i=this.files.length-1;i>=0;--i) {
559 if(this.selection.isSelected(i)) { 565 if(this.selection.isSelected(i)) {
560 this.files.splice(i,1); 566 this.files.splice(i,1);
561 this.rowCount--; 567 this.rowCount--;
562 } 568 }
563 } 569 }
564 this.tree.endUpdateBatch(); 570 this.tree.endUpdateBatch();
565 this.selection.clearSelection(); 571 this.selection.clearSelection();
566 } 572 }
567 }, 573 },
568 on_add: function() { 574 on_add: function() {
569 var ifp = Components.interfaces.nsIFilePicker; 575 var ifp = Components.interfaces.nsIFilePicker;
570 var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp); 576 var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp);
571 fp.init(window, "Select a File", ifp.modeOpenMultiple); 577 fp.init(window, "Select a File", ifp.modeOpenMultiple);
572 fp.appendFilters(ifp.filterImages); 578 fp.appendFilters(ifp.filterImages);
573 var rv = fp.show(); 579 var rv = fp.show();
574 if(rv==ifp.returnOK) { 580 if(rv==ifp.returnOK) {
575 var ff = fp.files; 581 var ff = fp.files;
576 while(ff.hasMoreElements()) { 582 while(ff.hasMoreElements()) {
577 var f = ff.getNext(); 583 var f = ff.getNext();
578 f.QueryInterface(Components.interfaces.nsIFile); 584 f.QueryInterface(Components.interfaces.nsIFile);
579 this.add(f.path); 585 this.add(f.path);
580 } 586 }
581 } 587 }
582 } 588 }
583 }, 589 },
584 590
585 on_set_props: function() { 591 on_set_props: function() {
586 var pset = this.photosets.sets[this.photosets.selection.currentIndex]; 592 var pset = this.photosets.sets[this.photosets.selection.currentIndex];
587 window.openDialog( 593 window.openDialog(
588 "chrome://fireflix/content/photoset-props.xul", 594 "chrome://fireflix/content/photoset-props.xul",
589 null, "dependent,modal,dialog,chrome", this, 595 null, "dependent,modal,dialog,chrome", this,
590 pset ); 596 pset );
591 if(pset.dirty) { 597 if(pset.dirty) {
592 var _this = this; 598 var _this = this;
593 this.flickr.api_call( 599 this.flickr.api_call(
594 { 600 {
595 method: 'flickr.photosets.editMeta', 601 method: 'flickr.photosets.editMeta',
596 auth_token: 'default', 602 auth_token: 'default',
597 photoset_id: pset.id, 603 photoset_id: pset.id,
598 title: pset.title, 604 title: pset.title,
599 description: pset.description 605 description: pset.description
600 }, function(xr) { 606 }, function(xr) {
601 pset.dirty = false; 607 pset.dirty = false;
602 _this.flickr.api_call( 608 _this.flickr.api_call(
603 { 609 {
604 method: 'flickr.photosets.getPhotos', 610 method: 'flickr.photosets.getPhotos',
605 auth_token: 'default', 611 auth_token: 'default',
606 photoset_id: pset.id 612 photoset_id: pset.id
607 }, function(xr) { 613 }, function(xr) {
608 var x = xr.responseXML; 614 var x = xr.responseXML;
609 var xp = x.evaluate( 615 var xp = x.evaluate(
610 '/rsp/photoset/photo', x, null, 616 '/rsp/photoset/photo', x, null,
611 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 617 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
612 var phids = new Array(); 618 var phids = new Array();
613 var priph = null; 619 var priph = null;
614 var n; while(n=xp.iterateNext()) { 620 var n; while(n=xp.iterateNext()) {
615 var pid = n.getAttribute('id'); 621 var pid = n.getAttribute('id');
616 phids.push( pid ); 622 phids.push( pid );
617 if(pid==pset.primary && n.getAttribute('isprimary')!='1') 623 if(pid==pset.primary && n.getAttribute('isprimary')!='1')
618 priph = pid; 624 priph = pid;
619 } 625 }
620 if(priph) { 626 if(priph) {
621 _this.flickr.api_call( 627 _this.flickr.api_call(
622 { 628 {
623 method: 'flickr.photosets.editPhotos', 629 method: 'flickr.photosets.editPhotos',
624 auth_token: 'default', 630 auth_token: 'default',
625 photoset_id: pset.id, 631 photoset_id: pset.id,
626 primary_photo_id: priph, 632 primary_photo_id: priph,
627 photo_ids: phids.join(',') 633 photo_ids: phids.join(',')
628 }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ 634 }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */
629 _this.flickr_failure(x,s,c,m); 635 _this.flickr_failure(x,s,c,m);
630 } 636 }
631 ); 637 );
632 } 638 }
633 }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ 639 }, function(x,s,c,m) { /* flickr.photosets.getPhotos */
634 _this.flickr_failure(x,s,c,m); 640 _this.flickr_failure(x,s,c,m);
635 } 641 }
636 ); 642 );
637 }, function(x,s,c,m) { /* flickr.photosets.editMeta */ 643 }, function(x,s,c,m) { /* flickr.photosets.editMeta */
638 _this.flickr_failure(x,s,c,m); 644 _this.flickr_failure(x,s,c,m);
639 } 645 }
640 ); 646 );
641 } 647 }
642 }, 648 },
643 on_refresh_sets: function() { 649 on_refresh_sets: function() {
644 this.refresh_sets(); 650 this.refresh_sets();
645 }, 651 },
646 on_cmd_sets_html: function(csfx,ev) { 652 on_cmd_sets_html: function(csfx,ev) {
647 var uti = csfx.charAt(0); var utl = csfx.charAt(1); 653 var uti = csfx.charAt(0); var utl = csfx.charAt(1);
648 var rv = this.build_html(this.photoset.photos,uti,utl); 654 var rv = this.build_html(this.photoset.photos,uti,utl);
649 this.popup_content(rv); 655 this.popup_content(rv);
650 }, 656 },
651 657
652 on_cmd_uploads_html: function(csfx,ev) { 658 on_cmd_uploads_html: function(csfx,ev) {
653 var uti = csfx.charAt(0); var utl = csfx.charAt(1); 659 var uti = csfx.charAt(0); var utl = csfx.charAt(1);
654 var pids = new Array(); 660 var pids = new Array();
655 for(var f in this.uploads.files) { 661 for(var f in this.uploads.files) {
656 if(this.uploads.selection.isSelected(f)) 662 if(this.uploads.selection.isSelected(f))
657 if(this.uploads.files[f].photoid) 663 if(this.uploads.files[f].photoid)
658 pids.push(this.uploads.files[f].photoid); 664 pids.push(this.uploads.files[f].photoid);
659 } 665 }
660 var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; 666 var pp = this.uploads.rowCount*2; if(pp>500) pp = 500;
661 var _this = this; 667 var _this = this;
662 this.flickr.api_call( 668 this.flickr.api_call(
663 { 669 {
664 method: 'flickr.photos.search', 670 method: 'flickr.photos.search',
665 auth_token: 'default', 671 auth_token: 'default',
666 extras: 'original_format', 672 extras: 'original_format',
667 user_id: 'me', 673 user_id: 'me',
668 per_page: pp 674 per_page: pp
669 }, 675 },
670 function(xr) { 676 function(xr) {
671 var x = xr.responseXML; 677 var x = xr.responseXML;
672 var rv = ''; 678 var rv = '';
673 for(var pn in pids) { 679 for(var pn in pids) {
674 var p = pids[pn]; 680 var p = pids[pn];
675 var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); 681 var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x));
676 rv += _this.photo_html(pp,uti,utl)+'\n'; 682 rv += _this.photo_html(pp,uti,utl)+'\n';
677 } 683 }
678 _this.popup_content(rv); 684 _this.popup_content(rv);
679 }, function(x,s,c,m) { 685 }, function(x,s,c,m) {
680 _this.flickr_failure(x,s,c,m); 686 _this.flickr_failure(x,s,c,m);
681 } 687 }
682 ); 688 );
683 }, 689 },
684 690
685 /* 691 /*
686 * 692 *
687 */ 693 */
688 foundphotos: { 694 foundphotos: {
689 fireflix: null, 695 fireflix: null,
690 init: function(f) { 696 init: function(f) {
691 this.fireflix = f; 697 this.fireflix = f;
692 pull_elements(this,document,[ 698 pull_elements(this,document,[
693 'search_for','search_tags','search_mine', 699 'search_for','search_tags','search_mine',
694 'searchresult_props','search_photo', 700 'searchresult_props','search_photo',
695 'searchresult_title','searchresult_description', 701 'searchresult_title','searchresult_description',
696 'search_page','cmd_search_prev_page','cmd_search_next_page' 702 'search_page','cmd_search_prev_page','cmd_search_next_page'
697 ]); 703 ]);
698 document.getElementById('searchresults').view = this; 704 document.getElementById('searchresults').view = this;
699 }, 705 },
700 photos: new Array(), 706 photos: new Array(),
701 rowCount: 0, 707 rowCount: 0,
702 getCellText: function(r,c) { 708 getCellText: function(r,c) {
703 var p = this.photos[r]; 709 var p = this.photos[r];
704 if(c.id=='sr_title') return p.title; 710 if(c.id=='sr_title') return p.title;
705 return c.id; 711 return c.id;
706 }, 712 },
707 setTree: function(t) { this.tree = t }, 713 setTree: function(t) { this.tree = t },
708 isContainer: function(r) { return false }, 714 isContainer: function(r) { return false },
709 isSeparator: function(r) { return false }, 715 isSeparator: function(r) { return false },
710 isSorted: function(r) { return false }, 716 isSorted: function(r) { return false },
711 getLevel: function(r) { return 0 }, 717 getLevel: function(r) { return 0 },
712 getImageSrc: function(r,c) { return null }, 718 getImageSrc: function(r,c) { return null },
713 getRowProperties: function(r,p) { }, 719 getRowProperties: function(r,p) { },
714 getCellProperties: function(cid,cel,p) { }, 720 getCellProperties: function(cid,cel,p) { },
715 getColumnProperties: function(cid,cel,p) { }, 721 getColumnProperties: function(cid,cel,p) { },
716 cycleHeader: function(cid,e) { }, 722 cycleHeader: function(cid,e) { },
717 getParentIndex: function(r) { return -1 }, 723 getParentIndex: function(r) { return -1 },
718 drop: function(r,o) { }, 724 drop: function(r,o) { },
719 canDropBeforeAfter: function(r,b) { return false }, 725 canDropBeforeAfter: function(r,b) { return false },
720 726
721 importXPR: function(xp) { 727 importXPR: function(xp) {
722 this.selection.clearSelection(); 728 this.selection.clearSelection();
723 this.selection.currentIndex = -1; 729 this.selection.currentIndex = -1;
724 this.searchresult_props.hidden = true; 730 this.searchresult_props.hidden = true;
725 this.tree.beginUpdateBatch(); 731 this.tree.beginUpdateBatch();
726 this.photos = new Array(); 732 this.photos = new Array();
727 var n; while(n=xp.iterateNext()) { 733 var n; while(n=xp.iterateNext()) {
728 this.photos.push(new Photo(n)); 734 this.photos.push(new Photo(n));
729 } 735 }
730 this.rowCount = this.photos.length; 736 this.rowCount = this.photos.length;
731 this.tree.endUpdateBatch(); 737 this.tree.endUpdateBatch();
732 }, 738 },
733 paging: { 739 paging: {
734 pars: null, 740 pars: null,
735 page: null, pages: null, perpage: null, total: null 741 page: null, pages: null, perpage: null, total: null
736 }, 742 },
737 search_photos: function() { 743 search_photos: function() {
738 var pars = { 744 var pars = {
739 method: 'flickr.photos.search', 745 method: 'flickr.photos.search',
740 auth_token: 'default', 746 auth_token: 'default',
741 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' 747 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo'
742 }; 748 };
743 if(this.search_mine.checked) 749 if(this.search_mine.checked)
744 pars.user_id='me'; 750 pars.user_id='me';
745 if(this.search_tags.checked) { 751 if(this.search_tags.checked) {
746 pars.tags=this.search_for.value.split(/ +/).join(','); 752 pars.tags=this.search_for.value.split(/ +/).join(',');
747 }else{ 753 }else{
748 pars.text=this.search_for.value; 754 pars.text=this.search_for.value;
749 } 755 }
750 this.paging.pars = new Object(); 756 this.paging.pars = new Object();
751 this.paging.page = null; this.paging.pages = null; 757 this.paging.page = null; this.paging.pages = null;
752 this.paging.perpage = null; this.paging.total = null; 758 this.paging.perpage = null; this.paging.total = null;
753 for(var p in pars) this.paging.pars[p] = pars[p]; 759 for(var p in pars) this.paging.pars[p] = pars[p];
754 this.perform_search(pars); 760 this.perform_search(pars);
755 }, 761 },
756 perform_search: function(p) { 762 perform_search: function(p) {
757 var _this = this; 763 var _this = this;
758 this.fireflix.flickr.api_call( p, 764 this.fireflix.flickr.api_call( p,
759 function(xr) { 765 function(xr) {
760 var x = xr.responseXML; 766 var x = xr.responseXML;
761 var xp = xp_nodes('/rsp/photos/photo',x); 767 var xp = xp_nodes('/rsp/photos/photo',x);
762 _this.importXPR(xp); 768 _this.importXPR(xp);
763 _this.tree.ensureRowIsVisible(0); 769 _this.tree.ensureRowIsVisible(0);
764 xp = xp_node('/rsp/photos',x); 770 xp = xp_node('/rsp/photos',x);
765 _this.paging.page = parseInt(xp.getAttribute('page')); 771 _this.paging.page = parseInt(xp.getAttribute('page'));
766 _this.paging.pages = parseInt(xp.getAttribute('pages')); 772 _this.paging.pages = parseInt(xp.getAttribute('pages'));
767 _this.paging.perpage = parseInt(xp.getAttribute('perpage')); 773 _this.paging.perpage = parseInt(xp.getAttribute('perpage'));
768 _this.paging.total = parseInt(xp.getAttribute('total')); 774 _this.paging.total = parseInt(xp.getAttribute('total'));
769 _this.update_paging(); 775 _this.update_paging();
770 _this.on_select(); 776 _this.on_select();
771 }, function(x,s,c,m) { 777 }, function(x,s,c,m) {
772 _this.fireflix.flickr_failure(x,s,c,m); 778 _this.fireflix.flickr_failure(x,s,c,m);
773 } 779 }
774 ); 780 );
775 }, 781 },
776 on_cmd_prev: function(ev) { 782 on_cmd_prev: function(ev) {
777 var pars = new Object(); 783 var pars = new Object();
778 for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; 784 for(var p in this.paging.pars) pars[p] = this.paging.pars[p];
779 pars.page=this.paging.page-1; pars.per_page=this.paging.perpage; 785 pars.page=this.paging.page-1; pars.per_page=this.paging.perpage;
780 this.perform_search(pars); 786 this.perform_search(pars);
781 }, 787 },
782 on_cmd_next: function(ev) { 788 on_cmd_next: function(ev) {
783 var pars = new Object(); 789 var pars = new Object();
784 for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; 790 for(var p in this.paging.pars) pars[p] = this.paging.pars[p];
785 pars.page=this.paging.page+1; pars.per_page=this.paging.perpage; 791 pars.page=this.paging.page+1; pars.per_page=this.paging.perpage;
786 this.perform_search(pars); 792 this.perform_search(pars);
787 }, 793 },
788 update_paging: function() { 794 update_paging: function() {
789 if(! (this.paging.pars && this.paging.page && this.paging.pages) ) { 795 if(! (this.paging.pars && this.paging.page && this.paging.pages) ) {
790 this.search_page.value=''; this.search_page.hidden = true; 796 this.search_page.value=''; this.search_page.hidden = true;
791 this.cmd_search_prev_page.setAttribute('disabled','true'); 797 this.cmd_search_prev_page.setAttribute('disabled','true');
792 this.cmd_search_next_page.setAttribute('disabled','true'); 798 this.cmd_search_next_page.setAttribute('disabled','true');
793 }else{ 799 }else{
794 this.search_page.value=this.fireflix.loc_strings.getFormattedString('search_page',[this.paging.page,this.paging.pages]); 800 this.search_page.value=this.fireflix.loc_strings.getFormattedString('search_page',[this.paging.page,this.paging.pages]);
795 this.search_page.hidden=false; 801 this.search_page.hidden=false;
796 this.cmd_search_prev_page.setAttribute('disabled',(this.paging.page>1)?'false':'true'); 802 this.cmd_search_prev_page.setAttribute('disabled',(this.paging.page>1)?'false':'true');
797 this.cmd_search_next_page.setAttribute('disabled',(this.paging.page<this.paging.pages)?'false':'true'); 803 this.cmd_search_next_page.setAttribute('disabled',(this.paging.page<this.paging.pages)?'false':'true');
798 } 804 }
799 }, 805 },
800 render_description_frame: function(content) { 806 render_description_frame: function(content) {
801 this.searchresult_description.innerHTML = ''; 807 this.searchresult_description.innerHTML = '';
802 if(content) { 808 if(content) {
803 var dp = new DOMParser(); 809 var dp = new DOMParser();
804 var pd = dp.parseFromString( 810 var pd = dp.parseFromString(
805 '<div xmlns="http://www.w3.org/1999/xhtml">'+content+'</div>', 'text/xml' ); 811 '<div xmlns="http://www.w3.org/1999/xhtml">'+content+'</div>', 'text/xml' );
806 var de = pd.documentElement; 812 var de = pd.documentElement;
807 if(de.tagName=='parsererror') 813 if(de.tagName=='parsererror')
808 this.searchresult_description.innerHTML=this.fireflix.loc_strings.getString('broken_description'); 814 this.searchresult_description.innerHTML=this.fireflix.loc_strings.getString('broken_description');
809 else 815 else
810 this.searchresult_description.appendChild(de); 816 this.searchresult_description.appendChild(de);
811 /* of all linking elements flickr only allows a */ 817 /* of all linking elements flickr only allows a */
812 var as = this.searchresult_description.getElementsByTagName('a'); 818 var as = this.searchresult_description.getElementsByTagName('a');
813 for(var a=0;a<as.length;++a) 819 for(var a=0;a<as.length;++a)
814 as.item(a).setAttribute('target','_blank'); 820 as.item(a).setAttribute('target','_blank');
815 } 821 }
816 }, 822 },
817 on_select: function() { 823 on_select: function() {
818 if(this.selection.currentIndex<0) { 824 if(this.selection.currentIndex<0) {
819 this.searchresult_props.hidden = true; 825 this.searchresult_props.hidden = true;
820 }else{ 826 }else{
821 var p = this.photos[this.selection.currentIndex]; 827 var p = this.photos[this.selection.currentIndex];
822 if(!p) { 828 if(!p) {
823 this.searchresult_props.hidden = true; 829 this.searchresult_props.hidden = true;
824 }else{ 830 }else{
825 this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); 831 this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t');
826 this.searchresult_title.value = p.title; 832 this.searchresult_title.value = p.title;
827 this.searchresult_title.tooltipText = p.title; 833 this.searchresult_title.tooltipText = p.title;
828 this.render_description_frame(null); 834 this.render_description_frame(null);
829 if(p.description==null && p.description==undefined) { 835 if(p.description==null && p.description==undefined) {
830 var pid = p.id; 836 var pid = p.id;
831 var ci = this.selection.currentIndex; 837 var ci = this.selection.currentIndex;
832 var _this = this; 838 var _this = this;
833 this.fireflix.flickr.api_call( 839 this.fireflix.flickr.api_call(
834 { 840 {
835 method: 'flickr.photos.getInfo', 841 method: 'flickr.photos.getInfo',
836 auth_token: 'default', 842 auth_token: 'default',
837 photo_id: p.id, 843 photo_id: p.id,
838 secret: p.secret 844 secret: p.secret
839 }, function(xr) { 845 }, function(xr) {
840 var pp = _this.photos[ci]; 846 var pp = _this.photos[ci];
841 if(ci==_this.selection.currentIndex && pp.id==pid) { 847 if(ci==_this.selection.currentIndex && pp.id==pid) {
842 var n = xp_node('/rsp/photo',xr.responseXML); 848 var n = xp_node('/rsp/photo',xr.responseXML);
843 pp.fromNode_(n); 849 pp.fromNode_(n);
844 _this.render_description_frame(pp.description); 850 _this.render_description_frame(pp.description);
845 } 851 }
846 }, function(x,s,c,m) { 852 }, function(x,s,c,m) {
847 _this.fireflix.flickr_failure(x,s,c,m); 853 _this.fireflix.flickr_failure(x,s,c,m);
848 } 854 }
849 ); 855 );
850 this.searchresult_props.hidden = false; 856 this.searchresult_props.hidden = false;
851 }else{ 857 }else{
852 this.render_description_frame(p.description); 858 this.render_description_frame(p.description);
853 } 859 }
854 } 860 }
855 } 861 }
856 }, 862 },
857 on_cmd_open: function(ev) { 863 on_cmd_open: function(ev) {
858 if(this.selection.currentIndex<0) 864 if(this.selection.currentIndex<0)
859 return; 865 return;
860 var p = this.photos[this.selection.currentIndex]; 866 var p = this.photos[this.selection.currentIndex];
861 if(!p.id) 867 if(!p.id)
862 return; 868 return;
863 this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); 869 this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p'));
864 } 870 }
865 }, 871 },
866 872
867 photo_html: function(p,i,l) { 873 photo_html: function(p,i,l) {
868 // TODO: add alt/title when possible 874 // TODO: add alt/title when possible
869 var rv = 875 var rv =
870 '<a href="'+this.flickr.make_photo_url(p,l)+'">' + 876 '<a href="'+this.flickr.make_photo_url(p,l)+'">' +
871 '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+ 877 '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+
872 '</a>'; 878 '</a>';