summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--NEWS1
-rw-r--r--NEWS.xml1
-rw-r--r--content/fireflix-panel.xul1
-rw-r--r--content/fireflix.js12
-rw-r--r--content/flickr.js4
5 files changed, 15 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index b44ece1..219a07f 100644
--- a/NEWS
+++ b/NEWS
@@ -1,20 +1,21 @@
0.0.5 ()
- Added toolbar button
- Enter or double click on photo in set now opens photo in flickr
+ - Double click on photoset opens photoset in flickr
0.0.4 (November 13th, 2006)
- Added button to remove linebreaks from generated HTML
- Added the word 'sidebar' to the extension name so that you don't have to look hard for it
- UI polishing, including making it more boring
- code cosmetics
0.0.3 (November 6th, 2006)
- Firefox 2.0 compatibility
0.0.2 (October 17th, 2006)
- Added brief help file
- Fixed HTML generation code
- Fixed a mistyped flickr url so that the 'Flickr' button works now
0.0.1 (October 3rd, 2006)
- Added ability to paginate through search results
- Fixed packaging bug that omitted packaging license dialog
- A lot of code cleanup and UI polishing
0.0 (September 26th, 2006)
- Initial release
diff --git a/NEWS.xml b/NEWS.xml
index 79ccf1a..b8f1cf4 100644
--- a/NEWS.xml
+++ b/NEWS.xml
@@ -1,29 +1,30 @@
<?xml version="1.0" encoding="us-ascii"?>
<news>
<version version="0.0.5">
<ni>Added toolbar button</ni>
<ni>Enter or double click on photo in set now opens photo in flickr</ni>
+ <ni>Double click on photoset opens photoset in flickr</ni>
</version>
<version version="0.0.4" date="November 13th, 2006">
<ni>Added button to remove linebreaks from generated HTML</ni>
<ni>Added the word 'sidebar' to the extension name so that you don't have to look hard for it</ni>
<ni>UI polishing, including making it more boring</ni>
<ni>code cosmetics</ni>
</version>
<version version="0.0.3" date="November 6th, 2006">
<ni>Firefox 2.0 compatibility</ni>
</version>
<version version="0.0.2" date="October 17th, 2006">
<ni>Added brief help file</ni>
<ni>Fixed HTML generation code</ni>
<ni>Fixed a mistyped flickr url so that the 'Flickr' button works now</ni>
</version>
<version version="0.0.1" date="October 3rd, 2006">
<ni>Added ability to paginate through search results</ni>
<ni>Fixed packaging bug that omitted packaging license dialog</ni>
<ni>A lot of code cleanup and UI polishing</ni>
</version>
<version version="0.0" date="September 26th, 2006">
<ni>Initial release</ni>
</version>
</news>
diff --git a/content/fireflix-panel.xul b/content/fireflix-panel.xul
index b2ca7dc..af92d22 100644
--- a/content/fireflix-panel.xul
+++ b/content/fireflix-panel.xul
@@ -1,295 +1,296 @@
<?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="util.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('http://www.flickr.com/')" />
<command id="cmd_auth_unauth" label="&panel.auth.unauth.label;"
oncommand="fireflix.on_cmd_auth_unauth()" />
<command id="cmd_help" label="?"
oncommand="fireflix.openTab('chrome://fireflix/content/help.xml')" />
</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)" />
<command id="cmd_search_prev_page"
label="&panel.search.cmd_search_prev_page.label;"
oncommand="fireflix.foundphotos.on_cmd_prev(event)" disabled="true"/>
<command id="cmd_search_next_page"
label="&panel.search.cmd_search_next_page.label;"
oncommand="fireflix.foundphotos.on_cmd_next(event)" disabled="true"/>
</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 context="auth_menu">
<caption label="&panel.auth_info;"/>
<hbox>
<vbox pack="center" flex="1">
<label id="auth_info" value="&panel.no_auth_info;" disabled="true" crop="end"/>
</vbox>
<button class="lean" id="b_auth" command="cmd_auth_auth"/>
<button class="lean" id="b_auth_done" command="cmd_auth_done" hidden="true"/>
<button class="lean" command="cmd_auth_open_flickr"
tooltiptext="&panel.auth.flickr.tip;"/>
<button class="lean" command="cmd_help"/>
</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>
<vbox pack="center">
<label control="search_for" value="&panel.search.search_for.label;" accesskey="s"/>
</vbox>
<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 class="lean" command="cmd_search"/>
</hbox>
</groupbox>
<hbox>
<button class="lean" command="cmd_search_prev_page"/>
<spacer flex="1"/>
<label id="search_page" hidden="true"/>
<spacer flex="1"/>
<button class="lean" command="cmd_search_next_page"/>
</hbox>
<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"
ondblclick="fireflix.foundphotos.on_cmd_open(event)"/>
</hbox>
</vbox>
<vbox flex="1">
<label id="searchresult_title" crop="end"/>
<hbox flex="1" pack="center">
<div flex="1" id="searchresult_description" xmlns="http://www.w3.org/1999/xhtml"/>
</hbox>
<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"
+ ondblclick="fireflix.photosets.on_cmd_open_in_flickr(event)"
>
<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" ondblclick="fireflix.photoset.on_cmd_open(event)"
onkeypress="if(event.keyCode==event.DOM_VK_RETURN) fireflix.photoset.on_cmd_open(event)">
<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"
ondblclick="fireflix.photoset.on_cmd_open(event)" />
</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 class="lean" command="cmd_uploads_add" />
<spacer flex="1"/>
<button class="lean" command="cmd_uploads_remove" />
<spacer flex="1"/>
<button class="lean" 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 24894df..48053c5 100644
--- a/content/fireflix.js
+++ b/content/fireflix.js
@@ -1,430 +1,434 @@
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() {
pull_elements(this,document,[
'cmd_auth_auth','cmd_auth_done','cmd_auth_unauth',
'menu_auth_done','b_auth','b_auth_done','auth_info',
'loc_strings','cmd_set_props'
]);
this.build_menus();
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();
this.no_auth_info_label = this.auth_info.value;
this.set_auth_state(this.flickr.token,false);
if(this.flickr.token) {
this.refresh_stuff();
}else{
this.on_cmd_auth();
}
},
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(
'delete',
function(x,f,u) {
_this.openTab(u);
_this.set_auth_state(_this.flickr.token,true);
}, function(x,s,c,m) {
_this.flickr_failure(x,s,c,m);
}
);
},
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();
_this.set_auth_state(_this.flickr.token,false);
_this.auth_info.value =
_this.flickr.user.fullname+' ['+_this.flickr.user.username+']';
}, function(x,s,c,m) {
_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;
pull_elements(this,document,[ 'set_photo' ]);
document.getElementById('setphotos').view = this;
},
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') {
var du = new Date(p.dateupload*1000);
var rv = du.getFullYear()+'-'+(du.getMonth()+1)+'-'+du.getDate()
+' '+
du.getHours()+':'+du.getMinutes()+':'+du.getSeconds();
return rv.replace(/(\D)(\d)(\D)/,'$10$2$3');
}
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();
this.selection.clearSelection();
},
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];
this.set_photo.src =
this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t');
this.set_photo.hidden = false;
}else{
this.set_photo.hidden = true;
}
},
on_cmd_open: function(ev) {
- if(this.selection.currentIndex<0)
- return;
+ if(this.selection.currentIndex<0) return;
var p = this.photos[this.selection.currentIndex];
- if(!p.id)
- return;
+ if(!p.id) return;
this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p'));
}
},
/* photosets treeview */
photosets: {
sets: new Array(),
fireflix: null,
init: function(f) {
this.fireflix = f;
document.getElementById('setslist').view = this;
},
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');
}
+ },
+ on_cmd_open_in_flickr: function(ev) {
+ if(this.selection.currentIndex<0) return;
+ var p = this.sets[this.selection.currentIndex];
+ if(!p.id) return;
+ this.fireflix.openTab(this.fireflix.flickr.make_photoset_url(p));
}
},
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;
pull_elements(this,document,[
'upload_filename','upload_title','upload_file_preview',
'upload_file_props','upload_progress','upload_tags',
'cmd_uploads_upload'
]);
document.getElementById('uploadlist').view = this;
},
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];
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;
}
}
this.on_finish_upload();
},
upload_to: function(_this) { _this.upload_worker(); },
on_file_upload: function(f) {
this.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;
}
}
diff --git a/content/flickr.js b/content/flickr.js
index 75d1a72..b8360c1 100644
--- a/content/flickr.js
+++ b/content/flickr.js
@@ -82,271 +82,275 @@ Photo.prototype = {
// TODO: editability/@canaddcomment editability/@canaddmeta
// TODO: comments
// TODO: notes/note/@id notes/note/@author notes/note/@authorname
// TODO: notes/note/@x notes/note/@y notes/note/@w notes/note/@h
// TODO: notes/note
// TODO: tags/tag/@id tags/tag/@author tags/tag/@raw tags/tag
// TODO: urls/url/@type urls/url
}
};
function Flickr() { }
Flickr.prototype = {
rest_url: 'http://www.flickr.com/services/rest/',
auth_url: 'http://flickr.com/services/auth/',
photo_url: 'http://static.flickr.com/',
photos_url: 'http://www.flickr.com/photos/',
upload_url: 'http://www.flickr.com/services/upload/',
api_sig: function(paramstr) {
return MD5(toutf8(this.api_shs+paramstr));
},
api_call_url: function(params,url) {
params.api_key = this.api_key;
var pp = new Array();
for(var p in params) {
pp.push(p);
}
var pstr = '';
var rv = (url?url:this.rest_url)+'?';
for(var p in pp.sort()) {
var pn = pp[p];
pstr += pn+params[pn];
rv += pn+'='+params[pn]+'&';
}
rv += 'api_sig='+this.api_sig(pstr);
return rv;
},
api_call: function(params, on_success, on_failure) {
if(params.auth_token == 'default')
params.auth_token = this.token;
var x = new XMLHttpRequest();
x.open("GET",this.api_call_url(params));
x.onreadystatechange=function() {
if(x.readyState!=4) return false;
if(x.status==200) {
var stat = x.responseXML.firstChild.getAttribute('stat');
if(stat=='ok') {
if(on_success) on_success(x);
}else{
var e = x.responseXML.getElementsByTagName('err').item(0);
var ecode = e.getAttribute('code');
var emsg = e.getAttribute('msg');
dump(params.method+' failed: '+ecode+' '+emsg+'\n');
if(on_failure) on_failure(x,stat,ecode,emsg);
}
}else{
if(on_failure) on_failure(x);
}
return true;
}
x.send(null);
return true;
},
frob: null,
authorize_0: function(perms, on_s, on_f) {
var _this = this;
this.api_call(
{ method: 'flickr.auth.getFrob' },
function(x) {
_this.frob = xp_str('/rsp/frob',x.responseXML);
var u = _this.api_call_url(
{ frob: _this.frob, perms: perms?perms:'delete' }, _this.auth_url );
if(on_s) on_s(x,_this.frob,u);
}, function(x,s,c,m) {
if(on_f) on_f(x,s,c,m);
}
);
},
token: null,
perms: null,
user: null,
authorize_1: function(on_s, on_f) {
var _this = this;
this.api_call(
{ method: 'flickr.auth.getToken', frob: this.frob },
function(x) {
_this.token = xp_str('/rsp/auth/token',x.responseXML);
_this.perms = xp_str('/rsp/auth/perms',x.responseXML);
var u = xp_node('/rsp/auth/user',x.responseXML);
_this.user = {
nsid: u.getAttribute('nsid'),
username: u.getAttribute('username'),
fullname: u.getAttribute('fullname')
};
if(on_s) on_s(x);
}, function(x,s,c,m) {
if(on_f) on_f(x,s,c,m);
}
);
},
prefs: Components.classes['@mozilla.org/preferences-service;1'].getService(
Components.interfaces.nsIPrefBranch
),
prefs_root: 'net.klever.kin.flickr',
save_token: function() {
// TODO: don't clear when there's nothing to clear or catch exceptions
if(this.token)
this.prefs.setCharPref(this.prefs_root+'.auth_token',this.token);
else
this.prefs.clearUserPref(this.prefs_root+'.auth_token');
if(this.perms)
this.prefs.setCharPref(this.prefs_root+'.auth_perms',this.perms);
else
this.prefs.clearUserPref(this.prefs_root+'.auth_perms');
if(this.user && this.user.nsid!=null && this.user.nsid!=undefined)
this.prefs.setCharPref(this.prefs_root+'.auth_user.nsid',this.user.nsid);
else
this.prefs.clearUserPref(this.prefs_root+'.auth_user.nsid');
if(this.user && this.user.username!=null && this.user.username!=undefined)
this.prefs.setCharPref(this.prefs_root+'.auth_user.username',this.user.username);
else
this.prefs.clearUserPref(this.prefs_root+'.auth_user.username');
if(this.user && this.user.fullname!=null && this.user.fullname!=undefined)
this.prefs.setCharPref(this.prefs_root+'.auth_user.fullname',this.user.fullname);
else
this.prefs.clearUserPref(this.prefs_root+'.auth_user.fullname');
},
_reset_token: function() {
this.token = null; this.perms = null; this.user = null;
return false;
},
load_token: function() {
try {
if(this.prefs.getPrefType(this.prefs_root+'.auth_token')!=this.prefs.PREF_STRING)
return this._reset_token();
this.token = this.prefs.getCharPref(this.prefs_root+'.auth_token');
if(this.prefs.getPrefType(this.prefs_root+'.auth_perms')!=this.prefs.PREF_STRING)
return this._reset_token();
this.perms = this.prefs.getCharPref(this.prefs_root+'.auth_perms');
if(this.prefs.getPrefType(this.prefs_root+'.auth_user.nsid')!=this.prefs.PREF_STRING)
return this._reset_token();
this.user = new Object();
this.user.nsid = this.prefs.getCharPref(this.prefs_root+'.auth_user.nsid');
if(this.prefs.getPrefType(this.prefs_root+'.auth_user.username')!=this.prefs.PREF_STRING)
return this._reset_token();
this.user.username = this.prefs.getCharPref(this.prefs_root+'.auth_user.username');
if(this.prefs.getPrefType(this.prefs_root+'.auth_user.fullname')!=this.prefs.PREF_STRING)
return this._reset_token();
this.user.fullname = this.prefs.getCharPref(this.prefs_root+'.auth_user.fullname');
}catch(e) { return this._reset_token(); }
return true;
},
reset_token: function() {
this._reset_token();
this.save_token();
},
get_photo_url: function(ser,id,sec,sfx,ext) {
var rv = this.photo_url + ser + '/' + id + '_' + sec;
if(sfx && sfx!='_') rv += '_'+sfx;
rv += ext?'.'+ext:'.jpg';
return rv;
},
get_image_url: function(o,sfx) {
return this.get_photo_url(
o.server,
(o instanceof Photoset)? o.primary : o.id,
o.secret,
sfx,
(sfx=='o')?o.originalformat:null
);
},
get_photo_page_url: function(p) {
if(p instanceof Photo) {
// TODO: track photoset and user owner id from there?
// The approach below is sheerly wrong.
var o = this.user.nsid;
if(p.owner && p.owner.nsid) o = p.owner.nsid;
var rv = this.photos_url + o +'/' + p.id;
return rv;
}else // TODO: take owner into account?
return this.photos_url + this.user.nsid + '/' + p;
},
make_photo_url: function(p,sfx) {
if(sfx=='p')
return this.get_photo_page_url(p);
else
return this.get_image_url(p,sfx);
},
+ make_photoset_url: function(ps) {
+ // TODO: allow for using someone else's photoset?
+ return this.photos_url+this.user.nsid+'/sets/'+ps.id;
+ },
upload_file: function(f,fa,on_success,on_failure) {
try {
var fi = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
fi.initWithPath( f );
var st = Components.classes["@mozilla.org/network/file-input-stream;1"]
.createInstance(Components.interfaces.nsIFileInputStream);
st.init(fi,0x01,00004,null);
var bis = Components.classes["@mozilla.org/binaryinputstream;1"]
.createInstance(Components.interfaces.nsIBinaryInputStream);
bis.setInputStream(st);
// allocate and initialize temp storage string
var pbs = Components.classes["@mozilla.org/storagestream;1"]
.createInstance(Components.interfaces.nsIStorageStream);
pbs.init(1024,10000000,null);
// create output stream
var pbos = pbs.getOutputStream(0);
// and a binaryoutputstream interface
var pbbos = Components.classes["@mozilla.org/binaryoutputstream;1"]
.createInstance(Components.interfaces.nsIBinaryOutputStream);
pbbos.setOutputStream(pbos);
/* create POST body */
var boundarytoken = 'kadaroloongazaduviaxamma';
var boundary = '--'+boundarytoken;
var b = '';
var parms = { api_key: this.api_key, auth_token: this.token };
for(var p in fa) parms[p] = fa[p];
var pns = new Array();
for(var p in parms) pns.push(p);
var pstr = '';
for(var p in pns.sort()) {
var pn = pns[p];
pstr += pn+parms[pn];
b += boundary+'\nContent-Disposition: form-data; name="'+pn+'"\n\n'+toutf8(parms[pn])+'\n';
}
b += boundary+'\nContent-Disposition: form-data; name="api_sig"\n\n'+this.api_sig(pstr)+'\n';
b += boundary+'\nContent-Disposition: form-data; name="photo"; filename="'+f+'"\nContent-Type: image/jpeg\nContent-Transfer-Encoding: binary\n\n';
pbbos.writeBytes(b,b.length);
var bisbytes = bis.available();
pbbos.writeBytes(bis.readBytes(bisbytes),bisbytes);
pbbos.writeBytes('\n'+boundary+'--',3+boundary.length); bis.close(); st.close();
pbbos.close(); pbos.close();
var x = new XMLHttpRequest();
x.open("POST",this.upload_url);
x.setRequestHeader('Content-Type', 'multipart/form-data; boundary="'+boundarytoken+'"');
x.setRequestHeader('Connection','close');
x.setRequestHeader('Content-Length',b.length);
x.onreadystatechange=function() {
if(x.readyState!=4) return false;
if(x.status==200) {
var stat = x.responseXML.firstChild.getAttribute('stat');
if(stat=='ok') {
var pid = xp_str('/rsp/photoid',x.responseXML);
if(on_success) on_success(x,pid);
}else{
var e = x.responseXML.getElementsByTagName('err').item(0);
var ecode = e.getAttribute('code');
var emsg = e.getAttribute('msg');
dump('upload failed: '+ecode+' '+emsg+'\n');
if(on_failure) on_failure(x,stat,ecode,emsg);
}
}else{
if(on_failure) on_failure(x);
}
return true;
};
x.send(pbs.newInputStream(0));
}catch(e) {
if(on_failure) on_failure(e,null,-1,e.message);
}
}
};