author | Michael Krelin <hacker@klever.net> | 2006-09-28 19:40:39 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2006-09-28 19:40:39 (UTC) |
commit | 438c60c606a15792893c38415d0f405ae21e433d (patch) (side-by-side diff) | |
tree | d8a56268d5ebedf8669587af7469fedbe1527154 | |
parent | b62171950ffbbdae7826b1b8cdd4cfd0bde8cc93 (diff) | |
download | fireflix-438c60c606a15792893c38415d0f405ae21e433d.zip fireflix-438c60c606a15792893c38415d0f405ae21e433d.tar.gz fireflix-438c60c606a15792893c38415d0f405ae21e433d.tar.bz2 |
Better tracking of auth state, added possibility to sign off and reauth
git-svn-id: http://svn.klever.net/kin/fireflix/trunk@164 fe716a7a-6dde-0310-88d9-d003556173a8
-rw-r--r-- | content/fireflix-panel.xul | 33 | ||||
-rw-r--r-- | content/fireflix.js | 52 | ||||
-rw-r--r-- | locale/en-US/fireflix.dtd | 10 |
3 files changed, 67 insertions, 28 deletions
diff --git a/content/fireflix-panel.xul b/content/fireflix-panel.xul index 75d6c2d..70a58fe 100644 --- a/content/fireflix-panel.xul +++ b/content/fireflix-panel.xul @@ -1,252 +1,271 @@ <?xml version="1.0"?> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> <?xml-stylesheet href="fireflix.css" type="text/css"?> <!DOCTYPE page SYSTEM "chrome://fireflix/locale/fireflix.dtd"> <page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" id="fireflixwindow" title="Fireflix" onload="fireflix.init()" orient="vertical" ondragover="nsDragAndDrop.dragOver(event,fireflix.uploadObserver)" ondragdrop="nsDragAndDrop.drop(event,fireflix.uploadObserver)" > <script src="chrome://global/content/nsDragAndDrop.js"/> <script src="chrome://global/content/nsTransferable.js"/> <script type="application/x-javascript" src="md5.js" /> <script type="application/x-javascript" src="flickr.js" /> <script type="application/x-javascript" src="fireflix.js" /> <stringbundleset> <stringbundle id="loc_strings" src="chrome://fireflix/locale/fireflix.properties" /> </stringbundleset> + <commandset> + <command id="cmd_auth_auth" label="&panel.auth.auth.label;" + oncommand="fireflix.on_cmd_auth()"/> + <command id="cmd_auth_done" label="&panel.auth.done.label;" + oncommand="fireflix.on_cmd_auth_done()" disabled="true"/> + <command id="cmd_auth_open_flickr" label="&panel.auth.flickr.label;" + oncommand="fireflix.openTab('htp://www.flickr.com/')" /> + <command id="cmd_auth_unauth" label="&panel.auth.unauth.label;" + oncommand="fireflix.on_cmd_auth_unauth()" /> + </commandset> + + <popupset> + <popup id="auth_menu"> + <menuitem command="cmd_auth_auth"/> + <menuitem command="cmd_auth_done" hidden="true" id="menu_auth_done"/> + <menuitem command="cmd_auth_unauth" /> + <menuseparator/> + <menuitem command="cmd_auth_open_flickr"/> + </popup> + </popupset> + <commandset id="cmdset_search"> <command id="cmd_search" label="&panel.search.cmd_search.label;" oncommand="fireflix.foundphotos.search_photos()"/> <command id="cmd_search_open" label="&panel.search.cmd_search_open.label;" oncommand="fireflix.foundphotos.on_cmd_open(event)" /> </commandset> <commandset id="cmdset_sets"> <command id="cmd_refresh_sets" label="&panel.sets.cmd_refresh_sets;" oncommand="fireflix.on_refresh_sets()" /> <command id="cmd_set_props" label="&panel.sets.cmd_properties;" oncommand="fireflix.on_set_props()" disabled="true" /> </commandset> <popupset> <popup id="sets_menu"> <menuitem command="cmd_set_props"/> <menuitem command="cmd_refresh_sets"/> <menuseparator/> <menu label="&panel.sets.generate_html;" id="sets_html_menu"/> </popup> </popupset> <commandset id="cmdset_uploads"> <command id="cmd_uploads_clear" label="&panel.uploads.clear.label;" oncommand="fireflix.uploads.on_clear()" /> <command id="cmd_uploads_upload" label="&panel.uploads.upload.label;" oncommand="fireflix.uploads.on_upload()" /> <command id="cmd_uploads_remove" label="&panel.uploads.remove.label;" oncommand="fireflix.uploads.on_remove()" /> <command id="cmd_uploads_add" label="&panel.uploads.add.label;" oncommand="fireflix.uploads.on_add()" /> </commandset> <popupset> <popup id="uploads_menu"> <menuitem command="cmd_uploads_add"/> <menuitem command="cmd_uploads_clear"/> <menuitem command="cmd_uploads_remove"/> <menuseparator/> <menuitem command="cmd_uploads_upload"/> <menuseparator/> <menu label="&panel.uploads.generate_html;" id="uploads_html_menu"/> </popup> </popupset> <vbox class="wholething" flex="1"> - <groupbox> + <groupbox context="auth_menu"> <caption label="&panel.auth_info;"/> <hbox> <label id="auth_info" value="&panel.no_auth_info;" flex="1" disabled="true"/> - <button id="b_auth" label="&panel.auth_button;" oncommand="fireflix.on_auth()"/> - <button id="b_auth_done" label="&panel.auth_complete_button;" hidden="true" - oncommand="fireflix.on_auth_done()"/> - <button label="&panel.flickr_button.label;" - tooltiptext="&panel.flickr_button.tip;" - oncommand="fireflix.openTab('http://www.flickr.com/')" /> + <button id="b_auth" command="cmd_auth_auth"/> + <button id="b_auth_done" command="cmd_auth_done" hidden="true"/> + <button command="cmd_auth_open_flickr" + tooltiptext="&panel.auth.flickr.tip;"/> </hbox> </groupbox> <tabbox flex="1" id="fireflix_tabs"> <tabs> <tab label="&panel.tabs.search;"/> <tab label="&panel.tabs.sets;"/> <tab label="&panel.tabs.tags;" hidden="true"/> <!-- TODO: --> <tab id="tab_upload" label="&panel.tabs.upload;"/> </tabs> <tabpanels flex="1"> <tabpanel id="tabpanel_search" flex="1"> <vbox flex="1"> <groupbox class="search_params" orient="vertical" onkeypress="if(event.keyCode==event.DOM_VK_RETURN) fireflix.foundphotos.search_photos()"> <hbox> <label control="search_for" value="&panel.search.search_for.label;" accesskey="s"/> <textbox id="search_for" flex="1"/> </hbox> <hbox> <checkbox id="search_tags" label="&panel.search.mode.tagsonly.label;" tooltiptext="&panel.search.mode.tagsonly.tip;" checked="false" accesskey="t" /> <checkbox id="search_mine" label="&panel.search.mode.mine.label;" checked="true" accesskey="m"/> <spacer flex="1"/> <button command="cmd_search"/> </hbox> </groupbox> <tree id="searchresults" rows="2" flex="1" onselect="fireflix.foundphotos.on_select()" ondblclick="fireflix.foundphotos.on_cmd_open(event)" onkeypress="if(event.keyCode==event.DOM_VK_RETURN) fireflix.foundphotos.on_cmd_open(event)"> <treecols> <treecol id="sr_title" label="&panel.search.col.title.label;" flex="2" crop="end" align="start" /> </treecols> <treechildren/> </tree> <groupbox id="searchresult_props" orient="horizontal" hidden="true"> <vbox width="100" pack="center"> <hbox pack="center"> <image id="search_photo"/> </hbox> </vbox> <vbox flex="1"> <label id="searchresult_title"/> <textbox flex="1" multiline="true" class="plain" readonly="true" id="searchresult_description"/> <hbox pack="end"> <button command="cmd_search_open"/> </hbox> </vbox> </groupbox> </vbox> </tabpanel> <tabpanel id="tabpanel_sets" flex="1" onkeypress="if(event.keyCode==event.DOM_VK_RETURN) document.getElementById('setphotos').focus()"> <vbox flex="1"> <tree id="setslist" rows="2" onselect="fireflix.photosets.on_select()" flex="1" context="sets_menu" > <treecols> <treecol id="sl_name" label="&panel.sets.name.label;" flex="4" crop="end" align="start" tooltiptext="&panel.sets.name.tip;"/> <splitter class="tree-splitter" /> <treecol id="sl_photos" label="&panel.sets.photos.label;" flex="1" align="end" tooltiptext="&panel.sets.photos.tip;" /> </treecols> <treechildren/> </tree> <hbox> <button command="cmd_refresh_sets" /> <button command="cmd_set_props" /> </hbox> <tree id="setphotos" rows="2" onselect="fireflix.photoset.on_select()" flex="1"> <treecols> <treecol id="sp_title" label="&panel.setphotos.title.label;" flex="1" crop="end" align="start" tooltiptext="&panel.setphotos.title.tip;" /> <splitter class="tree-splitter" /> <treecol id="sp_taken" label="&panel.setphotos.taken.label;" crop="end" align="start" tooltiptext="&panel.setphotos.taken.tip;" hidden="true" /> <treecol id="sp_upload" label="&panel.setphotos.upload.label;" crop="end" align="start" tooltiptext="&panel.setphotos.upload.tip;" hidden="true" /> </treecols> <treechildren/> </tree> <groupbox id="set_photo_props" orient="horizontal"> <vbox width="100" pack="center"> <hbox pack="center"> <image id="set_photo" hidden="true"/> </hbox> </vbox> <spacer flex="1"/> </groupbox> </vbox> </tabpanel> <tabpanel id="tabpanel_tags"> <listbox id="tagslist" rows="8" flex="1"> <listhead> <listheader label="&panel.tagslist.tag.label;"/> </listhead> <listcols> <listcol flex="1"/> </listcols> </listbox> </tabpanel> <tabpanel id="tabpanel_upload"> <vbox flex="1"> <tree id="uploadlist" rows="2" flex="1" onselect="fireflix.uploads.selectionChanged()" context="uploads_menu"> <treecols> <treecol id="up_file" label="&panel.uploadlist.file.label;" flex="4" crop="start" align="start"/> <splitter class="tree-splitter" /> <treecol id="up_title" label="&panel.uploadlist.title.label;" flex="5" crop="end" align="start" /> <splitter class="tree-splitter" /> <treecol id="up_status" label="&panel.uploadlist.status.label;" flex="1" crop="end" align="start" /> </treecols> <treechildren/> </tree> <progressmeter id="upload_progress" mode="undetermined" hidden="true" /> <groupbox id="upload_file_props" orient="horizontal" hidden="true"> <image id="upload_file_preview" width="100" height="100" /> <grid flex="1"> <columns> <column/> <column flex="1"/> </columns> <rows> <row> <label control="upload_filename" value="&panel.upload_props.filename.label;" /> <textbox id="upload_filename" oninput="fireflix.uploads.propsToSel('filename')"/> </row> <row> <label control="upload_title" value="&panel.upload_props.title.label;" /> <textbox id="upload_title" oninput="fireflix.uploads.propsToSel('title')"/> </row> <row> <label control="uplod_tags" value="&panel.upload_props.tags.label;" /> <textbox id="upload_tags" oninput="fireflix.uploads.propsToSel('tags')"/> </row> <!-- TODO: description, public, friend, family --> </rows> </grid> </groupbox> <hbox> <button command="cmd_uploads_add" /> <spacer flex="1"/> <button command="cmd_uploads_remove" /> <spacer flex="1"/> <button command="cmd_uploads_clear" /> </hbox> <hbox pack="center"> <button command="cmd_uploads_upload" flex="1"/> </hbox> </vbox> </tabpanel> </tabpanels> </tabbox> </vbox> </page> diff --git a/content/fireflix.js b/content/fireflix.js index 9518480..82c7b0c 100644 --- a/content/fireflix.js +++ b/content/fireflix.js @@ -1,878 +1,896 @@ function splitascii(s) { var rv=''; for(var i=0;i<s.length;++i) { var w = s.charCodeAt(i); rv += String.fromCharCode( w&0xff, (w>>8)&0xff ); } return rv; } var fireflix = { flickr: new Flickr(), init: function() { + this.cmd_auth_auth = document.getElementById('cmd_auth_auth'); + this.cmd_auth_done = document.getElementById('cmd_auth_done'); + this.cmd_auth_unauth = document.getElementById('cmd_auth_unauth'); + this.menu_auth_done = document.getElementById('menu_auth_done'); + this.b_auth = document.getElementById('b_auth'); + this.b_auth_done = document.getElementById('b_auth_done'); + this.auth_info = document.getElementById('auth_info'); this.loc_strings = document.getElementById('loc_strings'); this.build_menus(); this.cmd_set_props = document.getElementById('cmd_set_props'); this.foundphotos.init(this); this.photosets.init(this); this.photoset.init(this); this.uploads.init(this); this.uploadObserver.init(this); this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3'; this.flickr.api_shs = '9c33c9e2f0f0cfd5'; this.flickr.prefs_root = 'net.klever.kin.fireflix'; this.flickr.load_token(); document.getElementById('setslist').view = this.photosets; document.getElementById('setphotos').view = this.photoset; document.getElementById('uploadlist').view = this.uploads; - this.flickr.no_auth_info_label = document.getElementById('auth_info').value; + this.no_auth_info_label = this.auth_info.value; + this.set_auth_state(this.flickr.token,false); if(this.flickr.token) { this.refresh_stuff(); - document.getElementById('auth_info').value = - this.flickr.user.fullname+' ['+this.flickr.user.username+']'; - document.getElementById('auth_info').disabled = false; - document.getElementById('b_auth').hidden = true; } }, - on_auth: function() { + set_auth_state: function(au,inp) { /* authorized, in progress */ + this.cmd_auth_unauth.disabled = !au; + this.b_auth.hidden = au || inp; + this.b_auth_done.hidden = !inp; + this.menu_auth_done.hidden = !inp; + this.cmd_auth_done.setAttribute('disabled',!inp); + this.auth_info.disabled = !au; + if(au) { + this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */ + }else{ + this.auth_info.value = this.no_auth_info_label; + } + }, + on_cmd_auth: function() { var _this = this; this.flickr.authorize_0( function() { - document.getElementById('b_auth').hidden = true; - document.getElementById('b_auth_done').hidden = false; + _this.set_auth_state(_this.flickr.token,true); }, function(x,s,c,m) { _this.flickr_failure(x,s,c,m); } ); }, - on_auth_done: function() { - document.getElementById('b_auth_done').hidden = true; + on_cmd_auth_done: function() { + this.set_auth_state(this.flickr.token,false); var _this = this; this.flickr.authorize_1( function() { _this.flickr.save_token(); _this.refresh_stuff(); - document.getElementById('auth_info').value = + _this.set_auth_state(_this.flickr.token,false); + _this.auth_info.value = _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; - document.getElementById('auth_info').disabled = false; }, function(x,s,c,m) { - document.getElementById('b_auth').hidden = false; + _this.set_auth_state(_this.flickr.token,false); /* XXX: no reset token? */ _this.flickr_failure(x,s,c,m); } ); }, + on_cmd_auth_unauth: function() { + this.flickr.reset_token(); + this.set_auth_state(false,false); + }, refresh_sets: function() { this.photosets.refresh_sets(); }, refresh_stuff: function() { this.refresh_sets(); this.refresh_user_tags(); }, /* photoset treeview */ photoset: { photos: new Array(), fireflix: null, init: function(f) { this.fireflix = f; }, rowCount: 0, getCellText: function(r,c) { var p = this.photos[r]; if(c.id=='sp_title') return p.title; if(c.id=='sp_taken') return p.datetaken; if(c.id=='sp_upload') return p.dateupload; /* TODO: unixtime conversion */ return c.id; }, setTree: function(t) { this.tree = t }, isContainer: function(r) { return false; }, isSeparator: function(r) { return false; }, isSorted: function(r) { return false; }, getLevel: function(r) { return 0; }, getImageSrc: function(r,c) { return null }, getRowProperties: function(r,p) {}, getCellProperties: function(cid,cel,p) {}, getColumnProperties: function(cid,cel,p) { }, cycleHeader: function(cid,e) { }, getParentIndex: function(r) { return -1; }, drop: function(r,o) { }, canDropBeforeAfter: function(r,b) { return false }, importXPR: function(xp) { this.tree.beginUpdateBatch(); this.photos = new Array(); var n; while(n=xp.iterateNext()) { this.photos.push(new Photo(n)); } this.rowCount = this.photos.length; this.tree.endUpdateBatch(); }, load_photos: function(psid) { var _this = this; this.fireflix.flickr.api_call( { method: 'flickr.photosets.getPhotos', auth_token: 'default', photoset_id: psid, extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' }, function(xr) { var x = xr.responseXML; var xp = x.evaluate( '/rsp/photoset/photo', x, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); _this.importXPR(xp); }, function(x,s,c,m) { _this.fireflix.flickr_failure(x,s,c,m); } ); }, on_select: function() { if(this.selection.count==1) { var p = this.photos[this.selection.currentIndex]; document.getElementById('set_photo').src = this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t'); document.getElementById('set_photo').hidden = false; }else{ document.getElementById('set_photo').hidden = true; } } }, /* photosets treeview */ photosets: { sets: new Array(), fireflix: null, init: function(f) { this.fireflix = f; }, rowCount: 0, getCellText: function(r,c) { var s = this.sets[r]; if(c.id=='sl_name') return s.title; if(c.id=='sl_photos') return s.photos; return c.id; }, setTree: function(t) { this.tree = t }, isContainer: function(r) { return false; }, isSeparator: function(r) { return false; }, isSorted: function() { return false; }, getLevel: function(r) { return 0; }, getImageSrc: function(r,c) { return null }, getRowProperties: function(r,p) {}, getCellProperties: function(cid,cel,p) { }, getColumnProperties: function(cid,cel,p) { }, cycleHeader: function(cid,e) { }, getParentIndex: function(r) { return -1; }, drop: function(r,o) { }, canDropBeforeAfter: function(r,b) { return false }, importXPR: function(xp) { this.tree.beginUpdateBatch(); this.sets = new Array(); var n; while(n=xp.iterateNext()) { this.sets.push(new Photoset(n)); } this.rowCount = this.sets.length; this.tree.endUpdateBatch(); }, refresh_sets: function() { var _this = this; this.fireflix.flickr.api_call( { method: 'flickr.photosets.getList', auth_token: 'default' }, function(xr) { var x = xr.responseXML; var xp = x.evaluate( '/rsp/photosets/photoset', x, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); _this.importXPR(xp); }, function(x,s,c,m) { _this.fireflix.flickr_failure(x,s,c,m); } ); }, on_select: function() { if(this.selection.count==1) { this.fireflix.cmd_set_props.setAttribute('disabled','false'); var s = this.sets[this.selection.currentIndex]; this.fireflix.photoset.load_photos(s.id); }else{ this.fireflix.cmd_set_props.setAttribute('disabled','true'); } } }, refresh_user_tags: function() { var lb = document.getElementById('tagslist'); var _this = this; this.flickr.api_call( { method: 'flickr.tags.getListUser', auth_token: 'default', }, function(xr) { var x = xr.responseXML; var xp = x.evaluate( '/rsp/who/tags/tag', x, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); // TODO: clear list var n; while(n=xp.iterateNext()) { lb.appendItem(n.firstChild.nodeValue); } }, function(x,s,c,m) { _this.flickr_failure(x,s,c,m); } ); }, uploadObserver: { fireflix: null, init: function(f) { this.fireflix = f; }, getSupportedFlavours: function() { var rv = new FlavourSet(); rv.appendFlavour('application/x-moz-file','nsIFile'); rv.appendFlavour('application/x-moz-url'); rv.appendFlavour('text/uri-list'); rv.appendFlavour('text/unicode'); return rv; }, canHandleMultipleItems: true, onDragOver: function(ev,fl,sess) { return true; }, onDrop: function(ev,dd,s) { var ldf = null; for(var i in dd.dataList) { var di = dd.dataList[i]; var dif = di.first; if( ldf==null || ldf.flavour.contentType!=dif.flavour.contentType || ldf.contentLength!=dif.contentLength || ldf.data!=dif.data ) this.drop_item(ev,di,s); ldf = dif; } }, drop_item: function(ev,di,s) { var d = di.first; switch(d.flavour.contentType) { case 'text/unicode': this.drop_urilist(ev,d.data,s); break; case 'application/x-moz-file': this.fireflix.uploads.add(d.data.path); document.getElementById('fireflix_tabs').selectedTab = document.getElementById('tab_upload'); break; case 'text/uri-list': // is it ascii or could it be utf8? this.drop_urilist(ev,splitascii(d.data),s); break; default: alert(d.flavour.contentType+':'+d.data); break; }; }, drop_urilist: function(ev,ul,s) { // TODO: check for being a file? var us = decodeURIComponent(ul).split(/[\r\n]/); for(var ui in us) if(/\S/.test(us[ui])) this.fireflix.uploads.add(us[ui]); document.getElementById('fireflix_tabs').selectedTab = document.getElementById('tab_upload'); } }, uploads: { fireflix: null, init: function(f) { this.fireflix=f; this.upload_filename = document.getElementById('upload_filename'); this.upload_title = document.getElementById('upload_title'); this.upload_file_preview = document.getElementById('upload_file_preview'); this.upload_file_props = document.getElementById('upload_file_props'); this.upload_progress = document.getElementById('upload_progress'); this.upload_tags = document.getElementById('upload_tags'); }, files: new Array(), rowCount: 0, getCellText: function(r,c) { var f = this.files[r]; if(c.id=='up_file') return f.file; if(c.id=='up_title') return f.title; if(c.id=='up_status') return f.state; return c.id; }, setTree: function(t) { this.tree = t }, isContainer: function(r) { return false; }, isSeparator: function(r) { return false; }, isSorted: function(r) { return false; }, getLevel: function(r) { return 0; }, getImageSrc: function(r,c) { return null }, getRowProperties: function(r,p) { try { if(!Components) return; }catch(e) { return } var f = this.files[r]; var as = Components.classes['@mozilla.org/atom-service;1']. getService(Components.interfaces.nsIAtomService); p.AppendElement(as.getAtom(f.state)); }, getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, getColumnProperties: function(c,p) { }, cycleHeader: function(cid,e) { }, getParentIndex: function(r) { return -1; }, drop: function(r,o) { }, canDropBeforeAfter: function(r,b) { return false }, add: function(f) { if(f.indexOf('file:/')==0) { f = f.substr(5); while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) f = f.substr(1); } } var t = f; var ls = t.lastIndexOf('/'); if(ls>0) t = t.substr(ls+1); ls = t.lastIndexOf('\\'); if(ls>0) t = t.substr(ls+1); var ld = t.lastIndexOf('.'); if(ld>0) t = t.substr(0,ld); this.files.push( { file: f, title: t, tags: '', state: 'pending' } ); this.rowCount = this.files.length; this.tree.rowCountChanged(this.rowCount-1,1); }, upload_worker: function() { for(var f in this.files) { if(this.files[f].state=='pending') { var ff = this.files[f]; dump('upload '+ff.file+'\n'); this.on_file_upload(ff); ff.state='uploading'; this.tree.invalidate(); var _this = this; this.fireflix.flickr.upload_file( ff.file, { title: ff.title, tags: ff.tags }, function(x,p) { ff.photoid = p; _this.batch_ids.push(p); ff.state='completed'; _this.tree.invalidate(); window.setTimeout(_this.upload_to,0,_this); }, function(x,s,c,m) { ff.state='failed'; ff.flickr_errcode = c; ff.flickr_errmsg = m; _this.tree.invalidate(); window.setTimeout(_this.upload_to,0,_this); } ); return; } } dump('uploading done\n'); this.on_finish_upload(); }, upload_to: function(_this) { _this.upload_worker(); }, on_file_upload: function(f) { document.getElementById('cmd_uploads_upload').setAttribute('disabled','true'); for(var fi in this.files) { if(this.files[fi].file==f.file) { this.tree.ensureRowIsVisible(fi); this.selection.rangedSelect(fi,fi,false); this.selection.currentIndex = fi; this.selToProps(); break; } } }, on_finish_upload: function() { if(this.batch_ids.length) { var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); if(psn!=null) { var pids = this.batch_ids.join(','); var ppid = this.batch_ids[0]; var _this = this; this.fireflix.flickr.api_call( { method: 'flickr.photosets.create', auth_token: 'default', title: psn, primary_photo_id: ppid }, function(x) { var npid = x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id'); _this.fireflix.flickr.api_call( { method: 'flickr.photosets.editPhotos', auth_token: 'default', photoset_id: npid, primary_photo_id: ppid, photo_ids: pids }, function(x) { _this.fireflix.refresh_sets(); }, function(x,s,c,m) { _this.fireflix.flickr_failure(x,s,c,m); } ); }, function(x,s,c,m) { _this.fireflix.flickr_failure(x,s,c,m); } ); } } this.selection.clearSelection(); document.getElementById('cmd_uploads_upload').setAttribute('disabled','false'); this.upload_progress.setAttribute('hidden','true'); }, clear_list: function() { this.tree.beginUpdateBatch(); this.rowCount = 0; this.files = new Array(); this.tree.endUpdateBatch(); this.selToProps(); }, selectionChanged: function() { this.selToProps(); }, disableProps: function() { this.upload_filename.value=''; this.upload_filename.disabled = true; this.upload_title.value=''; this.upload_title.disabled = true; this.upload_file_preview.src = null; this.upload_file_props.hidden = true; this.upload_tags.value=''; this.upload_tags.disabled = true; }, selToProps: function() { if(!this.selection.count) { this.disableProps(); }else if(this.selection.count==1) { var f=this.files[this.selection.currentIndex]; if(f==null || f.state!='pending') { this.disableProps(); }else{ this.upload_filename.value = f.file; this.upload_filename.disabled = false; this.upload_title.value = f.title; this.upload_title.disabled = false; this.upload_file_preview.src = 'file:///'+f.file; this.upload_file_props.hidden = false; this.upload_tags.value = f.tags; this.upload_tags.disabled = false; } }else{ var ftitle = null; var onetitle = true; var ftags = null; var onetag = true; var fs = 0; for(var ff in this.files) { if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { ++fs; if(ftitle==null) { ftitle = this.files[ff].title; }else if(ftitle!=this.files[ff].title) { onetitle = false; } if(ftags==null) { ftags = this.files[ff].tags; }else if(ftags!=this.files[ff].tags) { onetag = false; } } } if(fs) { this.upload_filename.value=''; this.upload_filename.disabled = true; if(onetitle) this.upload_title.value = ftitle; this.upload_title.disabled = false; if(onetag) this.upload_tags.value = ftags; this.upload_tags.disabled = false; this.upload_file_preview.src = null; this.upload_file_props.hidden = false; }else this.disableProps(); } }, propsToSel: function(prop) { if(this.selection.count<=0) return; for(var ff in this.files) { if(this.selection.isSelected(ff) && this.files[ff].state=='pending') { if(prop=='filename') this.files[ff].file = this.upload_filename.value; if(prop=='title') this.files[ff].title = this.upload_title.value; if(prop=='tags') this.files[ff].tags = this.upload_tags.value; this.tree.invalidateRow(ff); } } }, on_upload: function() { this.selToProps(); this.batch_ids = new Array(); this.upload_progress.value=0; this.upload_progress.setAttribute('hidden','false'); this.upload_worker(); }, on_clear: function() { this.clear_list(); }, on_remove: function() { if(this.selection.count) { this.tree.beginUpdateBatch(); for(var i=this.files.length-1;i>=0;--i) { if(this.selection.isSelected(i)) { this.files.splice(i,1); this.rowCount--; } } this.tree.endUpdateBatch(); this.selection.clearSelection(); } }, on_add: function() { var ifp = Components.interfaces.nsIFilePicker; var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp); fp.init(window, "Select a File", ifp.modeOpenMultiple); fp.appendFilters(ifp.filterImages); var rv = fp.show(); if(rv==ifp.returnOK) { var ff = fp.files; while(ff.hasMoreElements()) { var f = ff.getNext(); f.QueryInterface(Components.interfaces.nsIFile); this.add(f.path); } } } }, on_set_props: function() { var pset = this.photosets.sets[this.photosets.selection.currentIndex]; window.openDialog( "chrome://fireflix/content/photoset-props.xul", null, "dependent,modal,dialog,chrome", this, pset ); if(pset.dirty) { var _this = this; this.flickr.api_call( { method: 'flickr.photosets.editMeta', auth_token: 'default', photoset_id: pset.id, title: pset.title, description: pset.description }, function(xr) { pset.dirty = false; _this.flickr.api_call( { method: 'flickr.photosets.getPhotos', auth_token: 'default', photoset_id: pset.id }, function(xr) { var x = xr.responseXML; var xp = x.evaluate( '/rsp/photoset/photo', x, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); var phids = new Array(); var priph = null; var n; while(n=xp.iterateNext()) { var pid = n.getAttribute('id'); phids.push( pid ); if(pid==pset.primary && n.getAttribute('isprimary')!='1') priph = pid; } if(priph) { _this.flickr.api_call( { method: 'flickr.photosets.editPhotos', auth_token: 'default', photoset_id: pset.id, primary_photo_id: priph, photo_ids: phids.join(',') }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ _this.flickr_failure(x,s,c,m); } ); } }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ _this.flickr_failure(x,s,c,m); } ); }, function(x,s,c,m) { /* flickr.photosets.editMeta */ _this.flickr_failure(x,s,c,m); } ); } }, on_refresh_sets: function() { this.refresh_sets(); }, on_cmd_sets_html: function(csfx,ev) { var uti = csfx.charAt(0); var utl = csfx.charAt(1); var rv = this.build_html(this.photoset.photos,uti,utl); this.popup_content(rv); }, on_cmd_uploads_html: function(csfx,ev) { var uti = csfx.charAt(0); var utl = csfx.charAt(1); var pids = new Array(); for(var f in this.uploads.files) { if(this.uploads.selection.isSelected(f)) if(this.uploads.files[f].photoid) pids.push(this.uploads.files[f].photoid); } var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; var _this = this; this.flickr.api_call( { method: 'flickr.photos.search', auth_token: 'default', extras: 'original_format', user_id: 'me', per_page: pp }, function(xr) { var x = xr.responseXML; var rv = ''; for(var pn in pids) { var p = pids[pn]; var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); rv += _this.photo_html(pp,uti,utl)+'\n'; } _this.popup_content(rv); }, function(x,s,c,m) { _this.flickr_failure(x,s,c,m); } ); }, /* * */ foundphotos: { fireflix: null, init: function(f) { this.fireflix = f; this.search_for = document.getElementById('search_for'); this.search_tags= document.getElementById('search_tags'); this.search_mine = document.getElementById('search_mine'); document.getElementById('searchresults').view = this; this.searchresult_props = document.getElementById('searchresult_props'); this.search_photo = document.getElementById('search_photo'); this.searchresult_title = document.getElementById('searchresult_title'); this.searchresult_description = document.getElementById('searchresult_description'); }, photos: new Array(), rowCount: 0, getCellText: function(r,c) { var p = this.photos[r]; if(c.id=='sr_title') return p.title; return c.id; }, setTree: function(t) { this.tree = t }, isContainer: function(r) { return false }, isSeparator: function(r) { return false }, isSorted: function(r) { return false }, getLevel: function(r) { return 0 }, getImageSrc: function(r,c) { return null }, getRowProperties: function(r,p) { }, getCellProperties: function(cid,cel,p) { }, getColumnProperties: function(cid,cel,p) { }, cycleHeader: function(cid,e) { }, getParentIndex: function(r) { return -1 }, drop: function(r,o) { }, canDropBeforeAfter: function(r,b) { return false }, importXPR: function(xp) { this.selection.clearSelection(); this.selection.currentIndex = -1; this.searchresult_props.hidden = true; this.tree.beginUpdateBatch(); this.photos = new Array(); var n; while(n=xp.iterateNext()) { this.photos.push(new Photo(n)); } this.rowCount = this.photos.length; this.tree.endUpdateBatch(); }, search_photos: function() { var pars = { method: 'flickr.photos.search', auth_token: 'default', extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' }; if(this.search_mine.checked) pars.user_id='me'; if(this.search_tags.checked) { pars.tags=this.search_for.value.split(/ +/).join(','); }else{ pars.text=this.search_for.value; } var _this = this; this.fireflix.flickr.api_call( pars, function(xr) { var x = xr.responseXML; var xp = x.evaluate( '/rsp/photos/photo', x, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); _this.importXPR(xp); _this.on_select(); }, function(x,s,c,m) { _this.fireflix.flickr_failure(x,s,c,m); } ); }, on_select: function() { if(this.selection.currentIndex<0) { this.searchresult_props.hidden = true; }else{ var p = this.photos[this.selection.currentIndex]; if(!p) { this.searchresult_props.hidden = true; }else{ this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); this.searchresult_title.value = p.title; this.searchresult_description.value = null; if(p.description==null && p.description==undefined) { var pid = p.id; var ci = this.selection.currentIndex; var _this = this; this.fireflix.flickr.api_call( { method: 'flickr.photos.getInfo', auth_token: 'default', photo_id: p.id, secret: p.secret }, function(xr) { var pp = _this.photos[ci]; if(ci==_this.selection.currentIndex && pp.id==pid) { var n = xp_node('/rsp/photo',xr.responseXML); pp.fromNode_(n); _this.searchresult_description.value=pp.description?pp.description:null; } }, function(x,s,c,m) { _this.fireflix.flickr_failure(x,s,c,m); } ); this.searchresult_props.hidden = false; }else{ this.searchresult_description.value=p.description?p.description:null; } } } }, on_cmd_open: function(ev) { if(this.selection.currentIndex<0) return; var p = this.photos[this.selection.currentIndex]; if(!p.id) return; this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); } }, photo_html: function(p,i,l) { // TODO: add alt/title when possible var rv = '<a href="'+this.flickr.make_photo_url(p,l)+'">' + '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+ '</a>'; return rv; }, build_html: function(photos,uti,utl) { var rv = ''; for(var i in photos) { var p = photos[i]; rv += this.photo_html(p,utl,uti)+'\n'; } return rv; }, popup_content: function(s) { window.openDialog( "chrome://fireflix/content/generated-content.xul", null, "dialog,chrome", this, s ); }, copy_to_clipboard: function(s) { var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"] .getService(Components.interfaces.nsIClipboardHelper); ch.copyString(s); }, openTab: function(l) { var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService( Components.interfaces.nsIWindowMediator ); var bw = wm.getMostRecentWindow('navigator:browser'); var b = bw.getBrowser(); var t = b.addTab(l); b.selectedTab = t; }, build_menus: function() { this.append_html_menu( document.getElementById('sets_html_menu'), 'stm_','m_bop','cmdset_sets','cmd_sets_html' ); this.append_html_menu( document.getElementById('uploads_html_menu'), 'stm_','m_bop','cmdset_uploads','cmd_uploads_html' ); return; }, append_html_menu: function(m,imgt,lnkt,csid,cpfx) { var mp = m.appendChild(document.createElement('menupopup')); var t; t=mp.appendChild(document.createElement('menuitem')); t.setAttribute('label',this.loc_strings.getString('menutitle_Images')); t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); mp.appendChild(document.createElement('menuseparator')); var cs = document.getElementById(csid); for(var iti=0;iti<imgt.length;++iti) { t = mp.appendChild(document.createElement('menu')); t.setAttribute('label',this.loc_strings.getString('urltype_'+imgt.charAt(iti))); var smp = t.appendChild(document.createElement('menupopup')); t=smp.appendChild(document.createElement('menuitem')); t.setAttribute('label',this.loc_strings.getString('menutitle_Links')); t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); smp.appendChild(document.createElement('menuseparator')); for(var lti=0;lti<lnkt.length;++lti) { var csfx = imgt.charAt(iti)+lnkt.charAt(lti); t=smp.appendChild(document.createElement('menuitem')); t.setAttribute('label',this.loc_strings.getString('urltype_'+lnkt.charAt(lti))); t.setAttribute('command',cpfx+'_'+csfx); t=cs.appendChild(document.createElement('command')); t.setAttribute('id',cpfx+'_'+csfx); t.setAttribute('oncommand','fireflix.on_'+cpfx+"('"+csfx+"',event)"); } } return mp; }, flickr_failure: function(x,s,c,m) { if(c==98) { // Invalid auth token this.flickr.reset_token(); - document.getElementById('auth_info').value = this.no_auth_info_label; - document.getElementById('auth_info').disabled = true; - document.getElementById('b_auth').hidden = false; + this.set_auth_state(false,false); return; } - // TODO: is that beauty + // TODO: is that beauty? alert('flickr api call failed\n'+c+' '+m); } }; diff --git a/locale/en-US/fireflix.dtd b/locale/en-US/fireflix.dtd index 2b6e72a..f4ceb79 100644 --- a/locale/en-US/fireflix.dtd +++ b/locale/en-US/fireflix.dtd @@ -1,79 +1,81 @@ <!ENTITY % autoconf SYSTEM "chrome://fireflix/content/autoconf.dtd"> %autoconf; <!-- About Box --> <!ENTITY aboutFireflix "About Fireflix" > <!ENTITY about.ok.label "OK"> <!ENTITY about.license.label "License"> <!ENTITY about.license.tip "Show copying policy"> <!-- COPYING --> <!ENTITY copying.title "Filreflix: copying policy"> <!-- Sidebar --> <!ENTITY panel.auth_info "Authorization info"> <!ENTITY panel.no_auth_info "No auth info available"> -<!ENTITY panel.auth_button "Authorize"> -<!ENTITY panel.auth_complete_button "Authorization complete"> -<!ENTITY panel.flickr_button.label "Flickr"> -<!ENTITY panel.flickr_button.tip "Open Flickr in new tab"> + +<!ENTITY panel.auth.auth.label "Authorize"> +<!ENTITY panel.auth.done.label "Authorization complete"> +<!ENTITY panel.auth.flickr.label "Flickr"> +<!ENTITY panel.auth.flickr.tip "Open Flickr in new tab"> +<!ENTITY panel.auth.unauth.label "Sign off"> <!ENTITY panel.tabs.search "Search" > <!ENTITY panel.tabs.sets "Sets" > <!ENTITY panel.tabs.tags "Tags" > <!ENTITY panel.tabs.upload "Upload" > <!ENTITY panel.search.cmd_search.label "Search" > <!ENTITY panel.search.search_for.label "Search for:" > <!ENTITY panel.search.mode.tagsonly.label "tags"> <!ENTITY panel.search.mode.tagsonly.tip "Search tags only"> <!ENTITY panel.search.mode.mine.label "mine"> <!ENTITY panel.search.col.title.label "Title"> <!ENTITY panel.search.cmd_search_open.label "Open"> <!ENTITY panel.sets.name.label "Set"> <!ENTITY panel.sets.name.tip "Photoset name"> <!ENTITY panel.sets.photos.label "Photos"> <!ENTITY panel.sets.photos.tip "Number of photos in set"> <!ENTITY panel.sets.cmd_refresh_sets "Refresh"> <!ENTITY panel.sets.cmd_properties "Properties"> <!ENTITY panel.sets.generate_html "Generate HTML"> <!ENTITY panel.setphotos.title.label "Title"> <!ENTITY panel.setphotos.title.tip "Picture title"> <!ENTITY panel.setphotos.taken.label "Taken"> <!ENTITY panel.setphotos.taken.tip "When the picture was taken"> <!ENTITY panel.setphotos.upload.label "Uploaded"> <!ENTITY panel.setphotos.upload.tip "When the picure was uploaded"> <!ENTITY panel.tagslist.tag.label "Tag"> <!ENTITY panel.uploadlist.file.label "File name"> <!ENTITY panel.uploadlist.title.label "Title"> <!ENTITY panel.uploadlist.status.label "Status"> <!ENTITY panel.upload_props.filename.label "File:"> <!ENTITY panel.upload_props.title.label "Title:"> <!ENTITY panel.upload_props.tags.label "Tags:"> <!ENTITY panel.uploads.upload.label "Upload"> <!ENTITY panel.uploads.clear.label "Clear"> <!ENTITY panel.uploads.remove.label "Remove"> <!ENTITY panel.uploads.add.label "Add"> <!ENTITY panel.uploads.generate_html "Generate HTML"> <!ENTITY generated.title "Fireflix: Generated content"> <!ENTITY generated.copy "copy"> <!ENTITY browser.sidebar.label "Fireflix"> <!ENTITY browser.sidebar.title "Fireflix"> <!ENTITY photosetprops.title "Photoset properties"> <!ENTITY photosetprops.set_title.label "Photoset title:"> <!ENTITY photosetprops.set_desc.label "Photoset description:"> |