Version 0.001
This commit is contained in:
parent
1986e59b58
commit
2bc729d02c
77 changed files with 6020 additions and 819 deletions
12
v0.001/source-android/js/friendworker.js
Normal file
12
v0.001/source-android/js/friendworker.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
WorkerScript.onMessage = function(msg) {
|
||||
msg.model.clear();
|
||||
for (var j=0;j<msg.albums.length;j++){
|
||||
if (msg.albums[j]) {
|
||||
var albumobject=msg.albums[j];
|
||||
var data=({"albumobject": albumobject,"foreignPicture": msg.foreignPicture})}
|
||||
// print("Albums:"+j+msg.albums.length+JSON.stringify(data));
|
||||
msg.model.append(data);}
|
||||
if (j==msg.albums.length){
|
||||
msg.model.sync()
|
||||
};
|
||||
}
|
80
v0.001/source-android/js/helper.js
Normal file
80
v0.001/source-android/js/helper.js
Normal file
|
@ -0,0 +1,80 @@
|
|||
.pragma library
|
||||
.import QtQuick.LocalStorage 2.0 as Sql
|
||||
|
||||
function friendicaRequest(login,api,rootwindow,callback) {
|
||||
var xhrequest= new XMLHttpRequest();
|
||||
xhrequest.onreadystatechange = function() {
|
||||
if (xhrequest.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
|
||||
} else if(xhrequest.readyState === XMLHttpRequest.DONE) {
|
||||
try{ if (xhrequest.responseText!=""){
|
||||
callback(xhrequest.responseText)
|
||||
}else{
|
||||
showMessage("Error",api+" NO RESPONSE",rootwindow)
|
||||
callback(xhrequest.responseText)
|
||||
}
|
||||
}
|
||||
catch (e){
|
||||
showMessage("Error", api+" "+e,rootwindow)
|
||||
}
|
||||
}
|
||||
}
|
||||
xhrequest.open("GET", login.server+api,true,login.username,Qt.atob(login.password));
|
||||
xhrequest.send();
|
||||
}
|
||||
|
||||
|
||||
function friendicaWebRequest(url,rootwindow,callback) {
|
||||
var xhrequest = new XMLHttpRequest();
|
||||
xhrequest.onreadystatechange = function() {
|
||||
if (xhrequest.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
|
||||
} else if(xhrequest.readyState === XMLHttpRequest.DONE) {
|
||||
try{ callback(xhrequest.responseText);
|
||||
}
|
||||
catch (e){
|
||||
showMessage("Error",url+" "+e, rootwindow)
|
||||
}
|
||||
}
|
||||
}
|
||||
xhrequest.open("GET", url,true);
|
||||
xhrequest.send();
|
||||
}
|
||||
|
||||
function readData(database,table,callback,filter,filtervalue) { // reads and applies data from DB
|
||||
if (filter){
|
||||
var where = " WHERE "+ filter +" = '" + filtervalue+"'";
|
||||
} else { var where="";}
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
if(!db) { return; }
|
||||
db.transaction( function(tx) {
|
||||
// print('select * from '+table+where);
|
||||
var rsArray=[];
|
||||
var rs = tx.executeSql('select * from '+table+where);
|
||||
for(var i = 0; i < rs.rows.length; i++) {
|
||||
rsArray.push(rs.rows.item(i))
|
||||
}
|
||||
callback(rsArray);
|
||||
});
|
||||
}
|
||||
|
||||
function readField(field,database,table, username, callback,filter,filtervalue) { // reads and applies data from DB
|
||||
if (filter){
|
||||
var where = " AND "+ filter +" = '" + filtervalue+"'";
|
||||
} else { var where="";}
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
if(!db) { return; }
|
||||
db.transaction( function(tx) {
|
||||
// print('... read from database ' + field)
|
||||
var rsArray=[];
|
||||
print('select DISTINCT '+field+' from '+table+' WHERE username="'+username+'"'+where+' ORDER BY '+field+' ASC');
|
||||
var rs = tx.executeSql('select DISTINCT '+field+' from '+table+' WHERE username="'+username+'"'+where+' ORDER BY '+field+' ASC');
|
||||
for(var i = 0; i < rs.rows.length; i++) {
|
||||
rsArray.push(rs.rows.item(i)[field])
|
||||
}
|
||||
callback(rsArray);
|
||||
});
|
||||
}
|
||||
|
||||
function showMessage(header,message,rootwindow){
|
||||
var messageString='import QtQuick 2.0; import QtQuick.Dialogs 1.2; MessageDialog{ visible: true; title:"'+header+'";standardButtons: StandardButton.Ok; text:" '+message+'"}';
|
||||
var messageObject=Qt.createQmlObject(messageString,rootwindow,"messageOutput");
|
||||
}
|
44
v0.001/source-android/js/layout.js
Normal file
44
v0.001/source-android/js/layout.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
function showFriends(db) {
|
||||
Service.readActiveConfig(db,function(login){
|
||||
Service.requestFriends(login.url,login.user,login.password,displayFriends);
|
||||
});
|
||||
}
|
||||
function displayFriends(obj){
|
||||
for (var i=0; i<obj.length; i++){
|
||||
print(obj[i]);
|
||||
if (obj[i]) {friendsModel.append({"friendName": obj[i]});
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
function ensureVisibility(c,f)
|
||||
{
|
||||
if (f.contentX >= c.x)
|
||||
f.contentX = c.x;
|
||||
else if (f.contentX+f.width <= c.x+c.width)
|
||||
f.contentX = c.x+c.width-f.width;
|
||||
if (f.contentY >= c.y)
|
||||
f.contentY = c.y;
|
||||
else if (f.contentY+f.height <= c.y+c.height)
|
||||
f.contentY = c.y+c.height-f.height;
|
||||
}
|
||||
|
||||
function createObject(objectQml,qmlParameters,parentitem,callback) {
|
||||
var component = Qt.createComponent(objectQml);
|
||||
if (component.status === Component.Ready || component.status === Component.Error)
|
||||
finishCreation(component,qmlParameters,parentitem,callback);
|
||||
else
|
||||
component.statusChanged.connect(finishCreation(qmlParameters));
|
||||
}
|
||||
|
||||
function finishCreation(component,qmlParameters,parentitem,callback) {
|
||||
if (component.status === Component.Ready) {
|
||||
var createdObject = component.createObject(parentitem, qmlParameters);
|
||||
if (createdObject === null)
|
||||
print("Error creating image"); }
|
||||
else if (component.status === Component.Error)
|
||||
print("Error loading component:"+component.errorString());
|
||||
else {print("created")}
|
||||
callback(createdObject);
|
||||
}
|
||||
|
227
v0.001/source-android/js/news.js
Normal file
227
v0.001/source-android/js/news.js
Normal file
|
@ -0,0 +1,227 @@
|
|||
.pragma library
|
||||
.import QtQuick.LocalStorage 2.0 as Sql
|
||||
.import "qrc:/js/helper.js" as Helperjs
|
||||
|
||||
function requestFriends(login,database,rootwindow,callback){
|
||||
// return array of friends
|
||||
Helperjs.friendicaRequest(login,"/api/statuses/friends", rootwindow,function (obj){
|
||||
var friends=JSON.parse(obj);
|
||||
for (var i=0;i<friends.length;i++){ friends[i].isFriend=1}
|
||||
callback(friends)
|
||||
});
|
||||
}
|
||||
|
||||
function requestGroups(login,database,rootwindow,callback){
|
||||
// retrieve, save and return groups, currently not implemented
|
||||
Helperjs.friendicaRequest(login,"/api/friendica/group_show",rootwindow, function (obj){
|
||||
var groups=JSON.parse(obj);
|
||||
for (var i=0;i<groups.length;i++){
|
||||
updateGroupInDB(login,database,groups[i])
|
||||
}
|
||||
Helperjs.readData(database,"groups",callback)
|
||||
});}
|
||||
|
||||
function getFriendsTimeline(login,database,contacts,rootwindow,callback){// retrieve and return timeline since last news, return contacts which are not friends for update (friends can be updated in Friendstab)
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
var parameter = "";
|
||||
db.transaction( function(tx) {
|
||||
var result = tx.executeSql('SELECT status_id from news WHERE username="'+login.username+'" ORDER BY status_id DESC LIMIT 1'); // check for last news id
|
||||
try{parameter="&since_id="+result.rows.item(0).status_id;}catch(e){};})
|
||||
var newContacts=[];
|
||||
Helperjs.friendicaRequest(login,"/api/statuses/friends_timeline"+parameter, rootwindow,function (obj){
|
||||
var news=JSON.parse(obj);
|
||||
for (var i=0;i<news.length;i++){
|
||||
if(contacts.indexOf(news[i].user.id)==-1 && !(inArray(newContacts,"id",news[i].user.id))){
|
||||
news[i].user.isFriend=0;
|
||||
newContacts.push(news[i].user);
|
||||
}}
|
||||
callback(news,newContacts)
|
||||
})}
|
||||
|
||||
function storeNews(login,database,news,rootwindow,callback){
|
||||
// save news after contacts download, call next function
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
for (var i=0;i<news.length;i++){
|
||||
var ausdruck=news[i];
|
||||
print('store news data for ' + news[i].id);
|
||||
db.transaction( function(tx) {
|
||||
var result = tx.executeSql('SELECT * from news where status_id = "'+news[i].id+'"'); // check for news id
|
||||
if(result.rows.length === 1) {// use update
|
||||
print(news[i].id +' exists, update it')
|
||||
result = tx.executeSql('UPDATE news SET username="'+login.username+'", messagetype=0, text="'+Qt.btoa(news[i].text)+'", truncated="'+news[i].truncated+'", created_at="'+Date.parse(cleanDate(news[i].created_at))+'", in_reply_to_status_id="'+news[i].in_reply_to_status_id+'", source="'+news[i].source+'", status_id="'+news[i].id+'", in_reply_to_user_id="'+news[i].in_reply_to_user_id+'", geo="'+news[i].geo+'", favorited="'+news[i].favorited+'", uid="'+news[i].user.id+'", statusnet_html="'+Qt.btoa(news[i].status_html)+'", statusnet_conversation_id="'+news[i].statusnet_conversation_id+'", attachments="'+news[i].attachments+'" where status_id="'+news[i].status_id+'"');
|
||||
} else {// use insert
|
||||
result = tx.executeSql('INSERT INTO news VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [login.username,0,Qt.btoa(news[i].text),news[i].truncated,Date.parse(cleanDate(news[i].created_at)), news[i].in_reply_to_status_id, news[i].source, news[i].id,news[i].in_reply_to_user_id,news[i].geo,news[i].favorited, news[i].user.id,Qt.btoa(news[i].statusnet_html),news[i].statusnet_conversation_id, news[i].attachments,0,0,0])}})
|
||||
|
||||
}
|
||||
getDirectMessage(login,database,rootwindow,callback)
|
||||
}
|
||||
|
||||
function getDirectMessage(login,database,rootwindow,callback){
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
Helperjs.friendicaRequest(login,"/api/direct_messages/all",rootwindow, function (obj){
|
||||
var messages=JSON.parse(obj);
|
||||
for (var i=0;i<messages.length;i++){
|
||||
// print('store message data for '+JSON.stringify(messages[i]));
|
||||
db.transaction( function(tx) {
|
||||
var result = tx.executeSql('SELECT * from news where status_id = "'+messages[i].id+'"'); // check for news id
|
||||
if(result.rows.length === 1) {// use update
|
||||
print(messages[i].id +' exists, update it')
|
||||
result = tx.executeSql('UPDATE news SET username="'+login.username+'", messagetype=1, text="'+Qt.btoa(messages[i].text)+'", created_at="'+Date.parse(cleanDate(messages[i].created_at))+'", in_reply_to_status_id="", source="Friendica", status_id="'+messages[i].id+'", in_reply_to_user_id="", geo="", favorited="", uid="'+messages[i].sender.id+'", statusnet_html="'+Qt.btoa(messages[i].text)+'", statusnet_conversation_id="", attachments="'+messages[i].attachments+'" where status_id="'+messages[i].status_id+'"');
|
||||
} else {// use insert
|
||||
result = tx.executeSql('INSERT INTO news VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [login.username,1,Qt.btoa(messages[i].text),0,Date.parse(cleanDate(messages[i].created_at)),, "Friendica", messages[i].id,,,, messages[i].sender.id,Qt.btoa(messages[i].text),,,0,0,0])}
|
||||
});
|
||||
}
|
||||
})
|
||||
getNotifications(login,database,rootwindow,callback)
|
||||
}
|
||||
|
||||
function getNotifications(login,database,rootwindow,callback){
|
||||
Helperjs.friendicaRequest(login,"/api/friendica/notifications", rootwindow,function (obj){
|
||||
var messages=JSON.parse(obj);
|
||||
for (var i=0;i<messages.length;i++){
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
//print('store message data for '+JSON.stringify(messages[i]));
|
||||
db.transaction( function(tx) {
|
||||
var result = tx.executeSql('SELECT * from news where status_id = "'+messages[i].id+'"'); // check for news id
|
||||
if(result.rows.length === 1) {// use update
|
||||
print(messages[i].id +' exists, update it')
|
||||
result = tx.executeSql('UPDATE news SET username="'+login.username+'", messagetype=1, text="'+Qt.btoa(messages[i].text)+'", truncated="'+messages[i].truncated+'", created_at="'+Date.parse(cleanDate(messages[i].created_at))+'", in_reply_to_status_id="", source="'+messages[i].source+'", status_id="'+messages[i].id+'", in_reply_to_user_id="", geo="'+messages[i].geo+'", favorited="", uid="'+messages[i].sender.id+'", statusnet_html="'+Qt.btoa(messages[i].text)+'", statusnet_conversation_id="", attachments="'+messages[i].attachments+'" where status_id="'+messages[i].status_id+'"');
|
||||
} else {// use insert
|
||||
result = tx.executeSql('INSERT INTO news VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [login.username,2,Qt.btoa(messages[i].msg_html),,Date.parse(cleanDate(messages[i].timestamp)),, messages[i].source, messages[i].id,,,, messages[i].sender.id,Qt.btoa(messages[i].msg_html),, messages[i].attachments],0,0,0)}});
|
||||
}
|
||||
})
|
||||
newsfromdb(database,login.username,callback)
|
||||
}
|
||||
|
||||
function newsfromdb(database,username,callback,contact,stop_time){
|
||||
// return news before stop_time (used by More button), in brackets of 20 entries, or by specified contact
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
db.transaction( function(tx) {
|
||||
if (!stop_time){var stop="";
|
||||
try{var rs = tx.executeSql('select created_at from news WHERE username="'+username+'" ORDER BY created_at DESC LIMIT 1');
|
||||
stop="<="+rs.rows.item(0).created_at}catch(e){stop="<99999999999999"}}
|
||||
else{var stop="<"+stop_time}
|
||||
var contactfilter="";if(contact){contactfilter=" AND uid='"+contact+"'"}
|
||||
var newsrs=tx.executeSql('select * from news WHERE username="'+username+'" AND created_at'+stop+contactfilter+' ORDER BY created_at DESC LIMIT 20');
|
||||
var newsArray=[];
|
||||
for(var i = 0; i < newsrs.rows.length; i++) {
|
||||
newsArray.push(newsrs.rows.item(i));
|
||||
Helperjs.readData(database,"contacts",function(userdata){
|
||||
newsArray[i].user=userdata[0];
|
||||
},"id",newsArray[i].uid);
|
||||
if(newsArray[i].in_reply_to_user_id){
|
||||
Helperjs.readData(database,"contacts",function(replytodata){
|
||||
newsArray[i].reply_user=replytodata[0];
|
||||
},"id",newsArray[i].in_reply_to_user_id)
|
||||
}
|
||||
}
|
||||
callback(newsArray)});
|
||||
}
|
||||
|
||||
function deleteNews(login,database,newsid,rootwindow,callback){
|
||||
Helperjs.friendicaRequest(login,"/api/statuses/destroy?id="+newsid, rootwindow,function (obj){
|
||||
var news=JSON.parse(obj);
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
print('delete news data for ' + newsid);
|
||||
db.transaction( function(tx) {var result = tx.executeSql('DELETE from news where status_id ='+newsid); // delete news id
|
||||
Helperjs.showMessage("Delete",result,rootwindow)});
|
||||
})}
|
||||
|
||||
function retweetNews(login,database,newsid,rootwindow,callback){
|
||||
Helperjs.friendicaRequest(login,"/api/statuses/retweet?id="+newsid, rootwindow,function (obj){
|
||||
var answer=JSON.parse(obj);
|
||||
Helperjs.showMessage("Repost",answer,rootwindow);
|
||||
})}
|
||||
|
||||
function favorite(login,favorite,newsid,rootwindow){
|
||||
// toggle favorites
|
||||
if(favorite){ Helperjs.friendicaRequest(login,"/api/favorites/create?id="+newsid, rootwindow,function (obj){
|
||||
var news=JSON.parse(obj);
|
||||
})}
|
||||
else {Helperjs.friendicaRequest(login,"/api/favorites/destroy?id="+newsid, rootwindow,function (obj){
|
||||
var news=JSON.parse(obj);
|
||||
})}
|
||||
}
|
||||
|
||||
function likerequest(login,database,toggle,verb,newsid,rootwindow,callback){ // not tested
|
||||
Helperjs.friendicaRequest(login,"/api/friendica/activity/"+verb+"?id="+newsid, rootwindow,function (obj){
|
||||
var likeReturn=JSON.parse(obj);
|
||||
if (likeReturn=="OK"){
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
db.transaction( function(tx) {var result = tx.executeSql('UPDATE news SET '+verb+'d ='+toggle+' where status_id ='+newsid);
|
||||
callback();
|
||||
})}})
|
||||
}
|
||||
|
||||
function like(login,database,toggle,verb,newsid,rootwindow,callback){
|
||||
if(verb=="like"&& toggle==1){
|
||||
likerequest(login,database,1,"like",newsid,rootwindow,callback);
|
||||
likerequest(login,database,0,"undislike",newsid,rootwindow);}
|
||||
if(verb=="dislike"&& toggle==1){
|
||||
likerequest(login,database,1,"dislike",newsid,rootwindow,callback);
|
||||
likerequest(login,database,0,"unlike",newsid,rootwindow);}
|
||||
if(toggle==0){
|
||||
likerequest(login,database,0,"un"+verb,newsid,rootwindow,callback);}
|
||||
}
|
||||
|
||||
function attend(login,database,attend,newsid,rootwindow,callback){
|
||||
Helperjs.friendicaRequest(login,"/api/friendica/activity/attend"+attend+"?id="+newsid, rootwindow,function (obj){
|
||||
var attendReturn=JSON.parse(obj);
|
||||
// print("attend: "+obj);
|
||||
//if (attendReturn=="OK")
|
||||
{
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
db.transaction( function(tx) {var result = tx.executeSql('UPDATE news SET attend="+attend+" where status_id ='+newsid);
|
||||
callback();
|
||||
})}})}
|
||||
|
||||
function requestConversation(login,database,newsid,rootwindow,callback){
|
||||
Helperjs.friendicaRequest(login,"/api/conversation/show?id="+newsid,rootwindow, function (obj){
|
||||
print(obj+JSON.stringify(obj));
|
||||
var news=JSON.parse(obj);
|
||||
for (var i=0;i<news.length;i++){
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
print('store news data for ' + news[i].id);
|
||||
db.transaction( function(tx) {
|
||||
var result = tx.executeSql('SELECT * from news where status_id = "'+news[i].id+'"'); // check for news id
|
||||
if(result.rows.length === 1) {// use update
|
||||
print(news[i].id +' exists, update it')
|
||||
result = tx.executeSql('UPDATE news SET username="'+login.username+'", messagetype=0, text="'+Qt.btoa(news[i].text)+'", truncated="'+news[i].truncated+'", created_at="'+Date.parse(cleanDate(news[i].created_at))+'", in_reply_to_status_id="'+news[i].in_reply_to_status_id+'", source="'+news[i].source+'", status_id="'+news[i].id+'", in_reply_to_user_id="'+news[i].in_reply_to_user_id+'", geo="'+news[i].geo+'", favorited="'+news[i].favorited+'", uid="'+news[i].user.id+'", statusnet_html="'+Qt.btoa(news[i].status_html)+'", statusnet_conversation_id="'+news[i].statusnet_conversation_id+'", attachments="'+news[i].attachments+'" where status_id="'+news[i].status_id+'"');
|
||||
} else {// use insert
|
||||
result = tx.executeSql('INSERT INTO news VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [login.username,0,Qt.btoa(news[i].text),news[i].truncated,Date.parse(cleanDate(news[i].created_at)), news[i].in_reply_to_status_id, news[i].source, news[i].id,news[i].in_reply_to_user_id,news[i].geo,news[i].favorited, news[i].user.id,Qt.btoa(news[i].statusnet_html),news[i].statusnet_conversation_id, news[i].attachments,0,0,0]);
|
||||
}});
|
||||
if(news[i].user.following!=true){
|
||||
updateContactInDB(login,database,rootwindow,news[i].user)}
|
||||
}
|
||||
callback();
|
||||
}
|
||||
);}
|
||||
|
||||
function conversationfromdb(database,user,conversationId,callback){
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
db.transaction( function(tx) {
|
||||
print('select * from news WHERE statusnet_conversation_id='+conversationId+' ORDER BY status_id DESC');
|
||||
var newsrs=tx.executeSql('select * from news WHERE statusnet_conversation_id='+conversationId+' ORDER BY status_id DESC');
|
||||
var newsArray=[];
|
||||
for(var i = 0; i < newsrs.rows.length; i++) {
|
||||
newsArray.push(newsrs.rows.item(i))
|
||||
Helperjs.readData(database,"contacts",function(userdata){
|
||||
newsArray[i].user=userdata[0];
|
||||
},"id",newsArray[i].uid);
|
||||
}
|
||||
callback(newsArray);
|
||||
});}
|
||||
|
||||
function inArray(list, prop, val) {
|
||||
if (list.length > 0 ) {
|
||||
for (var i in list) { if (list[i][prop] === val) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} return false;
|
||||
}
|
||||
|
||||
function cleanDate(date){
|
||||
var cleanedDate= date.slice(0,3)+", "+date.slice(8,11)+date.slice(4,7)+date.slice(25,30)+date.slice(10,25);
|
||||
return cleanedDate
|
||||
}
|
24
v0.001/source-android/js/newsworker.js
Normal file
24
v0.001/source-android/js/newsworker.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
WorkerScript.onMessage = function(msg) {
|
||||
if(msg.appendnews!==true){ msg.model.clear()};
|
||||
for (var j=0;j<msg.news.length;j++){
|
||||
if (msg.news[j]) {
|
||||
var newsitemobject=msg.news[j];
|
||||
var seconds=(msg.currentTime-newsitemobject.created_at)/1000;
|
||||
var timestring="";
|
||||
if (seconds<60) {timestring=seconds+" "+qsTr("seconds") +" "+qsTr("ago");}
|
||||
else if (seconds<90){timestring=Math.round(seconds/60)+" "+qsTr("minute") +" "+qsTr("ago");}
|
||||
else if (seconds<3600){timestring=Math.round(seconds/60)+" "+qsTr("minutes") +" "+qsTr("ago");}
|
||||
else if (seconds<5400){timestring=Math.round(seconds/3600)+" "+qsTr("hour") +" "+qsTr("ago");}
|
||||
else if (seconds<86400){timestring=Math.round(seconds/3600)+" "+qsTr("hours") +" "+qsTr("ago");}
|
||||
else if (seconds<129600){timestring=Math.round(seconds/86400)+" "+qsTr("day") +" "+qsTr("ago");}
|
||||
else if (seconds<3888000){timestring=Math.round(seconds/86400)+" "+qsTr("days") +" "+qsTr("ago");}
|
||||
else if (seconds<5832000){timestring=Math.round(seconds/3888000)+" "+qsTr("month") +" "+qsTr("ago");}
|
||||
else if (seconds<69984000){timestring=Math.round(seconds/3888000)+" "+qsTr("months") +" "+qsTr("ago");}
|
||||
else {timestring=Math.round(seconds/69984000)+" "+qsTr("years") +" "+qsTr("ago");}
|
||||
var data=({"newsitemobject": newsitemobject,"dateDiff":timestring})}
|
||||
// print("News:"+j+msg.news.length+JSON.stringify(data));
|
||||
msg.model.append(data);}
|
||||
if (j==msg.news.length){
|
||||
msg.model.sync()
|
||||
};
|
||||
}
|
15
v0.001/source-android/js/photoworker.js
Normal file
15
v0.001/source-android/js/photoworker.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
WorkerScript.onMessage = function(msg) {
|
||||
if (msg.firstalbum==0){msg.model.clear();}
|
||||
var limit=0; if (msg.albums.length-msg.firstalbum<20){limit=msg.albums.length} else{limit=msg.firstalbum+20}
|
||||
for (var j=msg.firstalbum;j<limit;j++){
|
||||
if (msg.albums[msg.firstalbum]) {
|
||||
// print("album"+msg.albums[j].name);
|
||||
if(msg.foreignPicture){
|
||||
var albumname=msg.albums[j].name.trim();var albumlink=msg.albums[j].link
|
||||
}else{
|
||||
var albumname=msg.albums[j].toString();var albumlink=""}
|
||||
msg.model.append({"albumlink":albumlink,"foreignPicture":msg.foreignPicture,"albumname":albumname});
|
||||
msg.model.sync()
|
||||
};
|
||||
}
|
||||
}
|
223
v0.001/source-android/js/service.js
Normal file
223
v0.001/source-android/js/service.js
Normal file
|
@ -0,0 +1,223 @@
|
|||
//.pragma library
|
||||
.import QtQuick.LocalStorage 2.0 as Sql
|
||||
.import "qrc:/js/helper.js" as Helperjs
|
||||
.import "qrc:/js/news.js" as Newsjs
|
||||
|
||||
// IMAGE FUNCTIONS
|
||||
|
||||
function requestList(login,database,rootwindow,callback) {
|
||||
//get list of own images and call download function
|
||||
Helperjs.friendicaRequest(login,"/api/friendica/photos/list", rootwindow,function (helperobject){
|
||||
// print("return"+helperobject);
|
||||
var obj=JSON.parse(helperobject);
|
||||
Helperjs.readField("resourceID",database,"imageData",login.username,function(AllStoredImages){
|
||||
for(var i=0;i< AllStoredImages.length;i++){
|
||||
obj.splice(obj.indexOf(AllStoredImages[i]),1);
|
||||
}
|
||||
});
|
||||
callback(obj);
|
||||
})}
|
||||
|
||||
function dataRequest(login,photoID,database,rootwindow) {
|
||||
// check if image exist and call download function
|
||||
Helperjs.friendicaRequest(login,"/api/friendica/photo?photo_id="+photoID, rootwindow, function (obj){
|
||||
try{ if(obj==""){currentImageNo=currentImageNo+1}else{
|
||||
var image = JSON.parse(obj);
|
||||
storeData(image,database,login)}}
|
||||
catch (e){print("Data retrieval failure! "+ e+obj);}
|
||||
});
|
||||
}
|
||||
|
||||
function storeData(obj,database,login) { // store image data to DB
|
||||
print('storeData() for ' + obj.filename)
|
||||
try{sprite.destroy();}catch(e){}
|
||||
if (obj.data==""){currentImageNo=currentImageNo+1}
|
||||
else{
|
||||
var filename=obj.filename;
|
||||
// check if text name has valid image format ending, otherwise append appropriate ending
|
||||
if(["jpg","png"].indexOf(filename.substring(filename.lastIndexOf(".")+1,filename.length))==-1){
|
||||
// print("falscheEndung: "+filename.substring(filename.lastIndexOf(".")+1,filename.length));
|
||||
{ if (obj.type=="image/jpeg") {obj["filename"]=filename+".jpg"}
|
||||
if (obj.type=="image/png") {obj["filename"]=filename+".png"} }
|
||||
print("Filename: "+obj.filename+filename)
|
||||
}
|
||||
if (filename==""){
|
||||
if (obj.type=="image/jpeg") {obj["filename"]=obj["resource-id"]+".jpg"}
|
||||
if (obj.type=="image/png") {obj["filename"]=obj["resource-id"]+".png"} }
|
||||
print("Name for savebase64image: "+ obj.filename+" ResourceID: "+ obj["resource-id"]+obj.type)
|
||||
// call image download function
|
||||
saveBase64Image(obj,login.imagestore,function(obj,sprite){
|
||||
//sprite.destroy(500);
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
db.transaction( function(tx) {
|
||||
print('... check if a object exists: '+obj["resource-id"])
|
||||
var result = tx.executeSql('SELECT * from imageData where resourceID = "'+obj["resource-id"]+'"');
|
||||
if(result.rows.length === 1) {// use update
|
||||
print(obj["resource-id"] +' exists, update it')
|
||||
result = tx.executeSql('UPDATE imageData SET username ="' +login.username+ '",id="'+obj.id+'", uid="'+obj.uid+'", contact_id="'+obj.contact_id+'", guid="'+obj.guid+'", created="'+obj.created+'", edited="'+obj.edited+'", datasize="'+obj.datasize+'", scale="'+obj.scale+'", profile="'+obj.profile+'", allow_cid="'+obj.allow_cid+'", allow_gid="'+obj.allow_gid+'", deny_cid="'+obj.deny_cid+'", deny_gid="'+obj.deny_gid+'", filename="'+obj.filename+'",title="'+obj.title+'", desc="'+obj.desc+'", type="'+obj.type+'", width="'+obj.width+'", height="'+obj.height+'", album="'+obj.album+'", location="file://'+login.imagestore+'", data="", where resourceID="'+obj["resource-id"]+'"');
|
||||
} else {// use insert print('... does not exists, create it')
|
||||
result = tx.executeSql('INSERT INTO imageData VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [login.username,obj.id,obj.uid,obj.contact_id,obj.guid, obj["resource-id"], obj.created,obj.edited, obj.title, obj.desc, obj.album, obj.filename, obj.type, obj.height, obj.width, obj.datasize, ,obj.scale, obj.profile,obj.allow_cid,obj.allow_gid,obj.deny_cid,obj.deny_gid,'file://'+login.imagestore]);
|
||||
print("Inserted");}
|
||||
});
|
||||
})}}
|
||||
|
||||
function saveBase64Image(obj,storagedirectory,callback) {
|
||||
// create image component from base64 code and save it
|
||||
print("Storing "+storagedirectory+obj.filename+obj.width+"x"+obj.height);
|
||||
var maxSize=Math.max(fotostab.width,fotostab.height);
|
||||
var helpwidth=(obj.width<maxSize)?obj.width:maxSize;
|
||||
var helpheight=(obj.height<maxSize)?obj.height:maxSize;
|
||||
|
||||
if (obj.width>obj.height){ //landscape
|
||||
helpheight=helpwidth*obj.height/obj.width
|
||||
} else { //portrait
|
||||
helpwidth=helpheight*obj.width/obj.height
|
||||
}
|
||||
var component=Qt.createComponent("qrc:/qml/PhotoPlaceholder.qml");
|
||||
var sprite = component.createObject(fotostab, {"x":0,"y":0,"imageName":storagedirectory+obj.filename ,"width":helpwidth,"height":helpheight,"source": "data:image/jpeg;base64,"+obj.data,"downloadtype":"picture"});
|
||||
// print("sprite: "+sprite);
|
||||
callback(obj,sprite)
|
||||
}
|
||||
|
||||
function deleteImageData(database,user,field,selection,callback) { // does nothing useful at the moment
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
print(' delete Image Data() for ' + field +"="+selection)
|
||||
db.transaction( function(tx) {
|
||||
result = tx.executeSql('UPDATE imageData SET data="" where '+ field +'="'+selection+'"');
|
||||
callback(result)})
|
||||
}
|
||||
|
||||
function requestFriendsAlbumPictures(friend,rootwindow,callback){
|
||||
// screenscraping of albums page of contact without user and password
|
||||
Helperjs.friendicaWebRequest(friend.url.replace("profile","photos"),rootwindow,function(photohtml){
|
||||
var photoarray=[];
|
||||
var arr = photohtml.split("sidebar-photos-albums-li");
|
||||
for (var i=2;i<arr.length;i++){
|
||||
var albumlink = arr[i].substring(arr[i].indexOf('http'),arr[i].indexOf('class')-2);
|
||||
var albumname=arr[i].substring(arr[i].indexOf('/span')+6,arr[i].indexOf('</a>')-1);
|
||||
var album={'link':albumlink,'name':albumname}
|
||||
photoarray.push(album);
|
||||
}
|
||||
//print("Album"+JSON.stringify(photoarray));
|
||||
callback(photoarray)
|
||||
})
|
||||
}
|
||||
|
||||
function requestFriendsPictures(link,rootwindow,callback){
|
||||
// screenscraping of pictures page for given album
|
||||
Helperjs.friendicaWebRequest(link,rootwindow,function(photohtml){
|
||||
var photoarray=[];
|
||||
var basehtml=photohtml.substring(photohtml.indexOf('<base')+12,photohtml.indexOf('/>',photohtml.indexOf('<base'))-2);
|
||||
|
||||
// old theme
|
||||
if (photohtml.indexOf("photo-album-image-wrapper-end")>-1){ //theme 1
|
||||
var arr = photohtml.split("photo-album-image-wrapper-end");}
|
||||
|
||||
// other themes
|
||||
if (photohtml.indexOf("photo-album-wrapper")>-1){ //theme 2
|
||||
var photoarea=photohtml.substring(photohtml.indexOf("photo-album-wrapper"),photohtml.indexOf("photo-album-end"))
|
||||
var arr = photoarea.split("</a>");}
|
||||
|
||||
for (var i=0;i<arr.length-1;i++){
|
||||
var photoname=arr[i].substring(arr[i].lastIndexOf('alt')+5,arr[i].lastIndexOf('title')-2);
|
||||
var thumblink=arr[i].substring(arr[i].lastIndexOf('<img')+10,arr[i].lastIndexOf('alt')-2);
|
||||
|
||||
var imagetype=thumblink.substring(thumblink.lastIndexOf("."));
|
||||
var photolink=thumblink.substring(0,thumblink.length-imagetype.length-2)+"-0"+imagetype
|
||||
if(thumblink.substring(0,4)!=="http"){thumblink=basehtml+thumblink}
|
||||
if(photolink.substring(0,4)!=="http"){photolink=basehtml+photolink}
|
||||
var photo={'link':photolink,'name':photoname,'thumb':thumblink}
|
||||
photoarray.push(photo);
|
||||
}
|
||||
callback(photoarray)
|
||||
})
|
||||
}
|
||||
|
||||
// CONFIG FUNCTIONS
|
||||
|
||||
function initDatabase(database) { // initialize the database object
|
||||
var db =Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
print('initDatabase()'+database[0]+database[1]+database[2]+database[3])
|
||||
db.transaction( function(tx) {
|
||||
print('... create table')
|
||||
tx.executeSql('CREATE TABLE IF NOT EXISTS imageData(username TEXT,id INT, uid INT, contact_id INT, guid TEXT, resourceID TEXT, created TEXT,edited TEXT, title TEXT, desc TEXT, album TEXT,filename TEXT, type TEXT, height INT, width INT, datasize INT, data BLOB, scale INT, profile INT, allow_cid TEXT, allow_gid TEXT, deny_cid TEXT, deny_gid TEXT,location TEXT)');
|
||||
tx.executeSql('CREATE TABLE IF NOT EXISTS config(server TEXT, username TEXT, password TEXT, imagestore TEXT, maxnews INT, timerInterval INT, newsViewType TEXT,isActive INT)');
|
||||
tx.executeSql('CREATE TABLE IF NOT EXISTS news(username TEXT, messagetype INT, text TEXT, truncated TEXT, created_at INT, in_reply_to_status_id INT, source TEXT, status_id INT, in_reply_to_user_id INT, geo TEXT,favorited TEXT, uid INT, statusnet_html TEXT, statusnet_conversation_id TEXT,attachments TEXT, liked INT, disliked INT, attend TEXT)');
|
||||
tx.executeSql('CREATE TABLE IF NOT EXISTS contacts(username TEXT, id INT, name TEXT, screen_name TEXT, location TEXT,description TEXT, profile_image BLOB, url TEXT, protected TEXT, followers_count INT, friends_count INT, created_at TEXT, favourites_count TEXT, utc_offset TEXT, time_zone TEXT, statuses_count INT, following TEXT, verified TEXT, statusnet_blocking TEXT, notifications TEXT, statusnet_profile_url TEXT, cid INT, network TEXT, isFriend INT)');
|
||||
tx.executeSql('CREATE TABLE IF NOT EXISTS groups(username TEXT, groupname TEXT, gid INT, members TEXT)');
|
||||
})}
|
||||
|
||||
function storeConfig(database,obj) { // stores config to DB
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
print('storeConfig() for ' + obj.username)
|
||||
print('database: ' + database[0]);
|
||||
db.transaction( function(tx) {
|
||||
print('... check if a object exists: '+obj.username)
|
||||
var result = tx.executeSql('SELECT * from config WHERE username="'+obj.username+'"');
|
||||
if(result.rows.length === 1) {// use update
|
||||
print(obj.username +' exists, update it');
|
||||
var result2 = tx.executeSql('UPDATE config SET server="'+obj.server+'",password="'+obj.password+'", imagestore="'+obj.imagestore+'", maxnews="+obj.maxnews+", isActive=0 WHERE username="'+obj.username +'"');
|
||||
var result3 = tx.executeSql('UPDATE config SET isActive=1 WHERE username !="'+obj.username +'"');
|
||||
var result4 = tx.executeSql('UPDATE config SET maxnews='+obj.maxnews);
|
||||
} else {// use insert print('... does not exists, create it')
|
||||
var result2 = tx.executeSql('INSERT INTO config VALUES (?,?,?,?,?,?,?,?)', [obj.server, obj.username, obj.password, obj.imagestore, obj.maxnews, 0,"list",0]);
|
||||
var result3 = tx.executeSql('UPDATE config SET isActive=1 WHERE username !="'+obj.username +'"');
|
||||
var result4 = tx.executeSql('UPDATE config SET maxnews='+obj.maxnews);
|
||||
print("Inserted");}
|
||||
});}
|
||||
|
||||
function getServerConfig(login,rootwindow,callback){
|
||||
// check server with given credentials
|
||||
try {Helperjs.friendicaRequest(login,"/api/statusnet/config",rootwindow, function (obj){
|
||||
var serverconfig = JSON.parse(obj);
|
||||
var serverconfigString="import QtQuick 2.0; import QtQuick.Dialogs 1.2; MessageDialog{ visible: true; title:'Server';standardButtons: StandardButton.Ok;text: 'SUCCESS! \nName: "+serverconfig.site.name+"\nLanguage: "+serverconfig.site.language+
|
||||
"\nEmail: "+serverconfig.site.email+"\nTimezone: "+serverconfig.site.timezone+"\nClosed: "+serverconfig.site.closed+
|
||||
"\nText limit: "+serverconfig.site.textlimit+"\nShort Url length: "+serverconfig.site.shorturllength+
|
||||
"\nFriendica version: "+serverconfig.site.friendica.FRIENDICA_VERSION+"\nDFRN version: "+serverconfig.site.friendica.DFRN_PROTOCOL_VERSION +
|
||||
"\nDB Update version: "+serverconfig.site.friendica.DB_UPDATE_VERSION+"'}";
|
||||
callback(serverconfigString);
|
||||
})}
|
||||
catch (e){callback (e);
|
||||
}}
|
||||
|
||||
function readConfig(database,callback,filter,filtervalue) { // reads config
|
||||
print('readConfig()')
|
||||
if (filter){var where = " WHERE "+ filter +" = '" + filtervalue+"'";} else { var where="";}
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3],initDatabase(database));
|
||||
db.transaction( function(tx) {
|
||||
var tables = tx.executeSql("SELECT * FROM sqlite_master WHERE type='table'");
|
||||
if (tables.rows.length==0){print("no database");callback("")} else {
|
||||
print('... read from database '+where)
|
||||
var rs = tx.executeSql('select * from config'+where);
|
||||
var rsArray=[];
|
||||
if (rs.rows.length>0){
|
||||
for(var i = 0; i < rs.rows.length; i++) {
|
||||
rsArray.push(rs.rows.item(i))
|
||||
}
|
||||
var rsObject={server:rsArray[0].server,username:rsArray[0].username, password:rsArray[0].password,imagestore:rsArray[0].imagestore,maxnews:rsArray[0].maxnews,isActive:rsArray[0].isActive};
|
||||
} else {
|
||||
var rsObject=""
|
||||
}
|
||||
callback(rsObject);}}
|
||||
);
|
||||
}
|
||||
|
||||
function readActiveConfig(database){
|
||||
var obj;
|
||||
readConfig(database,function(config){
|
||||
obj=config},"isActive", 0);
|
||||
return obj;
|
||||
}
|
||||
|
||||
function deleteConfig(database,userobj,callback) { // delete user data from DB
|
||||
print('deleteConfig()')
|
||||
if (userobj){var where = " WHERE username='"+ userobj.username+"' and server='"+userobj.server+"'";} else { return "no user selected!";}
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
if(!db) { return; }
|
||||
db.transaction( function(tx) {
|
||||
print('... read from database '+where)
|
||||
var rs = tx.executeSql('delete * from config'+where);
|
||||
print(rs.toString);
|
||||
callback(rs);
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue