Friendiqa/v0.001/source-linux/qml/friendiqa.qml

112 lines
5.2 KiB
QML

import QtQuick 2.0
import QtQuick.LocalStorage 2.0
import QtQuick.Window 2.0
import QtQuick.Dialogs 1.2
import QtQuick.Controls 1.2
import QtQml.Models 2.1
import "qrc:/js/news.js" as Newsjs
import "qrc:/js/service.js" as Service
import "qrc:/js/layout.js" as Layoutjs
import "qrc:/js/helper.js" as Helperjs
import "qrc:/qml"
TabView{
id:root
tabPosition: Qt.BottomEdge
width: 400//Screen.desktopAvailableWidth
height: 400// Screen.desktopAvailableHeight
property var db: ["Photos", "1.0", "Stores Friendica data", 100000000]
property var login: Service.readActiveConfig(db)
property var contactlist: []
property real mm: Screen.pixelDensity
signal messageSignal(var friend)
signal fotoSignal(var friend)
signal directmessageSignal(var friend)
signal newsSignal(var news)
signal friendsSignal(var username)
currentIndex: (login=="")? 3:0
property var news:[]
property var newContacts:[]
property int currentContact: 0
property string contactLoadType: ""
onLoginChanged:{Newsjs.newsfromdb( db,login.username, function(dbnews){
newsSignal(dbnews)
})}
onNewContactsChanged:{if(newContacts.length>0){// download first contact image and update db
//print("newcontact"+JSON.stringify(newContacts[0]));
updateContactInDB(login,db,newContacts[currentContact].isFriend,newContacts[currentContact])}
}
onCurrentContactChanged:{// download next contact image after photoplaceholder is finished saving and update db
if(currentContact<newContacts.length){
updateContactInDB(login,db,newContacts[currentContact].isFriend,newContacts[currentContact])}
else if(currentContact==newContacts.length){//newImagesProgress.visible=false;
if (newContacts.length==0) {}
else if (contactLoadType=="news"){
Newsjs.storeNews(login,db,news,root,function(dbnews){
root.newsSignal(dbnews);
root.newContacts=[];
root.currentContact=0;
root.news=[]
})// show news
}
else if (contactLoadType=="friends"){
root.friendsSignal(login.username);
// show friends
Helperjs.readField("id",db,"contacts",login.username,function(contacts){contactlist=contacts;
root.newContacts=[];
root.currentContact=0},"isFriend",1) }
}
}
function updateContactInDB(login,database,isFriend,contact){// for newstab and friendstab
var imagename=login.imagestore+contact.screen_name+".jpg";
var component=Qt.createComponent("qrc:/qml/PhotoPlaceholder.qml");
var sprite = component.createObject(root, {"fillMode": "Image.PreserveAspectFit","x":root.width,"y":50,"imageName":imagename,"source": contact.profile_image_url,"downloadtype":"contact"});
var db=LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
var result;
db.transaction( function(tx) {
result = tx.executeSql('SELECT * from contacts where id = '+contact.id); // check for news id
if(result.rows.length === 1) {// use update
result = tx.executeSql('UPDATE contacts SET username="'+login.username+'", id='+contact.id+', name="'+Qt.btoa(contact.name)+'", screen_name="'+contact.screen_name+'", location="'+contact.location+'",description="'+Qt.btoa(contact.description)+'", profile_image="'+imagename+'", url="'+contact.url+'" , protected="'+contact.protected+'", followers_count='+contact.followers_count+', friends_count='+contact.friends_count+', created_at="'+ Newsjs.cleanDate(contact.created_at)+'", favourites_count="'+contact.favorites_count+'", utc_offset="'+contact.utc_offset+'", time_zone="'+contact.time_zone+'", statuses_count='+contact.statuses_count+', following="'+contact.following+'", verified ="'+contact.verified+'", statusnet_blocking="'+contact.statusnet_blocking+'", notifications="'+contact.notifictions+'", statusnet_profile_url="'+contact.statusnet_profile_url+'", cid='+contact.cid+', network="'+contact.network+'", isFriend='+isFriend+' where id='+contact.id);
} else {// use insert
result = tx.executeSql('INSERT INTO contacts VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [login.username,contact.id,Qt.btoa(contact.name),contact.screen_name,contact.location,Qt.btoa(contact.description),imagename,contact.url,contact.protected,contact.followers_count, contact.friends_count,Newsjs.cleanDate(contact.created_at),contact.favorites_count,contact.utc_offset,contact.time_zone,contact.statuses_count,contact.following,contact.verfied,contact.statusnet_blocking,contact.notifications,contact.statusnet_profile_url,contact.cid,contact.network,isFriend]);}
});
}
Component.onCompleted: {
if (login==""){Service.initDatabase(db);
}
Helperjs.readField("id",db,"contacts",login.username,function(contacts){contactlist=contacts},"isFriend",1)
}
Tab{
title: qsTr("News")
id: newstab
property string newstabStatus:"news"
source: "qrc:/qml/NewsTab.qml"
}
Tab{
title: qsTr("Friends")
id: friendstab
source: "qrc:/qml/FriendsTab.qml"
}
Tab{
title: qsTr("Photos")
id: fotostab
source: "qrc:/qml/PhotoTab.qml"
}
Tab{
title: qsTr("Config")
source: "qrc:/qml/ConfigTab.qml"
}
}