summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--content/fireflix-panel.xul3
-rw-r--r--content/fireflix.js17
-rw-r--r--content/flickr.js5
3 files changed, 20 insertions, 5 deletions
diff --git a/content/fireflix-panel.xul b/content/fireflix-panel.xul
index 405804c..8aec0e4 100644
--- a/content/fireflix-panel.xul
+++ b/content/fireflix-panel.xul
@@ -199,97 +199,98 @@
<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)" context="setphotos_menu">
<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" hidden="true">
<vbox width="100" pack="center">
<hbox pack="center">
<image id="set_photo"
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">
+ context="uploads_menu" ondblclick="fireflix.uploads.on_cmd_open(event)"
+ onkeypress="if(event.keyCode==event.DOM_VK_RETURN) fireflix.uploads.on_cmd_open(event)" >
<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="vertical" hidden="true">
<hbox>
<image id="upload_file_preview" width="100" height="100" />
<vbox flex="1">
<grid>
<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="upload_tags" value="&panel.upload_props.tags.label;" />
<textbox id="upload_tags"
oninput="fireflix.uploads.propsToSel('tags')"/>
</row>
<!-- TODO: description, public, friend, family -->
</rows>
</grid>
<hbox>
<checkbox id="upload_is_public" label="&panel.upload_props.is_public;"/>
<checkbox id="upload_is_friends" label="&panel.upload_props.is_friend;"/>
<checkbox id="upload_is_family" label="&panel.upload_props.is_family;"/>
</hbox>
</vbox>
</hbox>
<description id="upload_failure" hidden="true"/>
</groupbox>
diff --git a/content/fireflix.js b/content/fireflix.js
index 78e56c2..225e21c 100644
--- a/content/fireflix.js
+++ b/content/fireflix.js
@@ -583,96 +583,107 @@ var fireflix = {
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;
if(prop=='is_public') this.files[ff].is_public = this.upload_is_public.checked;
if(prop=='is_friends') this.files[ff].is_friend = this.upload_is_friends.checked;
if(prop=='is_family') this.files[ff].is_family = this.upload_is_family.checked;
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_cmd_open: function(ev) {
+ if(this.selection.currentIndex<0) return;
+ var f = this.files[this.selection.currentIndex];
+ if(f.photoid) {
+ this.fireflix.openTab(
+ this.fireflix.flickr.make_uploader_edit_url(f.photoid)
+ );
+ }else{
+ this.fireflix.openTab( 'file://'+f.file);
+ }
}
},
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);
@@ -868,101 +879,99 @@ var fireflix = {
this.searchresult_description.appendChild(de);
/* of all linking elements flickr only allows a */
var as = this.searchresult_description.getElementsByTagName('a');
for(var a=0;a<as.length;++a)
as.item(a).setAttribute('target','_blank');
}
},
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_title.tooltipText = p.title;
this.render_description_frame(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.render_description_frame(pp.description);
}
}, function(x,s,c,m) {
_this.fireflix.flickr_failure(x,s,c,m);
}
);
this.searchresult_props.hidden = false;
}else{
this.render_description_frame(p.description);
}
}
}
},
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'));
}
},
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,uti,utl)+'\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('setphotos_html_menu'),
'stm_','m_bop','cmdset_setphotos','cmd_setphotos_html'
diff --git a/content/flickr.js b/content/flickr.js
index b8360c1..e09d5f0 100644
--- a/content/flickr.js
+++ b/content/flickr.js
@@ -52,96 +52,97 @@ Photo.prototype = {
this.id = n.getAttribute('id'); this.secret = n.getAttribute('secret');
this.server = n.getAttribute('server');
this.title = n.getAttribute('title');
this.isprimary = n.getAttribute('isprimary');
this.license = n.getAttribute('license');
this.dateupload = n.getAttribute('dateupload');
this.datetaken = n.getAttribute('datetaken'); this.datetakengranularity = n.getAttribute('datetakengranularity');
this.ownername = n.getAttribute('ownername');
this.iconserver = n.getAttribute('iconserver');
this.originalformat = n.getAttribute('originalformat');
this.lastupdate = n.getAttribute('lastupdate');
},
fromNode_: function(n) {
var t;
// TODO: @rotation @isfavorite
this.owner = {};
t = n.getElementsByTagName('owner').item(0);
if(t) {
this.owner.nsid=t.getAttribute('nsid');
this.owner.username=t.getAttribute('username');
this.owner.realname=t.getAttribute('realname');
this.owner.location=t.getAttribute.location;
}
t = n.getElementsByTagName('description').item(0);
if(t && t.firstChild) {
this.description = t.firstChild.nodeValue;
}
// TODO: visibility/@ispublic visibility/@isfriend visibility/@isfamily
// TODO: dates/@posted dates/@taken dates/@takengranularity dates/@lastupdate
// TODO: permissions/@permcomment permsiions/@permaddmeta
// 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/',
+ uploader_edit_url: 'http://www.flickr.com/tools/uploader_edit.gne',
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,
@@ -230,96 +231,100 @@ Flickr.prototype = {
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;
},
+ make_uploader_edit_url: function(pid) {
+ // TODO: handle arrays
+ return this.uploader_edit_url+'?ids='+pid;
+ },
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();