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,902 +1,903 @@
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;
327 pull_elements(this,document,[ 328 pull_elements(this,document,[
328 'upload_filename','upload_title','upload_file_preview', 329 'upload_filename','upload_title','upload_file_preview',
329 'upload_file_props','upload_progress','upload_tags', 330 'upload_file_props','upload_progress','upload_tags',
330 'cmd_uploads_upload' 331 'cmd_uploads_upload'
331 ]); 332 ]);
332 document.getElementById('uploadlist').view = this; 333 document.getElementById('uploadlist').view = this;
333 }, 334 },
334 files: new Array(), 335 files: new Array(),
335 rowCount: 0, 336 rowCount: 0,
336 getCellText: function(r,c) { 337 getCellText: function(r,c) {
337 var f = this.files[r]; 338 var f = this.files[r];
338 if(c.id=='up_file') return f.file; 339 if(c.id=='up_file') return f.file;
339 if(c.id=='up_title') return f.title; 340 if(c.id=='up_title') return f.title;
340 if(c.id=='up_status') return f.state; 341 if(c.id=='up_status') return f.state;
341 return c.id; 342 return c.id;
342 }, 343 },
343 setTree: function(t) { this.tree = t }, 344 setTree: function(t) { this.tree = t },
344 isContainer: function(r) { return false; }, 345 isContainer: function(r) { return false; },
345 isSeparator: function(r) { return false; }, 346 isSeparator: function(r) { return false; },
346 isSorted: function(r) { return false; }, 347 isSorted: function(r) { return false; },
347 getLevel: function(r) { return 0; }, 348 getLevel: function(r) { return 0; },
348 getImageSrc: function(r,c) { return null }, 349 getImageSrc: function(r,c) { return null },
349 getRowProperties: function(r,p) { 350 getRowProperties: function(r,p) {
350 try { 351 try {
351 if(!Components) return; 352 if(!Components) return;
352 }catch(e) { return } 353 }catch(e) { return }
353 var f = this.files[r]; 354 var f = this.files[r];
354 var as = Components.classes['@mozilla.org/atom-service;1']. 355 var as = Components.classes['@mozilla.org/atom-service;1'].
355 getService(Components.interfaces.nsIAtomService); 356 getService(Components.interfaces.nsIAtomService);
356 p.AppendElement(as.getAtom(f.state)); 357 p.AppendElement(as.getAtom(f.state));
357 }, 358 },
358 getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, 359 getCellProperties: function(r,c,p) { this.getRowProperties(r,p); },
359 getColumnProperties: function(c,p) { }, 360 getColumnProperties: function(c,p) { },
360 cycleHeader: function(cid,e) { }, 361 cycleHeader: function(cid,e) { },
361 getParentIndex: function(r) { return -1; }, 362 getParentIndex: function(r) { return -1; },
362 drop: function(r,o) { }, 363 drop: function(r,o) { },
363 canDropBeforeAfter: function(r,b) { return false }, 364 canDropBeforeAfter: function(r,b) { return false },
364 365
365 add: function(f) { 366 add: function(f) {
366 if(f.indexOf('file:/')==0) { 367 if(f.indexOf('file:/')==0) {
367 f = f.substr(5); 368 f = f.substr(5);
368 while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) 369 while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-)
369 f = f.substr(1); 370 f = f.substr(1);
370 } 371 }
371 } 372 }
372 var t = f; 373 var t = f;
373 var ls = t.lastIndexOf('/'); 374 var ls = t.lastIndexOf('/');
374 if(ls>0) t = t.substr(ls+1); 375 if(ls>0) t = t.substr(ls+1);
375 ls = t.lastIndexOf('\\'); 376 ls = t.lastIndexOf('\\');
376 if(ls>0) t = t.substr(ls+1); 377 if(ls>0) t = t.substr(ls+1);
377 var ld = t.lastIndexOf('.'); 378 var ld = t.lastIndexOf('.');
378 if(ld>0) t = t.substr(0,ld); 379 if(ld>0) t = t.substr(0,ld);
379 this.files.push( { 380 this.files.push( {
380 file: f, 381 file: f,
381 title: t, 382 title: t,
382 tags: '', 383 tags: '',
383 state: 'pending' 384 state: 'pending'
384 } ); 385 } );
385 this.rowCount = this.files.length; 386 this.rowCount = this.files.length;
386 this.tree.rowCountChanged(this.rowCount-1,1); 387 this.tree.rowCountChanged(this.rowCount-1,1);
387 }, 388 },
388 389
389 upload_worker: function() { 390 upload_worker: function() {
390 for(var f in this.files) { 391 for(var f in this.files) {
391 if(this.files[f].state=='pending') { 392 if(this.files[f].state=='pending') {
392 var ff = this.files[f]; 393 var ff = this.files[f];
393 this.on_file_upload(ff); 394 this.on_file_upload(ff);
394 ff.state='uploading'; 395 ff.state='uploading';
395 this.tree.invalidate(); 396 this.tree.invalidate();
396 var _this = this; 397 var _this = this;
397 this.fireflix.flickr.upload_file( 398 this.fireflix.flickr.upload_file(
398 ff.file, { title: ff.title, tags: ff.tags }, 399 ff.file, { title: ff.title, tags: ff.tags },
399 function(x,p) { 400 function(x,p) {
400 ff.photoid = p; 401 ff.photoid = p;
401 _this.batch_ids.push(p); 402 _this.batch_ids.push(p);
402 ff.state='completed'; 403 ff.state='completed';
403 _this.tree.invalidate(); 404 _this.tree.invalidate();
404 window.setTimeout(_this.upload_to,0,_this); 405 window.setTimeout(_this.upload_to,0,_this);
405 }, function(x,s,c,m) { 406 }, function(x,s,c,m) {
406 ff.state='failed'; 407 ff.state='failed';
407 ff.flickr_errcode = c; 408 ff.flickr_errcode = c;
408 ff.flickr_errmsg = m; 409 ff.flickr_errmsg = m;
409 _this.tree.invalidate(); 410 _this.tree.invalidate();
410 window.setTimeout(_this.upload_to,0,_this); 411 window.setTimeout(_this.upload_to,0,_this);
411 } 412 }
412 ); 413 );
413 return; 414 return;
414 } 415 }
415 } 416 }
416 this.on_finish_upload(); 417 this.on_finish_upload();
417 }, 418 },
418 upload_to: function(_this) { _this.upload_worker(); }, 419 upload_to: function(_this) { _this.upload_worker(); },
419 on_file_upload: function(f) { 420 on_file_upload: function(f) {
420 this.cmd_uploads_upload.setAttribute('disabled','true'); 421 this.cmd_uploads_upload.setAttribute('disabled','true');
421 for(var fi in this.files) { 422 for(var fi in this.files) {
422 if(this.files[fi].file==f.file) { 423 if(this.files[fi].file==f.file) {
423 this.tree.ensureRowIsVisible(fi); 424 this.tree.ensureRowIsVisible(fi);
424 this.selection.rangedSelect(fi,fi,false); 425 this.selection.rangedSelect(fi,fi,false);
425 this.selection.currentIndex = fi; 426 this.selection.currentIndex = fi;
426 this.selToProps(); 427 this.selToProps();
427 break; 428 break;
428 } 429 }
429 } 430 }
430 }, 431 },
431 on_finish_upload: function() { 432 on_finish_upload: function() {
432 if(this.batch_ids.length) { 433 if(this.batch_ids.length) {
433 var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); 434 var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset'));
434 if(psn!=null) { 435 if(psn!=null) {
435 var pids = this.batch_ids.join(','); 436 var pids = this.batch_ids.join(',');
436 var ppid = this.batch_ids[0]; 437 var ppid = this.batch_ids[0];
437 var _this = this; 438 var _this = this;
438 this.fireflix.flickr.api_call( 439 this.fireflix.flickr.api_call(
439 { 440 {
440 method: 'flickr.photosets.create', 441 method: 'flickr.photosets.create',
441 auth_token: 'default', 442 auth_token: 'default',
442 title: psn, 443 title: psn,
443 primary_photo_id: ppid 444 primary_photo_id: ppid
444 }, function(x) { 445 }, function(x) {
445 var npid = 446 var npid =
446 x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id'); 447 x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id');
447 _this.fireflix.flickr.api_call( 448 _this.fireflix.flickr.api_call(
448 { 449 {
449 method: 'flickr.photosets.editPhotos', 450 method: 'flickr.photosets.editPhotos',
450 auth_token: 'default', 451 auth_token: 'default',
451 photoset_id: npid, 452 photoset_id: npid,
452 primary_photo_id: ppid, 453 primary_photo_id: ppid,
453 photo_ids: pids 454 photo_ids: pids
454 }, function(x) { 455 }, function(x) {
455 _this.fireflix.refresh_sets(); 456 _this.fireflix.refresh_sets();
456 }, function(x,s,c,m) { 457 }, function(x,s,c,m) {
457 _this.fireflix.flickr_failure(x,s,c,m); 458 _this.fireflix.flickr_failure(x,s,c,m);
458 } 459 }
459 ); 460 );
460 }, function(x,s,c,m) { 461 }, function(x,s,c,m) {
461 _this.fireflix.flickr_failure(x,s,c,m); 462 _this.fireflix.flickr_failure(x,s,c,m);
462 } 463 }
463 ); 464 );
464 } 465 }
465 } 466 }
466 this.selection.clearSelection(); 467 this.selection.clearSelection();
467 this.cmd_uploads_upload.setAttribute('disabled','false'); 468 this.cmd_uploads_upload.setAttribute('disabled','false');
468 this.upload_progress.setAttribute('hidden','true'); 469 this.upload_progress.setAttribute('hidden','true');
469 }, 470 },
470 471
471 clear_list: function() { 472 clear_list: function() {
472 this.tree.beginUpdateBatch(); 473 this.tree.beginUpdateBatch();
473 this.rowCount = 0; 474 this.rowCount = 0;
474 this.files = new Array(); 475 this.files = new Array();
475 this.tree.endUpdateBatch(); 476 this.tree.endUpdateBatch();
476 this.selToProps(); 477 this.selToProps();
477 }, 478 },
478 selectionChanged: function() { 479 selectionChanged: function() {
479 this.selToProps(); 480 this.selToProps();
480 }, 481 },
481 disableProps: function() { 482 disableProps: function() {
482 this.upload_filename.value=''; 483 this.upload_filename.value='';
483 this.upload_filename.disabled = true; 484 this.upload_filename.disabled = true;
484 this.upload_title.value=''; 485 this.upload_title.value='';
485 this.upload_title.disabled = true; 486 this.upload_title.disabled = true;
486 this.upload_file_preview.src = null; 487 this.upload_file_preview.src = null;
487 this.upload_file_props.hidden = true; 488 this.upload_file_props.hidden = true;
488 this.upload_tags.value=''; 489 this.upload_tags.value='';
489 this.upload_tags.disabled = true; 490 this.upload_tags.disabled = true;
490 }, 491 },
491 selToProps: function() { 492 selToProps: function() {
492 if(!this.selection.count) { 493 if(!this.selection.count) {
493 this.disableProps(); 494 this.disableProps();
494 }else if(this.selection.count==1) { 495 }else if(this.selection.count==1) {
495 var f=this.files[this.selection.currentIndex]; 496 var f=this.files[this.selection.currentIndex];
496 if(f==null || f.state!='pending') { 497 if(f==null || f.state!='pending') {
497 this.disableProps(); 498 this.disableProps();
498 }else{ 499 }else{
499 this.upload_filename.value = f.file; 500 this.upload_filename.value = f.file;
500 this.upload_filename.disabled = false; 501 this.upload_filename.disabled = false;
501 this.upload_title.value = f.title; 502 this.upload_title.value = f.title;
502 this.upload_title.disabled = false; 503 this.upload_title.disabled = false;
503 this.upload_file_preview.src = 'file:///'+f.file; 504 this.upload_file_preview.src = 'file:///'+f.file;
504 this.upload_file_props.hidden = false; 505 this.upload_file_props.hidden = false;
505 this.upload_tags.value = f.tags; 506 this.upload_tags.value = f.tags;
506 this.upload_tags.disabled = false; 507 this.upload_tags.disabled = false;
507 } 508 }
508 }else{ 509 }else{
509 var ftitle = null; var onetitle = true; 510 var ftitle = null; var onetitle = true;
510 var ftags = null; var onetag = true; 511 var ftags = null; var onetag = true;
511 var fs = 0; 512 var fs = 0;
512 for(var ff in this.files) { 513 for(var ff in this.files) {
513 if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { 514 if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) {
514 ++fs; 515 ++fs;
515 if(ftitle==null) { 516 if(ftitle==null) {
516 ftitle = this.files[ff].title; 517 ftitle = this.files[ff].title;
517 }else if(ftitle!=this.files[ff].title) { 518 }else if(ftitle!=this.files[ff].title) {
518 onetitle = false; 519 onetitle = false;
519 } 520 }
520 if(ftags==null) { 521 if(ftags==null) {
521 ftags = this.files[ff].tags; 522 ftags = this.files[ff].tags;
522 }else if(ftags!=this.files[ff].tags) { 523 }else if(ftags!=this.files[ff].tags) {
523 onetag = false; 524 onetag = false;
524 } 525 }
525 } 526 }
526 } 527 }
527 if(fs) { 528 if(fs) {
528 this.upload_filename.value=''; 529 this.upload_filename.value='';
529 this.upload_filename.disabled = true; 530 this.upload_filename.disabled = true;
530 if(onetitle) 531 if(onetitle)
531 this.upload_title.value = ftitle; 532 this.upload_title.value = ftitle;
532 this.upload_title.disabled = false; 533 this.upload_title.disabled = false;
533 if(onetag) 534 if(onetag)
534 this.upload_tags.value = ftags; 535 this.upload_tags.value = ftags;
535 this.upload_tags.disabled = false; 536 this.upload_tags.disabled = false;
536 this.upload_file_preview.src = null; 537 this.upload_file_preview.src = null;
537 this.upload_file_props.hidden = false; 538 this.upload_file_props.hidden = false;
538 }else 539 }else
539 this.disableProps(); 540 this.disableProps();
540 } 541 }
541 }, 542 },
542 propsToSel: function(prop) { 543 propsToSel: function(prop) {
543 if(this.selection.count<=0) return; 544 if(this.selection.count<=0) return;
544 for(var ff in this.files) { 545 for(var ff in this.files) {
545 if(this.selection.isSelected(ff) && this.files[ff].state=='pending') { 546 if(this.selection.isSelected(ff) && this.files[ff].state=='pending') {
546 if(prop=='filename') 547 if(prop=='filename')
547 this.files[ff].file = this.upload_filename.value; 548 this.files[ff].file = this.upload_filename.value;
548 if(prop=='title') 549 if(prop=='title')
549 this.files[ff].title = this.upload_title.value; 550 this.files[ff].title = this.upload_title.value;
550 if(prop=='tags') 551 if(prop=='tags')
551 this.files[ff].tags = this.upload_tags.value; 552 this.files[ff].tags = this.upload_tags.value;
552 this.tree.invalidateRow(ff); 553 this.tree.invalidateRow(ff);
553 } 554 }
554 } 555 }
555 }, 556 },
556 557
557 on_upload: function() { 558 on_upload: function() {
558 this.selToProps(); 559 this.selToProps();
559 this.batch_ids = new Array(); 560 this.batch_ids = new Array();
560 this.upload_progress.value=0; 561 this.upload_progress.value=0;
561 this.upload_progress.setAttribute('hidden','false'); 562 this.upload_progress.setAttribute('hidden','false');
562 this.upload_worker(); 563 this.upload_worker();
563 }, 564 },
564 on_clear: function() { 565 on_clear: function() {
565 this.clear_list(); 566 this.clear_list();
566 }, 567 },
567 on_remove: function() { 568 on_remove: function() {
568 if(this.selection.count) { 569 if(this.selection.count) {
569 this.tree.beginUpdateBatch(); 570 this.tree.beginUpdateBatch();
570 for(var i=this.files.length-1;i>=0;--i) { 571 for(var i=this.files.length-1;i>=0;--i) {
571 if(this.selection.isSelected(i)) { 572 if(this.selection.isSelected(i)) {
572 this.files.splice(i,1); 573 this.files.splice(i,1);
573 this.rowCount--; 574 this.rowCount--;
574 } 575 }
575 } 576 }
576 this.tree.endUpdateBatch(); 577 this.tree.endUpdateBatch();
577 this.selection.clearSelection(); 578 this.selection.clearSelection();
578 } 579 }
579 }, 580 },
580 on_add: function() { 581 on_add: function() {
581 var ifp = Components.interfaces.nsIFilePicker; 582 var ifp = Components.interfaces.nsIFilePicker;
582 var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp); 583 var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp);
583 fp.init(window, "Select a File", ifp.modeOpenMultiple); 584 fp.init(window, "Select a File", ifp.modeOpenMultiple);
584 fp.appendFilters(ifp.filterImages); 585 fp.appendFilters(ifp.filterImages);
585 var rv = fp.show(); 586 var rv = fp.show();
586 if(rv==ifp.returnOK) { 587 if(rv==ifp.returnOK) {
587 var ff = fp.files; 588 var ff = fp.files;
588 while(ff.hasMoreElements()) { 589 while(ff.hasMoreElements()) {
589 var f = ff.getNext(); 590 var f = ff.getNext();
590 f.QueryInterface(Components.interfaces.nsIFile); 591 f.QueryInterface(Components.interfaces.nsIFile);
591 this.add(f.path); 592 this.add(f.path);
592 } 593 }
593 } 594 }
594 } 595 }
595 }, 596 },
596 597
597 on_set_props: function() { 598 on_set_props: function() {
598 var pset = this.photosets.sets[this.photosets.selection.currentIndex]; 599 var pset = this.photosets.sets[this.photosets.selection.currentIndex];
599 window.openDialog( 600 window.openDialog(
600 "chrome://fireflix/content/photoset-props.xul", 601 "chrome://fireflix/content/photoset-props.xul",
601 null, "dependent,modal,dialog,chrome", this, 602 null, "dependent,modal,dialog,chrome", this,
602 pset ); 603 pset );
603 if(pset.dirty) { 604 if(pset.dirty) {
604 var _this = this; 605 var _this = this;
605 this.flickr.api_call( 606 this.flickr.api_call(
606 { 607 {
607 method: 'flickr.photosets.editMeta', 608 method: 'flickr.photosets.editMeta',
608 auth_token: 'default', 609 auth_token: 'default',
609 photoset_id: pset.id, 610 photoset_id: pset.id,
610 title: pset.title, 611 title: pset.title,
611 description: pset.description 612 description: pset.description
612 }, function(xr) { 613 }, function(xr) {
613 pset.dirty = false; 614 pset.dirty = false;
614 _this.flickr.api_call( 615 _this.flickr.api_call(
615 { 616 {
616 method: 'flickr.photosets.getPhotos', 617 method: 'flickr.photosets.getPhotos',
617 auth_token: 'default', 618 auth_token: 'default',
618 photoset_id: pset.id 619 photoset_id: pset.id
619 }, function(xr) { 620 }, function(xr) {
620 var x = xr.responseXML; 621 var x = xr.responseXML;
621 var xp = x.evaluate( 622 var xp = x.evaluate(
622 '/rsp/photoset/photo', x, null, 623 '/rsp/photoset/photo', x, null,
623 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 624 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
624 var phids = new Array(); 625 var phids = new Array();
625 var priph = null; 626 var priph = null;
626 var n; while(n=xp.iterateNext()) { 627 var n; while(n=xp.iterateNext()) {
627 var pid = n.getAttribute('id'); 628 var pid = n.getAttribute('id');
628 phids.push( pid ); 629 phids.push( pid );
629 if(pid==pset.primary && n.getAttribute('isprimary')!='1') 630 if(pid==pset.primary && n.getAttribute('isprimary')!='1')
630 priph = pid; 631 priph = pid;
631 } 632 }
632 if(priph) { 633 if(priph) {
633 _this.flickr.api_call( 634 _this.flickr.api_call(
634 { 635 {
635 method: 'flickr.photosets.editPhotos', 636 method: 'flickr.photosets.editPhotos',
636 auth_token: 'default', 637 auth_token: 'default',
637 photoset_id: pset.id, 638 photoset_id: pset.id,
638 primary_photo_id: priph, 639 primary_photo_id: priph,
639 photo_ids: phids.join(',') 640 photo_ids: phids.join(',')
640 }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ 641 }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */
641 _this.flickr_failure(x,s,c,m); 642 _this.flickr_failure(x,s,c,m);
642 } 643 }
643 ); 644 );
644 } 645 }
645 }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ 646 }, function(x,s,c,m) { /* flickr.photosets.getPhotos */
646 _this.flickr_failure(x,s,c,m); 647 _this.flickr_failure(x,s,c,m);
647 } 648 }
648 ); 649 );
649 }, function(x,s,c,m) { /* flickr.photosets.editMeta */ 650 }, function(x,s,c,m) { /* flickr.photosets.editMeta */
650 _this.flickr_failure(x,s,c,m); 651 _this.flickr_failure(x,s,c,m);
651 } 652 }
652 ); 653 );
653 } 654 }
654 }, 655 },
655 on_refresh_sets: function() { 656 on_refresh_sets: function() {
656 this.refresh_sets(); 657 this.refresh_sets();
657 }, 658 },
658 on_cmd_sets_html: function(csfx,ev) { 659 on_cmd_sets_html: function(csfx,ev) {
659 var uti = csfx.charAt(0); var utl = csfx.charAt(1); 660 var uti = csfx.charAt(0); var utl = csfx.charAt(1);
660 var rv = this.build_html(this.photoset.photos,uti,utl); 661 var rv = this.build_html(this.photoset.photos,uti,utl);
661 this.popup_content(rv); 662 this.popup_content(rv);
662 }, 663 },
663 664
664 on_cmd_uploads_html: function(csfx,ev) { 665 on_cmd_uploads_html: function(csfx,ev) {
665 var uti = csfx.charAt(0); var utl = csfx.charAt(1); 666 var uti = csfx.charAt(0); var utl = csfx.charAt(1);
666 var pids = new Array(); 667 var pids = new Array();
667 for(var f in this.uploads.files) { 668 for(var f in this.uploads.files) {
668 if(this.uploads.selection.isSelected(f)) 669 if(this.uploads.selection.isSelected(f))
669 if(this.uploads.files[f].photoid) 670 if(this.uploads.files[f].photoid)
670 pids.push(this.uploads.files[f].photoid); 671 pids.push(this.uploads.files[f].photoid);
671 } 672 }
672 var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; 673 var pp = this.uploads.rowCount*2; if(pp>500) pp = 500;
673 var _this = this; 674 var _this = this;
674 this.flickr.api_call( 675 this.flickr.api_call(
675 { 676 {
676 method: 'flickr.photos.search', 677 method: 'flickr.photos.search',
677 auth_token: 'default', 678 auth_token: 'default',
678 extras: 'original_format', 679 extras: 'original_format',
679 user_id: 'me', 680 user_id: 'me',
680 per_page: pp 681 per_page: pp
681 }, 682 },
682 function(xr) { 683 function(xr) {
683 var x = xr.responseXML; 684 var x = xr.responseXML;
684 var rv = ''; 685 var rv = '';
685 for(var pn in pids) { 686 for(var pn in pids) {
686 var p = pids[pn]; 687 var p = pids[pn];
687 var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); 688 var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x));
688 rv += _this.photo_html(pp,uti,utl)+'\n'; 689 rv += _this.photo_html(pp,uti,utl)+'\n';
689 } 690 }
690 _this.popup_content(rv); 691 _this.popup_content(rv);
691 }, function(x,s,c,m) { 692 }, function(x,s,c,m) {
692 _this.flickr_failure(x,s,c,m); 693 _this.flickr_failure(x,s,c,m);
693 } 694 }
694 ); 695 );
695 }, 696 },
696 697
697 /* 698 /*
698 * 699 *
699 */ 700 */
700 foundphotos: { 701 foundphotos: {
701 fireflix: null, 702 fireflix: null,
702 init: function(f) { 703 init: function(f) {
703 this.fireflix = f; 704 this.fireflix = f;
704 pull_elements(this,document,[ 705 pull_elements(this,document,[
705 'search_for','search_tags','search_mine', 706 'search_for','search_tags','search_mine',
706 'searchresult_props','search_photo', 707 'searchresult_props','search_photo',
707 'searchresult_title','searchresult_description', 708 'searchresult_title','searchresult_description',
708 'search_page','cmd_search_prev_page','cmd_search_next_page' 709 'search_page','cmd_search_prev_page','cmd_search_next_page'
709 ]); 710 ]);
710 document.getElementById('searchresults').view = this; 711 document.getElementById('searchresults').view = this;
711 }, 712 },
712 photos: new Array(), 713 photos: new Array(),
713 rowCount: 0, 714 rowCount: 0,
714 getCellText: function(r,c) { 715 getCellText: function(r,c) {
715 var p = this.photos[r]; 716 var p = this.photos[r];
716 if(c.id=='sr_title') return p.title; 717 if(c.id=='sr_title') return p.title;
717 return c.id; 718 return c.id;
718 }, 719 },
719 setTree: function(t) { this.tree = t }, 720 setTree: function(t) { this.tree = t },
720 isContainer: function(r) { return false }, 721 isContainer: function(r) { return false },
721 isSeparator: function(r) { return false }, 722 isSeparator: function(r) { return false },
722 isSorted: function(r) { return false }, 723 isSorted: function(r) { return false },
723 getLevel: function(r) { return 0 }, 724 getLevel: function(r) { return 0 },
724 getImageSrc: function(r,c) { return null }, 725 getImageSrc: function(r,c) { return null },
725 getRowProperties: function(r,p) { }, 726 getRowProperties: function(r,p) { },
726 getCellProperties: function(cid,cel,p) { }, 727 getCellProperties: function(cid,cel,p) { },
727 getColumnProperties: function(cid,cel,p) { }, 728 getColumnProperties: function(cid,cel,p) { },
728 cycleHeader: function(cid,e) { }, 729 cycleHeader: function(cid,e) { },
729 getParentIndex: function(r) { return -1 }, 730 getParentIndex: function(r) { return -1 },
730 drop: function(r,o) { }, 731 drop: function(r,o) { },
731 canDropBeforeAfter: function(r,b) { return false }, 732 canDropBeforeAfter: function(r,b) { return false },
732 733
733 importXPR: function(xp) { 734 importXPR: function(xp) {
734 this.selection.clearSelection(); 735 this.selection.clearSelection();
735 this.selection.currentIndex = -1; 736 this.selection.currentIndex = -1;
736 this.searchresult_props.hidden = true; 737 this.searchresult_props.hidden = true;
737 this.tree.beginUpdateBatch(); 738 this.tree.beginUpdateBatch();
738 this.photos = new Array(); 739 this.photos = new Array();
739 var n; while(n=xp.iterateNext()) { 740 var n; while(n=xp.iterateNext()) {
740 this.photos.push(new Photo(n)); 741 this.photos.push(new Photo(n));
741 } 742 }
742 this.rowCount = this.photos.length; 743 this.rowCount = this.photos.length;
743 this.tree.endUpdateBatch(); 744 this.tree.endUpdateBatch();
744 }, 745 },
745 paging: { 746 paging: {
746 pars: null, 747 pars: null,
747 page: null, pages: null, perpage: null, total: null 748 page: null, pages: null, perpage: null, total: null
748 }, 749 },
749 search_photos: function() { 750 search_photos: function() {
750 var pars = { 751 var pars = {
751 method: 'flickr.photos.search', 752 method: 'flickr.photos.search',
752 auth_token: 'default', 753 auth_token: 'default',
753 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' 754 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo'
754 }; 755 };
755 if(this.search_mine.checked) 756 if(this.search_mine.checked)
756 pars.user_id='me'; 757 pars.user_id='me';
757 if(this.search_tags.checked) { 758 if(this.search_tags.checked) {
758 pars.tags=this.search_for.value.split(/ +/).join(','); 759 pars.tags=this.search_for.value.split(/ +/).join(',');
759 }else{ 760 }else{
760 pars.text=this.search_for.value; 761 pars.text=this.search_for.value;
761 } 762 }
762 this.paging.pars = new Object(); 763 this.paging.pars = new Object();
763 this.paging.page = null; this.paging.pages = null; 764 this.paging.page = null; this.paging.pages = null;
764 this.paging.perpage = null; this.paging.total = null; 765 this.paging.perpage = null; this.paging.total = null;
765 for(var p in pars) this.paging.pars[p] = pars[p]; 766 for(var p in pars) this.paging.pars[p] = pars[p];
766 this.perform_search(pars); 767 this.perform_search(pars);
767 }, 768 },
768 perform_search: function(p) { 769 perform_search: function(p) {
769 var _this = this; 770 var _this = this;
770 this.fireflix.flickr.api_call( p, 771 this.fireflix.flickr.api_call( p,
771 function(xr) { 772 function(xr) {
772 var x = xr.responseXML; 773 var x = xr.responseXML;
773 var xp = xp_nodes('/rsp/photos/photo',x); 774 var xp = xp_nodes('/rsp/photos/photo',x);
774 _this.importXPR(xp); 775 _this.importXPR(xp);
775 _this.tree.ensureRowIsVisible(0); 776 _this.tree.ensureRowIsVisible(0);
776 xp = xp_node('/rsp/photos',x); 777 xp = xp_node('/rsp/photos',x);
777 _this.paging.page = parseInt(xp.getAttribute('page')); 778 _this.paging.page = parseInt(xp.getAttribute('page'));
778 _this.paging.pages = parseInt(xp.getAttribute('pages')); 779 _this.paging.pages = parseInt(xp.getAttribute('pages'));
779 _this.paging.perpage = parseInt(xp.getAttribute('perpage')); 780 _this.paging.perpage = parseInt(xp.getAttribute('perpage'));
780 _this.paging.total = parseInt(xp.getAttribute('total')); 781 _this.paging.total = parseInt(xp.getAttribute('total'));
781 _this.update_paging(); 782 _this.update_paging();
782 _this.on_select(); 783 _this.on_select();
783 }, function(x,s,c,m) { 784 }, function(x,s,c,m) {
784 _this.fireflix.flickr_failure(x,s,c,m); 785 _this.fireflix.flickr_failure(x,s,c,m);
785 } 786 }
786 ); 787 );
787 }, 788 },
788 on_cmd_prev: function(ev) { 789 on_cmd_prev: function(ev) {
789 var pars = new Object(); 790 var pars = new Object();
790 for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; 791 for(var p in this.paging.pars) pars[p] = this.paging.pars[p];
791 pars.page=this.paging.page-1; pars.per_page=this.paging.perpage; 792 pars.page=this.paging.page-1; pars.per_page=this.paging.perpage;
792 this.perform_search(pars); 793 this.perform_search(pars);
793 }, 794 },
794 on_cmd_next: function(ev) { 795 on_cmd_next: function(ev) {
795 var pars = new Object(); 796 var pars = new Object();
796 for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; 797 for(var p in this.paging.pars) pars[p] = this.paging.pars[p];
797 pars.page=this.paging.page+1; pars.per_page=this.paging.perpage; 798 pars.page=this.paging.page+1; pars.per_page=this.paging.perpage;
798 this.perform_search(pars); 799 this.perform_search(pars);
799 }, 800 },
800 update_paging: function() { 801 update_paging: function() {
801 if(! (this.paging.pars && this.paging.page && this.paging.pages) ) { 802 if(! (this.paging.pars && this.paging.page && this.paging.pages) ) {
802 this.search_page.value=''; this.search_page.hidden = true; 803 this.search_page.value=''; this.search_page.hidden = true;
803 this.cmd_search_prev_page.setAttribute('disabled','true'); 804 this.cmd_search_prev_page.setAttribute('disabled','true');
804 this.cmd_search_next_page.setAttribute('disabled','true'); 805 this.cmd_search_next_page.setAttribute('disabled','true');
805 }else{ 806 }else{
806 this.search_page.value=this.fireflix.loc_strings.getFormattedString('search_page',[this.paging.page,this.paging.pages]); 807 this.search_page.value=this.fireflix.loc_strings.getFormattedString('search_page',[this.paging.page,this.paging.pages]);
807 this.search_page.hidden=false; 808 this.search_page.hidden=false;
808 this.cmd_search_prev_page.setAttribute('disabled',(this.paging.page>1)?'false':'true'); 809 this.cmd_search_prev_page.setAttribute('disabled',(this.paging.page>1)?'false':'true');
809 this.cmd_search_next_page.setAttribute('disabled',(this.paging.page<this.paging.pages)?'false':'true'); 810 this.cmd_search_next_page.setAttribute('disabled',(this.paging.page<this.paging.pages)?'false':'true');
810 } 811 }
811 }, 812 },
812 render_description_frame: function(content) { 813 render_description_frame: function(content) {
813 this.searchresult_description.innerHTML = ''; 814 this.searchresult_description.innerHTML = '';
814 if(content) { 815 if(content) {
815 var dp = new DOMParser(); 816 var dp = new DOMParser();
816 var pd = dp.parseFromString( 817 var pd = dp.parseFromString(
817 '<div xmlns="http://www.w3.org/1999/xhtml">'+content+'</div>', 'text/xml' ); 818 '<div xmlns="http://www.w3.org/1999/xhtml">'+content+'</div>', 'text/xml' );
818 var de = pd.documentElement; 819 var de = pd.documentElement;
819 if(de.tagName=='parsererror') 820 if(de.tagName=='parsererror')
820 this.searchresult_description.innerHTML=this.fireflix.loc_strings.getString('broken_description'); 821 this.searchresult_description.innerHTML=this.fireflix.loc_strings.getString('broken_description');
821 else 822 else
822 this.searchresult_description.appendChild(de); 823 this.searchresult_description.appendChild(de);
823 /* of all linking elements flickr only allows a */ 824 /* of all linking elements flickr only allows a */
824 var as = this.searchresult_description.getElementsByTagName('a'); 825 var as = this.searchresult_description.getElementsByTagName('a');
825 for(var a=0;a<as.length;++a) 826 for(var a=0;a<as.length;++a)
826 as.item(a).setAttribute('target','_blank'); 827 as.item(a).setAttribute('target','_blank');
827 } 828 }
828 }, 829 },
829 on_select: function() { 830 on_select: function() {
830 if(this.selection.currentIndex<0) { 831 if(this.selection.currentIndex<0) {
831 this.searchresult_props.hidden = true; 832 this.searchresult_props.hidden = true;
832 }else{ 833 }else{
833 var p = this.photos[this.selection.currentIndex]; 834 var p = this.photos[this.selection.currentIndex];
834 if(!p) { 835 if(!p) {
835 this.searchresult_props.hidden = true; 836 this.searchresult_props.hidden = true;
836 }else{ 837 }else{
837 this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); 838 this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t');
838 this.searchresult_title.value = p.title; 839 this.searchresult_title.value = p.title;
839 this.searchresult_title.tooltipText = p.title; 840 this.searchresult_title.tooltipText = p.title;
840 this.render_description_frame(null); 841 this.render_description_frame(null);
841 if(p.description==null && p.description==undefined) { 842 if(p.description==null && p.description==undefined) {
842 var pid = p.id; 843 var pid = p.id;
843 var ci = this.selection.currentIndex; 844 var ci = this.selection.currentIndex;
844 var _this = this; 845 var _this = this;
845 this.fireflix.flickr.api_call( 846 this.fireflix.flickr.api_call(
846 { 847 {
847 method: 'flickr.photos.getInfo', 848 method: 'flickr.photos.getInfo',
848 auth_token: 'default', 849 auth_token: 'default',
849 photo_id: p.id, 850 photo_id: p.id,
850 secret: p.secret 851 secret: p.secret
851 }, function(xr) { 852 }, function(xr) {
852 var pp = _this.photos[ci]; 853 var pp = _this.photos[ci];
853 if(ci==_this.selection.currentIndex && pp.id==pid) { 854 if(ci==_this.selection.currentIndex && pp.id==pid) {
854 var n = xp_node('/rsp/photo',xr.responseXML); 855 var n = xp_node('/rsp/photo',xr.responseXML);
855 pp.fromNode_(n); 856 pp.fromNode_(n);
856 _this.render_description_frame(pp.description); 857 _this.render_description_frame(pp.description);
857 } 858 }
858 }, function(x,s,c,m) { 859 }, function(x,s,c,m) {
859 _this.fireflix.flickr_failure(x,s,c,m); 860 _this.fireflix.flickr_failure(x,s,c,m);
860 } 861 }
861 ); 862 );
862 this.searchresult_props.hidden = false; 863 this.searchresult_props.hidden = false;
863 }else{ 864 }else{
864 this.render_description_frame(p.description); 865 this.render_description_frame(p.description);
865 } 866 }
866 } 867 }
867 } 868 }
868 }, 869 },
869 on_cmd_open: function(ev) { 870 on_cmd_open: function(ev) {
870 if(this.selection.currentIndex<0) 871 if(this.selection.currentIndex<0)
871 return; 872 return;
872 var p = this.photos[this.selection.currentIndex]; 873 var p = this.photos[this.selection.currentIndex];
873 if(!p.id) 874 if(!p.id)
874 return; 875 return;
875 this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); 876 this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p'));
876 } 877 }
877 }, 878 },
878 879
879 photo_html: function(p,i,l) { 880 photo_html: function(p,i,l) {
880 // TODO: add alt/title when possible 881 // TODO: add alt/title when possible
881 var rv = 882 var rv =
882 '<a href="'+this.flickr.make_photo_url(p,l)+'">' + 883 '<a href="'+this.flickr.make_photo_url(p,l)+'">' +
883 '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+ 884 '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+
884 '</a>'; 885 '</a>';
885 return rv; 886 return rv;
886 }, 887 },
887 build_html: function(photos,uti,utl) { 888 build_html: function(photos,uti,utl) {
888 var rv = ''; 889 var rv = '';
889 for(var i in photos) { 890 for(var i in photos) {
890 var p = photos[i]; 891 var p = photos[i];
891 rv += this.photo_html(p,uti,utl)+'\n'; 892 rv += this.photo_html(p,uti,utl)+'\n';
892 } 893 }
893 return rv; 894 return rv;
894 }, 895 },
895 896
896 popup_content: function(s) { 897 popup_content: function(s) {
897 window.openDialog( 898 window.openDialog(
898 "chrome://fireflix/content/generated-content.xul", 899 "chrome://fireflix/content/generated-content.xul",
899 null, "dialog,chrome", this, s ); 900 null, "dialog,chrome", this, s );
900 }, 901 },
901 copy_to_clipboard: function(s) { 902 copy_to_clipboard: function(s) {
902 var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"] 903 var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"]