Friendiqa/v0.002/Release/source-linux/qml/friendiqa.qml

150 lines
5.4 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 QtQuick.Controls.Styles 1.4
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: 500//Screen.desktopAvailableWidth
height: 500//Screen.desktopAvailableHeight
focus:true
property var db: ["Friendiqa", "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.getCurrentContacts(login,db,function(contacts){
contactlist=contacts});
}
onNewContactsChanged:{
if(newContacts.length>0){// download first contact image and update db
Service.updateContactInDB(login,db,newContacts[currentContact].isFriend,newContacts[currentContact])}
else if (contactLoadType!=""){
Service.processNews(function(){
root.contactLoadType="";
root.news=[];
})}
}
onCurrentContactChanged:{// download next contact image after photoplaceholder is finished saving and update db
if(currentContact<newContacts.length){
Service.updateContactInDB(login,db,newContacts[currentContact].isFriend,newContacts[currentContact])}
else if (contactLoadType!=""){
Service.processNews(function(){
root.contactLoadType="";
root.news=[];
root.newContacts=[];
root.currentContact=0;
})}
}
Connections{
target:xhr
onDownloaded:{if(data=="contact"){contacttimer.stop();root.currentContact=root.currentContact+1}}
}
Connections{
target:xhr
onError:{print("Error"+data);
if (data=="contact"){
var database=LocalStorage.openDatabaseSync(root.db[0],root.db[1],root.db[2],root.db[3]);
var result;
database.transaction( function(tx) {
//print('UPDATE contacts SET profile_image="" where username="'+root.login.username+'" AND id = '+newContacts[currentContact].id);
result = tx.executeSql('UPDATE contacts SET profile_image="" where username="'+root.login.username+'" AND id = '+newContacts[currentContact].id);
root.currentContact=root.currentContact+1;contacttimer.stop()})}
}}
Timer {id:contacttimer; interval: 5000; running: false; repeat: false
onTriggered: {
var database=LocalStorage.openDatabaseSync(root.db[0],root.db[1],root.db[2],root.db[3]);
database.transaction( function(tx) {
var result = tx.executeSql('UPDATE contacts SET profile_image="" where username="'+root.login.username+'" AND id = '+newContacts[currentContact].id);
root.currentContact=root.currentContact+1})}
}
Keys.onReleased: {
if (event.key === Qt.Key_Escape) {
if (currentIndex==0){
newstab.active=true;
if (newstab.newstabstatus!=login.newsViewType){
newstab.newstabstatus=login.newsViewType;
if(login.newsViewType=="Timeline"){Newsjs.newsfromdb(db,login.username,function(dbnews){
newsSignal(dbnews)
})}
else{Newsjs.chatsfromdb(db,login.username,function(dbnews){
newsSignal(dbnews)
})}
}
else{Service.cleanNews(root.db,function(){Qt.quit()})}
}
else {currentIndex=0}
event.accepted = true
}}
style: TabViewStyle {
frameOverlap: 1
tab: Rectangle {
color: styleData.selected?"white":"light blue"
border.color: "light grey"
implicitWidth: root.width/4-2*mm
implicitHeight: 4*mm
Text { id: text
anchors.centerIn: parent
text: styleData.title
color: "black"
font.pixelSize:3*mm
font.bold: styleData.selected
}
}
frame: Rectangle { color: "light grey" }
tabsAlignment:Qt.AlignHCenter
}
Tab{
title: qsTr("News")
id: newstab
property string newstabstatus:login.newsViewType
property var conversation
source:(root.currentIndex==0)? "qrc:/qml/newsqml/NewsTab.qml":""
}
Tab{
title: qsTr("Contacts")
id: friendstab
source: (root.currentIndex==1)?"qrc:/qml/contactqml/FriendsTab.qml":""
}
Tab{
title: qsTr("Photos")
id: fotostab
property string phototabstatus:"Images"
source: (root.currentIndex==2)?"qrc:/qml/photoqml/PhotoTab.qml":""
}
Tab{
title: qsTr("Config")
source: (root.currentIndex==3)?"qrc:/qml/configqml/ConfigTab.qml":""
}
}