-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,105 +1,124 @@ <?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;" diff --git a/content/fireflix.js b/content/fireflix.js index 9518480..82c7b0c 100644 --- a/content/fireflix.js +++ b/content/fireflix.js @@ -1,89 +1,109 @@ 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; }, @@ -845,34 +865,32 @@ var fireflix = { 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,46 +1,48 @@ <!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"> |