Friendiqa/source-android/qml/friendiqa.qml

281 lines
10 KiB
QML
Raw Normal View History

2018-02-19 22:36:00 +01:00
// This file is part of Friendiqa
2018-11-09 22:06:13 +01:00
// https://git.friendi.ca/lubuwest/Friendiqa
2018-02-19 22:36:00 +01:00
// 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/>.
2018-08-25 16:17:09 +02:00
import QtQuick 2.5
2017-01-26 21:55:31 +01:00
import QtQuick.LocalStorage 2.0
2020-01-27 21:53:51 +01:00
import QtQuick.Window 2.0
2019-06-25 20:59:10 +02:00
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.11
2017-01-26 21:55:31 +01:00
import "qrc:/js/news.js" as Newsjs
import "qrc:/js/service.js" as Service
2021-05-12 21:41:34 +02:00
import "qrc:/qml/genericqml"
2017-01-26 21:55:31 +01:00
2019-12-10 21:12:32 +01:00
2021-05-12 21:41:34 +02:00
ApplicationWindow{
2017-01-26 21:55:31 +01:00
id:root
2021-05-12 21:41:34 +02:00
title: "Friendiqa"
property var globaloptions: Service.readGO(db)
2017-03-25 23:36:14 +01:00
property QtObject osSettings: {var tmp=Qt.createComponent("qrc:/qml/configqml/OSSettingsAndroid.qml");return tmp.createObject(root)}
2021-05-12 21:41:34 +02:00
visible: true
2017-01-26 21:55:31 +01:00
property var db: ["Friendiqa", "1.0", "Stores Friendica data", 100000000]
property var login: Service.readActiveConfig(db)
2021-05-12 21:41:34 +02:00
property real fontFactor: root.font.pixelSize/root.font.pointSize
2017-01-26 21:55:31 +01:00
property var contactlist: []
2019-06-25 20:59:10 +02:00
property real mm: osSettings.osType=="Android"?Screen.pixelDensity:Screen.pixelDensity*1.5
2021-05-12 21:41:34 +02:00
property bool wideScreen : width>height
2018-11-09 22:06:13 +01:00
signal fotoSignal(var username, var friend)
2017-01-26 21:55:31 +01:00
signal directmessageSignal(var friend)
signal newsSignal(var news)
2019-06-25 20:59:10 +02:00
signal newstypeSignal(var type)
2017-01-26 21:55:31 +01:00
signal friendsSignal(var username)
2017-03-25 23:36:14 +01:00
signal contactdetailsSignal(var contact)
2021-05-12 21:41:34 +02:00
signal searchSignal (var searchterm)
2017-05-11 22:15:34 +02:00
signal eventSignal(var contact)
2018-04-11 21:50:43 +02:00
signal uploadSignal(var urls)
2018-04-22 21:12:40 +02:00
signal sendtextSignal(var intenttext)
2018-08-25 16:17:09 +02:00
signal changeimage(var method, var type, var id)
2020-05-24 21:14:23 +02:00
signal updateSyncinterval(int interval)
2021-05-12 21:41:34 +02:00
signal replySignal(var newsobject)
2017-01-26 21:55:31 +01:00
property var news:[]
property var newContacts:[]
2021-05-12 21:41:34 +02:00
property var contactposts:[]
2018-10-01 21:17:54 +02:00
//property string contactLoadType: ""
2018-08-25 16:17:09 +02:00
property bool imagePicking: false
2017-01-26 21:55:31 +01:00
2021-05-12 21:41:34 +02:00
function onLoginChanged(login){
if(login==""){rootstackView.push("qrc:/qml/configqml/AccountPage.qml")}
else{//rootstackView.push(rootstack)
2020-05-24 21:14:23 +02:00
if (login.newsViewType!="" || login.newsViewType!=null){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
}
2021-05-12 21:41:34 +02:00
function onNewContactsChanged(newContacts){
2018-02-19 22:36:00 +01:00
if(newContacts.length>0){// download contact images and update db
var contacturls=[];
var contactnames=[];
for (var link in newContacts){
2018-02-19 22:36:00 +01:00
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();
}
2018-10-01 21:17:54 +02:00
2017-01-26 21:55:31 +01:00
}
2021-05-12 21:41:34 +02:00
Connections {
target: root
function onWidthChanged(appWidth) {
if(osSettings.osType=="Linux" && Math.abs(appWidth-(globaloptions.appWidth||0))>50){
Service.updateglobaloptions(db,"appWidth",appWidth)
}
}
}
Connections {
target: root
function onHeightChanged(appHeight) {
if(osSettings.osType=="Linux" && Math.abs(appHeight-(globaloptions.appHeight||0))>50){
Service.updateglobaloptions(db,"appHeight",appHeight)
}
}
}
function showContact(contact){ //print(JSON.stringify(contact));
rootstackView.push("qrc:/qml/newsqml/ContactPage.qml",{"contact": contact})
}
2017-01-26 21:55:31 +01:00
Connections{
target:xhr
2021-05-12 21:41:34 +02:00
function onDownloaded(type,url,filename,i){
2018-02-19 22:36:00 +01:00
if(type=="contactlist"){
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+'"');
})
}
}
2017-01-26 21:55:31 +01:00
}
2021-05-12 21:41:34 +02:00
2017-03-25 23:36:14 +01:00
FontLoader{id: fontAwesome; source: "qrc:/images/fontawesome-webfont.ttf"}
2021-05-12 21:41:34 +02:00
onClosing: {
2019-12-10 21:12:32 +01:00
if (rootstack.currentIndex==0){
2017-01-26 21:55:31 +01:00
newstab.active=true;
2020-05-24 21:14:23 +02:00
if (newstab.newstabstatus!=globaloptions.newsViewType){
newstab.newstabstatus=globaloptions.newsViewType;
if(globaloptions.newsViewType=="Timeline"){Newsjs.newsfromdb(db,login.username,0,function(dbnews){
2017-01-26 21:55:31 +01:00
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)
})}
2021-05-12 21:41:34 +02:00
close.accepted=false;
2020-05-24 21:14:23 +02:00
}
2020-01-27 21:53:51 +01:00
2021-05-12 21:41:34 +02:00
else if (newstab.conversation.length>0){
newstab.conversation=[];
close.accepted=false
}
else if (root.depth>1){
root.pop();
close.accepted=false
}
else{
Service.cleanNews(root.db,function(){
Service.cleanHashtags(root.db,function(){
Service.cleanContacts(root.login,root.db,function(){
Qt.quit()
})
2021-05-12 21:41:34 +02:00
})})
close.accepted=true
}
2017-01-26 21:55:31 +01:00
}
else if (rootstack.currentIndex==2){fotoSignal(login.username,"backButton");print("close rootstack currentindex==2");close.accepted=false}
else {rootstack.currentIndex=0;close.accepted=false}
2021-05-12 21:41:34 +02:00
}
2017-01-26 21:55:31 +01:00
2021-05-12 21:41:34 +02:00
footer:ToolBar{
background: Rectangle{
anchors.fill: parent
color: "#EEEEEE"//"#F8F8F8"
}
TabBar {
id: bar
width:parent.width
onCurrentIndexChanged: rootstack.currentIndex=bar.currentIndex
TabButton {
text: "\uf03a"
font.pointSize: osSettings.bigFontSize
background:Rectangle{
anchors.fill: parent
color: "#EEEEEE"
2019-06-25 20:59:10 +02:00
}
}
TabButton {
text: "\uf0c0"
font.pointSize: osSettings.bigFontSize
background:Rectangle{
anchors.fill: parent
color: "#EEEEEE"
2019-06-25 20:59:10 +02:00
}
}
TabButton {
text: "\uf03e"
font.pointSize: osSettings.bigFontSize
background:Rectangle{
anchors.fill: parent
color: "#EEEEEE"
2019-06-25 20:59:10 +02:00
}
}
TabButton {
text: "\uf073"
font.pointSize: osSettings.bigFontSize
background:Rectangle{
anchors.fill: parent
color: "#EEEEEE"
2019-06-25 20:59:10 +02:00
}
}
}
2017-05-11 22:15:34 +02:00
}
2021-05-12 21:41:34 +02:00
// states: State {
// name: "fullscreen";
// PropertyChanges { target: bar; height:0 }
// PropertyChanges { target: rootstack; height:parent.height }
// }
2019-06-25 20:59:10 +02:00
2021-05-12 21:41:34 +02:00
// transitions: Transition {
// PropertyAnimation { properties: "height";
// easing.type: Easing.InOutQuad
// duration: 1000
// }
// }
StackView{id:rootstackView
width:root.width
height: root.height
initialItem: StackLayout{
2019-06-25 20:59:10 +02:00
id:rootstack
2021-05-12 21:41:34 +02:00
width:rootstackView.width
height: rootstackView.height
2019-06-25 20:59:10 +02:00
currentIndex:bar.currentIndex
Loader{
id: newstab
property string newstabstatus
property var conversation:[]
source:(rootstack.currentIndex==0)? "qrc:/qml/newsqml/NewsTab.qml":""
}
Loader{
id: friendstab
source: (rootstack.currentIndex==1)?"qrc:/qml/contactqml/FriendsTab.qml":""
}
Loader{
id: fotostab
property string phototabstatus:"Images"
source: (rootstack.currentIndex==2)?"qrc:/qml/photoqml/PhotoTab.qml":""
}
Loader{
id: calendartab
property string calendartabstatus:"Events"
source: (rootstack.currentIndex==3)?"qrc:/qml/calendarqml/CalendarTab.qml":""
}
}
2021-05-12 21:41:34 +02:00
}
2020-01-27 21:53:51 +01:00
Component.onCompleted: {
2021-05-12 21:41:34 +02:00
onLoginChanged(login);
globaloptions=Service.readGO(db);
//forceActiveFocus();
2019-01-09 22:03:16 +01:00
if(osSettings.osType=="Android"){
var component = Qt.createComponent("qrc:/qml/genericqml/IntentReceiver.qml");
var IntentReceiverQml = component.createObject(root);
2020-05-24 21:14:23 +02:00
}
else if (osSettings.osType=="Linux"){
2019-06-25 20:59:10 +02:00
var component = Qt.createComponent("qrc:/qml/genericqml/LinuxSync.qml");
var LinuxSyncQml = component.createObject(root);
2018-07-01 15:09:21 +02:00
}
}
2019-06-25 20:59:10 +02:00
}