//.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.widthobj.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')-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('',photohtml.indexOf('-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("");} for (var i=0;i0){ 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); }); }