-rw-r--r-- | content/fireflix.js | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/content/fireflix.js b/content/fireflix.js index 966630c..63a4118 100644 --- a/content/fireflix.js +++ b/content/fireflix.js | |||
@@ -1,232 +1,231 @@ | |||
1 | function splitascii(s) { | 1 | function 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 | ||
12 | var fireflix = { | 12 | var 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 | document.getElementById('setslist').view = this.photosets; | ||
31 | document.getElementById('setphotos').view = this.photoset; | ||
32 | document.getElementById('uploadlist').view = this.uploads; | ||
33 | this.no_auth_info_label = this.auth_info.value; | 30 | this.no_auth_info_label = this.auth_info.value; |
34 | this.set_auth_state(this.flickr.token,false); | 31 | this.set_auth_state(this.flickr.token,false); |
35 | if(this.flickr.token) { | 32 | if(this.flickr.token) { |
36 | this.refresh_stuff(); | 33 | this.refresh_stuff(); |
37 | }else{ | 34 | }else{ |
38 | this.on_cmd_auth(); | 35 | this.on_cmd_auth(); |
39 | } | 36 | } |
40 | }, | 37 | }, |
41 | set_auth_state: function(au,inp) { /* authorized, in progress */ | 38 | set_auth_state: function(au,inp) { /* authorized, in progress */ |
42 | this.cmd_auth_unauth.disabled = !au; | 39 | this.cmd_auth_unauth.disabled = !au; |
43 | this.b_auth.hidden = au || inp; | 40 | this.b_auth.hidden = au || inp; |
44 | this.b_auth_done.hidden = !inp; | 41 | this.b_auth_done.hidden = !inp; |
45 | this.menu_auth_done.hidden = !inp; | 42 | this.menu_auth_done.hidden = !inp; |
46 | this.cmd_auth_done.setAttribute('disabled',!inp); | 43 | this.cmd_auth_done.setAttribute('disabled',!inp); |
47 | this.auth_info.disabled = !au; | 44 | this.auth_info.disabled = !au; |
48 | if(au) { | 45 | if(au) { |
49 | 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 */ |
50 | }else{ | 47 | }else{ |
51 | this.auth_info.value = this.no_auth_info_label; | 48 | this.auth_info.value = this.no_auth_info_label; |
52 | } | 49 | } |
53 | }, | 50 | }, |
54 | on_cmd_auth: function() { | 51 | on_cmd_auth: function() { |
55 | var _this = this; | 52 | var _this = this; |
56 | this.flickr.authorize_0( | 53 | this.flickr.authorize_0( |
57 | 'delete', | 54 | 'delete', |
58 | function(x,f,u) { | 55 | function(x,f,u) { |
59 | _this.openTab(u); | 56 | _this.openTab(u); |
60 | _this.set_auth_state(_this.flickr.token,true); | 57 | _this.set_auth_state(_this.flickr.token,true); |
61 | }, function(x,s,c,m) { | 58 | }, function(x,s,c,m) { |
62 | _this.flickr_failure(x,s,c,m); | 59 | _this.flickr_failure(x,s,c,m); |
63 | } | 60 | } |
64 | ); | 61 | ); |
65 | }, | 62 | }, |
66 | on_cmd_auth_done: function() { | 63 | on_cmd_auth_done: function() { |
67 | this.set_auth_state(this.flickr.token,false); | 64 | this.set_auth_state(this.flickr.token,false); |
68 | var _this = this; | 65 | var _this = this; |
69 | this.flickr.authorize_1( | 66 | this.flickr.authorize_1( |
70 | function() { | 67 | function() { |
71 | _this.flickr.save_token(); | 68 | _this.flickr.save_token(); |
72 | _this.refresh_stuff(); | 69 | _this.refresh_stuff(); |
73 | _this.set_auth_state(_this.flickr.token,false); | 70 | _this.set_auth_state(_this.flickr.token,false); |
74 | _this.auth_info.value = | 71 | _this.auth_info.value = |
75 | _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; | 72 | _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; |
76 | }, function(x,s,c,m) { | 73 | }, function(x,s,c,m) { |
77 | _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? */ |
78 | _this.flickr_failure(x,s,c,m); | 75 | _this.flickr_failure(x,s,c,m); |
79 | } | 76 | } |
80 | ); | 77 | ); |
81 | }, | 78 | }, |
82 | on_cmd_auth_unauth: function() { | 79 | on_cmd_auth_unauth: function() { |
83 | this.flickr.reset_token(); | 80 | this.flickr.reset_token(); |
84 | this.set_auth_state(false,false); | 81 | this.set_auth_state(false,false); |
85 | }, | 82 | }, |
86 | 83 | ||
87 | refresh_sets: function() { this.photosets.refresh_sets(); }, | 84 | refresh_sets: function() { this.photosets.refresh_sets(); }, |
88 | refresh_stuff: function() { | 85 | refresh_stuff: function() { |
89 | this.refresh_sets(); | 86 | this.refresh_sets(); |
90 | this.refresh_user_tags(); | 87 | this.refresh_user_tags(); |
91 | }, | 88 | }, |
92 | 89 | ||
93 | /* photoset treeview */ | 90 | /* photoset treeview */ |
94 | photoset: { | 91 | photoset: { |
95 | photos: new Array(), | 92 | photos: new Array(), |
96 | fireflix: null, | 93 | fireflix: null, |
97 | init: function(f) { | 94 | init: function(f) { |
98 | this.fireflix = f; | 95 | this.fireflix = f; |
99 | pull_elements(this,document,[ 'set_photo' ]); | 96 | pull_elements(this,document,[ 'set_photo' ]); |
97 | document.getElementById('setphotos').view = this; | ||
100 | }, | 98 | }, |
101 | rowCount: 0, | 99 | rowCount: 0, |
102 | getCellText: function(r,c) { | 100 | getCellText: function(r,c) { |
103 | var p = this.photos[r]; | 101 | var p = this.photos[r]; |
104 | if(c.id=='sp_title') return p.title; | 102 | if(c.id=='sp_title') return p.title; |
105 | if(c.id=='sp_taken') return p.datetaken; | 103 | if(c.id=='sp_taken') return p.datetaken; |
106 | if(c.id=='sp_upload') return p.dateupload; /* TODO: unixtime conversion */ | 104 | if(c.id=='sp_upload') return p.dateupload; /* TODO: unixtime conversion */ |
107 | return c.id; | 105 | return c.id; |
108 | }, | 106 | }, |
109 | setTree: function(t) { this.tree = t }, | 107 | setTree: function(t) { this.tree = t }, |
110 | isContainer: function(r) { return false; }, | 108 | isContainer: function(r) { return false; }, |
111 | isSeparator: function(r) { return false; }, | 109 | isSeparator: function(r) { return false; }, |
112 | isSorted: function(r) { return false; }, | 110 | isSorted: function(r) { return false; }, |
113 | getLevel: function(r) { return 0; }, | 111 | getLevel: function(r) { return 0; }, |
114 | getImageSrc: function(r,c) { return null }, | 112 | getImageSrc: function(r,c) { return null }, |
115 | getRowProperties: function(r,p) {}, | 113 | getRowProperties: function(r,p) {}, |
116 | getCellProperties: function(cid,cel,p) {}, | 114 | getCellProperties: function(cid,cel,p) {}, |
117 | getColumnProperties: function(cid,cel,p) { }, | 115 | getColumnProperties: function(cid,cel,p) { }, |
118 | cycleHeader: function(cid,e) { }, | 116 | cycleHeader: function(cid,e) { }, |
119 | getParentIndex: function(r) { return -1; }, | 117 | getParentIndex: function(r) { return -1; }, |
120 | drop: function(r,o) { }, | 118 | drop: function(r,o) { }, |
121 | canDropBeforeAfter: function(r,b) { return false }, | 119 | canDropBeforeAfter: function(r,b) { return false }, |
122 | 120 | ||
123 | importXPR: function(xp) { | 121 | importXPR: function(xp) { |
124 | this.tree.beginUpdateBatch(); | 122 | this.tree.beginUpdateBatch(); |
125 | this.photos = new Array(); | 123 | this.photos = new Array(); |
126 | var n; while(n=xp.iterateNext()) { | 124 | var n; while(n=xp.iterateNext()) { |
127 | this.photos.push(new Photo(n)); | 125 | this.photos.push(new Photo(n)); |
128 | } | 126 | } |
129 | this.rowCount = this.photos.length; | 127 | this.rowCount = this.photos.length; |
130 | this.tree.endUpdateBatch(); | 128 | this.tree.endUpdateBatch(); |
131 | }, | 129 | }, |
132 | load_photos: function(psid) { | 130 | load_photos: function(psid) { |
133 | var _this = this; | 131 | var _this = this; |
134 | this.fireflix.flickr.api_call( | 132 | this.fireflix.flickr.api_call( |
135 | { | 133 | { |
136 | method: 'flickr.photosets.getPhotos', | 134 | method: 'flickr.photosets.getPhotos', |
137 | auth_token: 'default', | 135 | auth_token: 'default', |
138 | photoset_id: psid, | 136 | photoset_id: psid, |
139 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' | 137 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' |
140 | }, function(xr) { | 138 | }, function(xr) { |
141 | var x = xr.responseXML; | 139 | var x = xr.responseXML; |
142 | var xp = x.evaluate( | 140 | var xp = x.evaluate( |
143 | '/rsp/photoset/photo', x, null, | 141 | '/rsp/photoset/photo', x, null, |
144 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 142 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
145 | _this.importXPR(xp); | 143 | _this.importXPR(xp); |
146 | }, function(x,s,c,m) { | 144 | }, function(x,s,c,m) { |
147 | _this.fireflix.flickr_failure(x,s,c,m); | 145 | _this.fireflix.flickr_failure(x,s,c,m); |
148 | } | 146 | } |
149 | ); | 147 | ); |
150 | }, | 148 | }, |
151 | on_select: function() { | 149 | on_select: function() { |
152 | if(this.selection.count==1) { | 150 | if(this.selection.count==1) { |
153 | var p = this.photos[this.selection.currentIndex]; | 151 | var p = this.photos[this.selection.currentIndex]; |
154 | this.set_photo.src = | 152 | this.set_photo.src = |
155 | this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t'); | 153 | this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t'); |
156 | this.set_photo.hidden = false; | 154 | this.set_photo.hidden = false; |
157 | }else{ | 155 | }else{ |
158 | this.set_photo.hidden = true; | 156 | this.set_photo.hidden = true; |
159 | } | 157 | } |
160 | } | 158 | } |
161 | }, | 159 | }, |
162 | 160 | ||
163 | /* photosets treeview */ | 161 | /* photosets treeview */ |
164 | photosets: { | 162 | photosets: { |
165 | sets: new Array(), | 163 | sets: new Array(), |
166 | fireflix: null, | 164 | fireflix: null, |
167 | init: function(f) { | 165 | init: function(f) { |
168 | this.fireflix = f; | 166 | this.fireflix = f; |
167 | document.getElementById('setslist').view = this; | ||
169 | }, | 168 | }, |
170 | rowCount: 0, | 169 | rowCount: 0, |
171 | getCellText: function(r,c) { | 170 | getCellText: function(r,c) { |
172 | var s = this.sets[r]; | 171 | var s = this.sets[r]; |
173 | if(c.id=='sl_name') return s.title; | 172 | if(c.id=='sl_name') return s.title; |
174 | if(c.id=='sl_photos') return s.photos; | 173 | if(c.id=='sl_photos') return s.photos; |
175 | return c.id; | 174 | return c.id; |
176 | }, | 175 | }, |
177 | setTree: function(t) { this.tree = t }, | 176 | setTree: function(t) { this.tree = t }, |
178 | isContainer: function(r) { return false; }, | 177 | isContainer: function(r) { return false; }, |
179 | isSeparator: function(r) { return false; }, | 178 | isSeparator: function(r) { return false; }, |
180 | isSorted: function() { return false; }, | 179 | isSorted: function() { return false; }, |
181 | getLevel: function(r) { return 0; }, | 180 | getLevel: function(r) { return 0; }, |
182 | getImageSrc: function(r,c) { return null }, | 181 | getImageSrc: function(r,c) { return null }, |
183 | getRowProperties: function(r,p) {}, | 182 | getRowProperties: function(r,p) {}, |
184 | getCellProperties: function(cid,cel,p) { }, | 183 | getCellProperties: function(cid,cel,p) { }, |
185 | getColumnProperties: function(cid,cel,p) { }, | 184 | getColumnProperties: function(cid,cel,p) { }, |
186 | cycleHeader: function(cid,e) { }, | 185 | cycleHeader: function(cid,e) { }, |
187 | getParentIndex: function(r) { return -1; }, | 186 | getParentIndex: function(r) { return -1; }, |
188 | drop: function(r,o) { }, | 187 | drop: function(r,o) { }, |
189 | canDropBeforeAfter: function(r,b) { return false }, | 188 | canDropBeforeAfter: function(r,b) { return false }, |
190 | 189 | ||
191 | importXPR: function(xp) { | 190 | importXPR: function(xp) { |
192 | this.tree.beginUpdateBatch(); | 191 | this.tree.beginUpdateBatch(); |
193 | this.sets = new Array(); | 192 | this.sets = new Array(); |
194 | var n; while(n=xp.iterateNext()) { | 193 | var n; while(n=xp.iterateNext()) { |
195 | this.sets.push(new Photoset(n)); | 194 | this.sets.push(new Photoset(n)); |
196 | } | 195 | } |
197 | this.rowCount = this.sets.length; | 196 | this.rowCount = this.sets.length; |
198 | this.tree.endUpdateBatch(); | 197 | this.tree.endUpdateBatch(); |
199 | }, | 198 | }, |
200 | refresh_sets: function() { | 199 | refresh_sets: function() { |
201 | var _this = this; | 200 | var _this = this; |
202 | this.fireflix.flickr.api_call( | 201 | this.fireflix.flickr.api_call( |
203 | { | 202 | { |
204 | method: 'flickr.photosets.getList', | 203 | method: 'flickr.photosets.getList', |
205 | auth_token: 'default' | 204 | auth_token: 'default' |
206 | }, function(xr) { | 205 | }, function(xr) { |
207 | var x = xr.responseXML; | 206 | var x = xr.responseXML; |
208 | var xp = x.evaluate( | 207 | var xp = x.evaluate( |
209 | '/rsp/photosets/photoset', x, null, | 208 | '/rsp/photosets/photoset', x, null, |
210 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 209 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
211 | _this.importXPR(xp); | 210 | _this.importXPR(xp); |
212 | }, function(x,s,c,m) { | 211 | }, function(x,s,c,m) { |
213 | _this.fireflix.flickr_failure(x,s,c,m); | 212 | _this.fireflix.flickr_failure(x,s,c,m); |
214 | } | 213 | } |
215 | ); | 214 | ); |
216 | }, | 215 | }, |
217 | on_select: function() { | 216 | on_select: function() { |
218 | if(this.selection.count==1) { | 217 | if(this.selection.count==1) { |
219 | this.fireflix.cmd_set_props.setAttribute('disabled','false'); | 218 | this.fireflix.cmd_set_props.setAttribute('disabled','false'); |
220 | var s = this.sets[this.selection.currentIndex]; | 219 | var s = this.sets[this.selection.currentIndex]; |
221 | this.fireflix.photoset.load_photos(s.id); | 220 | this.fireflix.photoset.load_photos(s.id); |
222 | }else{ | 221 | }else{ |
223 | this.fireflix.cmd_set_props.setAttribute('disabled','true'); | 222 | this.fireflix.cmd_set_props.setAttribute('disabled','true'); |
224 | } | 223 | } |
225 | } | 224 | } |
226 | }, | 225 | }, |
227 | 226 | ||
228 | refresh_user_tags: function() { | 227 | refresh_user_tags: function() { |
229 | var lb = document.getElementById('tagslist'); | 228 | var lb = document.getElementById('tagslist'); |
230 | var _this = this; | 229 | var _this = this; |
231 | this.flickr.api_call( | 230 | this.flickr.api_call( |
232 | { | 231 | { |
@@ -255,128 +254,129 @@ var fireflix = { | |||
255 | getSupportedFlavours: function() { | 254 | getSupportedFlavours: function() { |
256 | var rv = new FlavourSet(); | 255 | var rv = new FlavourSet(); |
257 | rv.appendFlavour('application/x-moz-file','nsIFile'); | 256 | rv.appendFlavour('application/x-moz-file','nsIFile'); |
258 | rv.appendFlavour('application/x-moz-url'); | 257 | rv.appendFlavour('application/x-moz-url'); |
259 | rv.appendFlavour('text/uri-list'); | 258 | rv.appendFlavour('text/uri-list'); |
260 | rv.appendFlavour('text/unicode'); | 259 | rv.appendFlavour('text/unicode'); |
261 | return rv; | 260 | return rv; |
262 | }, | 261 | }, |
263 | canHandleMultipleItems: true, | 262 | canHandleMultipleItems: true, |
264 | onDragOver: function(ev,fl,sess) { | 263 | onDragOver: function(ev,fl,sess) { |
265 | return true; | 264 | return true; |
266 | }, | 265 | }, |
267 | onDrop: function(ev,dd,s) { | 266 | onDrop: function(ev,dd,s) { |
268 | var ldf = null; | 267 | var ldf = null; |
269 | for(var i in dd.dataList) { | 268 | for(var i in dd.dataList) { |
270 | var di = dd.dataList[i]; | 269 | var di = dd.dataList[i]; |
271 | var dif = di.first; | 270 | var dif = di.first; |
272 | if( | 271 | if( |
273 | ldf==null | 272 | ldf==null |
274 | || ldf.flavour.contentType!=dif.flavour.contentType | 273 | || ldf.flavour.contentType!=dif.flavour.contentType |
275 | || ldf.contentLength!=dif.contentLength | 274 | || ldf.contentLength!=dif.contentLength |
276 | || ldf.data!=dif.data ) | 275 | || ldf.data!=dif.data ) |
277 | this.drop_item(ev,di,s); | 276 | this.drop_item(ev,di,s); |
278 | ldf = dif; | 277 | ldf = dif; |
279 | } | 278 | } |
280 | }, | 279 | }, |
281 | drop_item: function(ev,di,s) { | 280 | drop_item: function(ev,di,s) { |
282 | var d = di.first; | 281 | var d = di.first; |
283 | switch(d.flavour.contentType) { | 282 | switch(d.flavour.contentType) { |
284 | case 'text/unicode': | 283 | case 'text/unicode': |
285 | this.drop_urilist(ev,d.data,s); | 284 | this.drop_urilist(ev,d.data,s); |
286 | break; | 285 | break; |
287 | case 'application/x-moz-file': | 286 | case 'application/x-moz-file': |
288 | this.fireflix.uploads.add(d.data.path); | 287 | this.fireflix.uploads.add(d.data.path); |
289 | document.getElementById('fireflix_tabs').selectedTab | 288 | document.getElementById('fireflix_tabs').selectedTab |
290 | = document.getElementById('tab_upload'); | 289 | = document.getElementById('tab_upload'); |
291 | break; | 290 | break; |
292 | case 'text/uri-list': | 291 | case 'text/uri-list': |
293 | // is it ascii or could it be utf8? | 292 | // is it ascii or could it be utf8? |
294 | this.drop_urilist(ev,splitascii(d.data),s); | 293 | this.drop_urilist(ev,splitascii(d.data),s); |
295 | break; | 294 | break; |
296 | default: alert(d.flavour.contentType+':'+d.data); break; | 295 | default: alert(d.flavour.contentType+':'+d.data); break; |
297 | }; | 296 | }; |
298 | }, | 297 | }, |
299 | drop_urilist: function(ev,ul,s) { | 298 | drop_urilist: function(ev,ul,s) { |
300 | // TODO: check for being a file? | 299 | // TODO: check for being a file? |
301 | var us = decodeURIComponent(ul).split(/[\r\n]/); | 300 | var us = decodeURIComponent(ul).split(/[\r\n]/); |
302 | for(var ui in us) | 301 | for(var ui in us) |
303 | if(/\S/.test(us[ui])) | 302 | if(/\S/.test(us[ui])) |
304 | this.fireflix.uploads.add(us[ui]); | 303 | this.fireflix.uploads.add(us[ui]); |
305 | document.getElementById('fireflix_tabs').selectedTab | 304 | document.getElementById('fireflix_tabs').selectedTab |
306 | = document.getElementById('tab_upload'); | 305 | = document.getElementById('tab_upload'); |
307 | } | 306 | } |
308 | }, | 307 | }, |
309 | 308 | ||
310 | uploads: { | 309 | uploads: { |
311 | fireflix: null, | 310 | fireflix: null, |
312 | init: function(f) { | 311 | init: function(f) { |
313 | this.fireflix=f; | 312 | this.fireflix=f; |
314 | pull_elements(this,document,[ | 313 | pull_elements(this,document,[ |
315 | 'upload_filename','upload_title','upload_file_preview', | 314 | 'upload_filename','upload_title','upload_file_preview', |
316 | 'upload_file_props','upload_progress','upload_tags', | 315 | 'upload_file_props','upload_progress','upload_tags', |
317 | 'cmd_uploads_upload' | 316 | 'cmd_uploads_upload' |
318 | ]); | 317 | ]); |
318 | document.getElementById('uploadlist').view = this; | ||
319 | }, | 319 | }, |
320 | files: new Array(), | 320 | files: new Array(), |
321 | rowCount: 0, | 321 | rowCount: 0, |
322 | getCellText: function(r,c) { | 322 | getCellText: function(r,c) { |
323 | var f = this.files[r]; | 323 | var f = this.files[r]; |
324 | if(c.id=='up_file') return f.file; | 324 | if(c.id=='up_file') return f.file; |
325 | if(c.id=='up_title') return f.title; | 325 | if(c.id=='up_title') return f.title; |
326 | if(c.id=='up_status') return f.state; | 326 | if(c.id=='up_status') return f.state; |
327 | return c.id; | 327 | return c.id; |
328 | }, | 328 | }, |
329 | setTree: function(t) { this.tree = t }, | 329 | setTree: function(t) { this.tree = t }, |
330 | isContainer: function(r) { return false; }, | 330 | isContainer: function(r) { return false; }, |
331 | isSeparator: function(r) { return false; }, | 331 | isSeparator: function(r) { return false; }, |
332 | isSorted: function(r) { return false; }, | 332 | isSorted: function(r) { return false; }, |
333 | getLevel: function(r) { return 0; }, | 333 | getLevel: function(r) { return 0; }, |
334 | getImageSrc: function(r,c) { return null }, | 334 | getImageSrc: function(r,c) { return null }, |
335 | getRowProperties: function(r,p) { | 335 | getRowProperties: function(r,p) { |
336 | try { | 336 | try { |
337 | if(!Components) return; | 337 | if(!Components) return; |
338 | }catch(e) { return } | 338 | }catch(e) { return } |
339 | var f = this.files[r]; | 339 | var f = this.files[r]; |
340 | var as = Components.classes['@mozilla.org/atom-service;1']. | 340 | var as = Components.classes['@mozilla.org/atom-service;1']. |
341 | getService(Components.interfaces.nsIAtomService); | 341 | getService(Components.interfaces.nsIAtomService); |
342 | p.AppendElement(as.getAtom(f.state)); | 342 | p.AppendElement(as.getAtom(f.state)); |
343 | }, | 343 | }, |
344 | getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, | 344 | getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, |
345 | getColumnProperties: function(c,p) { }, | 345 | getColumnProperties: function(c,p) { }, |
346 | cycleHeader: function(cid,e) { }, | 346 | cycleHeader: function(cid,e) { }, |
347 | getParentIndex: function(r) { return -1; }, | 347 | getParentIndex: function(r) { return -1; }, |
348 | drop: function(r,o) { }, | 348 | drop: function(r,o) { }, |
349 | canDropBeforeAfter: function(r,b) { return false }, | 349 | canDropBeforeAfter: function(r,b) { return false }, |
350 | 350 | ||
351 | add: function(f) { | 351 | add: function(f) { |
352 | if(f.indexOf('file:/')==0) { | 352 | if(f.indexOf('file:/')==0) { |
353 | f = f.substr(5); | 353 | f = f.substr(5); |
354 | while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) | 354 | while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) |
355 | f = f.substr(1); | 355 | f = f.substr(1); |
356 | } | 356 | } |
357 | } | 357 | } |
358 | var t = f; | 358 | var t = f; |
359 | var ls = t.lastIndexOf('/'); | 359 | var ls = t.lastIndexOf('/'); |
360 | if(ls>0) t = t.substr(ls+1); | 360 | if(ls>0) t = t.substr(ls+1); |
361 | ls = t.lastIndexOf('\\'); | 361 | ls = t.lastIndexOf('\\'); |
362 | if(ls>0) t = t.substr(ls+1); | 362 | if(ls>0) t = t.substr(ls+1); |
363 | var ld = t.lastIndexOf('.'); | 363 | var ld = t.lastIndexOf('.'); |
364 | if(ld>0) t = t.substr(0,ld); | 364 | if(ld>0) t = t.substr(0,ld); |
365 | this.files.push( { | 365 | this.files.push( { |
366 | file: f, | 366 | file: f, |
367 | title: t, | 367 | title: t, |
368 | tags: '', | 368 | tags: '', |
369 | state: 'pending' | 369 | state: 'pending' |
370 | } ); | 370 | } ); |
371 | this.rowCount = this.files.length; | 371 | this.rowCount = this.files.length; |
372 | this.tree.rowCountChanged(this.rowCount-1,1); | 372 | this.tree.rowCountChanged(this.rowCount-1,1); |
373 | }, | 373 | }, |
374 | 374 | ||
375 | upload_worker: function() { | 375 | upload_worker: function() { |
376 | for(var f in this.files) { | 376 | for(var f in this.files) { |
377 | if(this.files[f].state=='pending') { | 377 | if(this.files[f].state=='pending') { |
378 | var ff = this.files[f]; | 378 | var ff = this.files[f]; |
379 | dump('upload '+ff.file+'\n'); | 379 | dump('upload '+ff.file+'\n'); |
380 | this.on_file_upload(ff); | 380 | this.on_file_upload(ff); |
381 | ff.state='uploading'; | 381 | ff.state='uploading'; |
382 | this.tree.invalidate(); | 382 | this.tree.invalidate(); |