Friendiqa/source-android/qml/friendiqa.qml
2018-07-01 15:09:21 +02:00

201 lines
7.2 KiB
QML

// This file is part of Friendiqa
// https://github.com/lubuwest/Friendiqa
// Copyright (C) 2017 Marco R. <thomasschmidt45@gmx.net>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations including
// the two.
//
// You must obey the GNU General Public License in all respects for all
// of the code used other than OpenSSL. If you modify file(s) with this
// exception, you may extend this exception to your version of the
// file(s), but you are not obligated to do so. If you do not wish to do
// so, delete this exception statement from your version. If you delete
// this exception statement from all source files in the program, then
// also delete it here.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
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
import "qrc:/qml/genericqml"
TabView{
id:root
property QtObject osSettings: {var tmp=Qt.createComponent("qrc:/qml/configqml/OSSettingsAndroid.qml");return tmp.createObject(root)}
//IntentReceiver{}
tabPosition: Qt.BottomEdge
width: osSettings.appWidth
height:osSettings.appHeight
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 login, var friend)
signal directmessageSignal(var friend)
signal newsSignal(var news)
signal friendsSignal(var username)
signal contactdetailsSignal(var contact)
signal eventSignal(var contact)
signal uploadSignal(var urls)
signal sendtextSignal(var intenttext)
property var news:[]
property var newContacts:[]
property string contactLoadType: ""
onLoginChanged:{
if(login==""){root.currentIndex=4}
else{
newstab.newstabstatus=login.newsViewType;
Newsjs.getCurrentContacts(login,db,function(contacts){
contactlist=contacts})}
}
onNewContactsChanged:{
if(newContacts.length>0){// download contact images and update db
var contacturls=[];
var contactnames=[];
for (var link in newContacts){
contacturls.push(newContacts[link].profile_image_url);
contactnames.push(newContacts[link].screen_name);
Service.updateContactInDB(login,db,newContacts[link].isFriend,newContacts[link])
contactlist.push(newContacts[link].url);
}
xhr.setDownloadtype("contactlist");
xhr.setFilelist(contacturls);
xhr.setContactlist(contactnames);
xhr.setImagedir(login.imagestore);
xhr.getlist();
// Service.processNews(function(){
// root.contactLoadType="";
// root.news=[];
// })
}
// else if (contactLoadType!=""){
// Service.processNews(function(){
// root.contactLoadType="";
// root.news=[];
// })}
}
Connections{
target:xhr
onDownloaded:{
if(type=="contactlist"){
//print("contact image saved"+Date.now()+" "+filename+" "+url);
var database=LocalStorage.openDatabaseSync(root.db[0],root.db[1],root.db[2],root.db[3]);
var result;
database.transaction( function(tx) {
result = tx.executeSql('UPDATE contacts SET profile_image="'+filename+'" where profile_image_url="'+url+'"');
})
}
}
}
FontLoader{id: fontAwesome; source: "qrc:/images/fontawesome-webfont.ttf"}
Keys.onReleased: {
if (event.key === osSettings.backKey) {
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 if (newstab.conversation.length>0){newstab.conversation=[]}
else{Service.cleanNews(root.db,function(){
Service.cleanContacts(root.login,root.db,function(){
Qt.quit()})
})}
}
else if (currentIndex==2){fotoSignal("backButton")}
else {currentIndex=0}
event.accepted = true
}}
style: TabViewStyle {
frameOverlap: 1
tab: Rectangle {
color: styleData.selected?"sky blue":"light blue"
//border.color: "light grey"
implicitWidth: root.width/5
implicitHeight: 5*mm
Text { id: text
anchors.centerIn: parent
text: styleData.title
color: "black"
font.family: fontAwesome.name
font.pixelSize: 3*mm
}
}
frame: Rectangle { color: "light grey" }
tabsAlignment:Qt.AlignHCenter
}
Tab{
title: "\uf03a"
id: newstab
property string newstabstatus
property var conversation:[]
source:(root.currentIndex==0)? "qrc:/qml/newsqml/NewsTab.qml":""
}
Tab{
title: "\uf0c0"
id: friendstab
source: (root.currentIndex==1)?"qrc:/qml/contactqml/FriendsTab.qml":""
}
Tab{
title: "\uf03e"
id: fotostab
property string phototabstatus:"Images"
source: (root.currentIndex==2)?"qrc:/qml/photoqml/PhotoTab.qml":""
}
Tab{
title: "\uf073"
id: calendartab
property string calendartabstatus:"Events"
source: (root.currentIndex==3)?"qrc:/qml/calendarqml/CalendarTab.qml":""
}
Tab{
title:"\uf085"
id: configtab
source: (root.currentIndex==4)?"qrc:/qml/configqml/ConfigTab.qml":""
}
Component.onCompleted: {
if(osSettings.imagePickQml=="ImagePicker"){var component = Qt.createComponent("qrc:/qml/genericqml/IntentReceiver.qml");
var IntentReceiverQml = component.createObject(root)
}
}
}