summaryrefslogtreecommitdiffabout
path: root/content
Side-by-side diff
Diffstat (limited to 'content') (more/less context) (show whitespace changes)
-rw-r--r--content/Makefile.am2
-rw-r--r--content/fireflix-panel.xul1
-rw-r--r--content/flickr.js50
-rw-r--r--content/util.js61
4 files changed, 63 insertions, 51 deletions
diff --git a/content/Makefile.am b/content/Makefile.am
index 8548400..d8607fb 100644
--- a/content/Makefile.am
+++ b/content/Makefile.am
@@ -1,22 +1,22 @@
xpichromecontent_DATA = \
autoconf.dtd \
browser.xul about.xul fireflix-panel.xul photoset-props.xul \
generated-content.xul \
- photoset-props.js fireflix.js flickr.js md5.js \
+ photoset-props.js fireflix.js flickr.js util.js md5.js \
generated-content.js \
fireflix.css \
background.jpeg
sized_icons = \
$(addsuffix .png, \
fireflix \
)
nobase_xpichromecontent_DATA = \
$(addprefix icons/, \
$(addprefix 16x16/,${sized_icons}) \
$(addprefix 32x32/,${sized_icons}) \
)
EXTRA_DIST = \
${xpichromecontent_DATA} ${nobase_xpichromecontent_DATA}
diff --git a/content/fireflix-panel.xul b/content/fireflix-panel.xul
index 569beb0..2a15a51 100644
--- a/content/fireflix-panel.xul
+++ b/content/fireflix-panel.xul
@@ -1,112 +1,113 @@
<?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('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 context="auth_menu">
<caption label="&panel.auth_info;"/>
<hbox>
<label id="auth_info" value="&panel.no_auth_info;" flex="1" disabled="true" crop="end"/>
<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>
diff --git a/content/flickr.js b/content/flickr.js
index 3554796..add628a 100644
--- a/content/flickr.js
+++ b/content/flickr.js
@@ -1,237 +1,187 @@
/*
* Photoset
*/
function Photoset(s) {
if(s instanceof Photoset) {
for(var p in s) this[p]=s[p];
}else
this.fromNode(s);
}
Photoset.prototype = {
id: null,
primary: null,
secret: null,
server: null,
photos: null,
title: null,
description: null,
fromNode: function(n) {
this.id = n.getAttribute('id');
this.primary = n.getAttribute('primary');
this.secret = n.getAttribute('secret');
this.server = n.getAttribute('server');
this.photos = n.getAttribute('photos');
this.title = n.getElementsByTagName('title').item(0).firstChild.nodeValue;
this.description = n.getElementsByTagName('description').item(0).firstChild;
if(this.description) this.description = this.description.nodeValue;
}
};
/*
* Photo
*/
function Photo(s) {
if(s instanceof Photo) {
for(var p in s) this[p]=s[p];
}else
this.fromNode(s);
}
Photo.prototype = {
id: null, secret: null,
server: null,
title: null,
isprimary: null,
license: null,
dateupload: null, datetaken: null, datetakengranularity: null,
ownername: null,
iconserver: null,
originalformat: null,
lastupdate: null,
fromNode: function(n) {
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 toutf8(ucode) {
- var rv = '';
- for(var i=0;i<ucode.length;++i) {
- var cc = ucode.charCodeAt(i);
- if(cc<=0x7F)
- rv += ucode.charAt(i);
- else if(cc<=0x7ff)
- rv += String.fromCharCode(
- 0xc0|((cc>> 6)&0x1f),
- 0x80|( cc &0x3f) );
- else if(cc<=0xffff)
- rv += String.fromCharCode(
- 0xe0|((cc>>12)&0x0f),
- 0x80|((cc>> 6)&0x3f),
- 0x80|( cc &0x3f) );
- else if(cc<=0x1fffff)
- rv += String.fromCharCode(
- 0xf0|((cc>>18)&0x07),
- 0x80|((cc>>12)&0x3f),
- 0x80|((cc>> 6)&0x3f),
- 0x80|( cc &0x3f) );
- else if(cc<=0x03ffffff)
- rv += String.fromCharCode(
- 0xf8|((cc>>24)&0x03),
- 0x80|((cc>>18)&0x3f),
- 0x80|((cc>>12)&0x3f),
- 0x80|((cc>> 6)&0x3f),
- 0x80|( cc &0x3f) );
- else if(cc<=0x7fffffff)
- rv += String.fromCharCode(
- 0xfc|((cc>>30)&0x01),
- 0x80|((cc>>24)&0x3f),
- 0x80|((cc>>18)&0x3f),
- 0x80|((cc>>12)&0x3f),
- 0x80|((cc>> 6)&0x3f),
- 0x80|( cc &0x3f) );
- }
- return rv;
-}
-function xp_str(xp,x) {
- var rv = x.evaluate(
- xp, x, null, XPathResult.STRING_TYPE, null );
- return rv.stringValue;
-}
-function xp_node(xp,x) {
- var rv = x.evaluate(
- xp, x, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null );
- return rv.singleNodeValue;
-}
-
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(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: 'delete' }, _this.auth_url );
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(u);
b.selectedTab = t;
if(on_s) on_s();
}, 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);
}
diff --git a/content/util.js b/content/util.js
new file mode 100644
index 0000000..5af0978
--- a/dev/null
+++ b/content/util.js
@@ -0,0 +1,61 @@
+/*
+ * convert unicode string to utf-8 representation.
+ * needed for correct md5 hash calculation.
+ */
+function toutf8(ucode) {
+ var rv = '';
+ for(var i=0;i<ucode.length;++i) {
+ var cc = ucode.charCodeAt(i);
+ if(cc<=0x7F)
+ rv += ucode.charAt(i);
+ else if(cc<=0x7ff)
+ rv += String.fromCharCode(
+ 0xc0|((cc>> 6)&0x1f),
+ 0x80|( cc &0x3f) );
+ else if(cc<=0xffff)
+ rv += String.fromCharCode(
+ 0xe0|((cc>>12)&0x0f),
+ 0x80|((cc>> 6)&0x3f),
+ 0x80|( cc &0x3f) );
+ else if(cc<=0x1fffff)
+ rv += String.fromCharCode(
+ 0xf0|((cc>>18)&0x07),
+ 0x80|((cc>>12)&0x3f),
+ 0x80|((cc>> 6)&0x3f),
+ 0x80|( cc &0x3f) );
+ else if(cc<=0x03ffffff)
+ rv += String.fromCharCode(
+ 0xf8|((cc>>24)&0x03),
+ 0x80|((cc>>18)&0x3f),
+ 0x80|((cc>>12)&0x3f),
+ 0x80|((cc>> 6)&0x3f),
+ 0x80|( cc &0x3f) );
+ else if(cc<=0x7fffffff)
+ rv += String.fromCharCode(
+ 0xfc|((cc>>30)&0x01),
+ 0x80|((cc>>24)&0x3f),
+ 0x80|((cc>>18)&0x3f),
+ 0x80|((cc>>12)&0x3f),
+ 0x80|((cc>> 6)&0x3f),
+ 0x80|( cc &0x3f) );
+ }
+ return rv;
+}
+
+/*
+ * extract xpath-specified string value
+ */
+function xp_str(xp,x) {
+ var rv = x.evaluate(
+ xp, x, null, XPathResult.STRING_TYPE, null );
+ return rv.stringValue;
+}
+/*
+ * extract xpath-specified node
+ */
+function xp_node(xp,x) {
+ var rv = x.evaluate(
+ xp, x, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null );
+ return rv.singleNodeValue;
+}
+