Friendiqa/source-linux/qml/friendiqa.qml

165 lines
5.9 KiB
QML
Raw Normal View History

2017-01-26 21:55:31 +01:00
import QtQuick 2.0
import QtQuick.LocalStorage 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.4
import "qrc:/js/news.js" as Newsjs
import "qrc:/js/service.js" as Service
2017-03-25 23:36:14 +01:00
2017-01-26 21:55:31 +01:00
TabView{
id:root
2017-03-25 23:36:14 +01:00
property QtObject osSettings: {var tmp=Qt.createComponent("qrc:/qml/configqml/OSSettingsLinux.qml");return tmp.createObject(root)}
2017-01-26 21:55:31 +01:00
tabPosition: Qt.BottomEdge
2017-03-25 23:36:14 +01:00
width: osSettings.appWidth
height:osSettings.appHeight
2017-01-26 21:55:31 +01:00
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)
2017-03-25 23:36:14 +01:00
signal contactdetailsSignal(var contact)
2017-05-11 22:15:34 +02:00
signal eventSignal(var contact)
2017-01-26 21:55:31 +01:00
property var news:[]
property var newContacts:[]
property int currentContact: 0
property string contactLoadType: ""
onLoginChanged:{
2017-05-11 22:15:34 +02:00
if(login==""){root.currentIndex=4}
else{
newstab.newstabstatus=login.newsViewType;
2017-03-25 23:36:14 +01:00
Newsjs.getCurrentContacts(login,db,function(contacts){
contactlist=contacts})}
2017-01-26 21:55:31 +01:00
}
2017-05-11 22:15:34 +02:00
onNewContactsChanged:{//print(JSON.stringify(newContacts));
2017-01-26 21:55:31 +01:00
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=[];
})}
}
2017-11-07 21:57:40 +01:00
onCurrentContactChanged:{// download next contact image after successful download and update db
2017-05-11 22:15:34 +02:00
2017-01-26 21:55:31 +01:00
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()})}
}}
2017-03-25 23:36:14 +01:00
FontLoader{id: fontAwesome; source: "qrc:/images/fontawesome-webfont.ttf"}
2017-01-26 21:55:31 +01:00
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: {
2017-03-25 23:36:14 +01:00
if (event.key === osSettings.backKey) {
2017-01-26 21:55:31 +01:00
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)
})}
2017-05-11 22:15:34 +02:00
else{
Newsjs.chatsfromdb(db,login.username,function(dbnews){
2017-01-26 21:55:31 +01:00
newsSignal(dbnews)
})}
}
2017-05-11 22:15:34 +02:00
else if (newstab.conversation.length>0){newstab.conversation=[]}
2017-01-26 21:55:31 +01:00
else{Service.cleanNews(root.db,function(){Qt.quit()})}
}
2017-03-25 23:36:14 +01:00
else if (currentIndex==2){fotoSignal("backButton")}
2017-01-26 21:55:31 +01:00
else {currentIndex=0}
event.accepted = true
}}
style: TabViewStyle {
frameOverlap: 1
tab: Rectangle {
2017-03-25 23:36:14 +01:00
color: styleData.selected?"sky blue":"light blue"
2017-01-26 21:55:31 +01:00
border.color: "light grey"
2017-11-07 21:57:40 +01:00
implicitWidth: root.width/5
2017-05-11 22:15:34 +02:00
implicitHeight: 5*mm
2017-01-26 21:55:31 +01:00
Text { id: text
anchors.centerIn: parent
text: styleData.title
color: "black"
2017-03-25 23:36:14 +01:00
font.family: fontAwesome.name
font.pixelSize: 3*mm
2017-01-26 21:55:31 +01:00
}
}
frame: Rectangle { color: "light grey" }
tabsAlignment:Qt.AlignHCenter
}
2017-03-25 23:36:14 +01:00
2017-01-26 21:55:31 +01:00
Tab{
2017-03-25 23:36:14 +01:00
title: "\uf03a"
2017-01-26 21:55:31 +01:00
id: newstab
2017-03-25 23:36:14 +01:00
property string newstabstatus
2017-01-26 21:55:31 +01:00
property var conversation
source:(root.currentIndex==0)? "qrc:/qml/newsqml/NewsTab.qml":""
}
Tab{
2017-03-25 23:36:14 +01:00
title: "\uf0c0"
2017-01-26 21:55:31 +01:00
id: friendstab
source: (root.currentIndex==1)?"qrc:/qml/contactqml/FriendsTab.qml":""
}
Tab{
2017-03-25 23:36:14 +01:00
title: "\uf03e"
2017-01-26 21:55:31 +01:00
id: fotostab
property string phototabstatus:"Images"
source: (root.currentIndex==2)?"qrc:/qml/photoqml/PhotoTab.qml":""
}
2017-05-11 22:15:34 +02:00
Tab{
title: "\uf073"
id: calendartab
property string calendartabstatus:"Events"
source: (root.currentIndex==3)?"qrc:/qml/calendarqml/CalendarTab.qml":""
}
2017-01-26 21:55:31 +01:00
Tab{
2017-03-25 23:36:14 +01:00
title:"\uf085"
id: configtab
2017-05-11 22:15:34 +02:00
source: (root.currentIndex==4)?"qrc:/qml/configqml/ConfigTab.qml":""
2017-01-26 21:55:31 +01:00
}
}