Friendiqa/source-linux/qml/newsqml/NewsTab.qml

273 lines
12 KiB
QML

// This file is part of Friendiqa
// https://git.friendi.ca/lubuwest/Friendiqa
// Copyright (C) 2020 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.15
import QtQuick.Controls 6.3
import "qrc:/qml/newsqml"
import "qrc:/qml/genericqml"
import "qrc:/js/news.js" as Newsjs
import "qrc:/js/helper.js" as Helperjs
import "qrc:/js/service.js" as Service
Page{
id:newstabitem
width:rootstack.width
height: rootstack.height
property var newstypes: globaloptions.hasOwnProperty("defaultNewsTypes")?globaloptions.defaultNewsTypes:["Home","Replies","DirectMessages","Notifications"]
Timer {id:contacttimer; interval: 50; running: false; repeat: false
onTriggered: {
root.newContacts=Newsjs.findNewContacts(root.news,root.contactlist);
root.onNewContactsChanged(root.newContacts);
Newsjs.storeNews(login,db,root.news,root)
}
}
function showConversation(conversationIndex,newsitemobject){
if(newsitemobject.messagetype==0 || newsitemobject.messagetype==3){
xhr.setAccount(login);
xhr.setApi("/api/conversation/show");
xhr.setParam("id",newsitemobject.id)
xhr.setParam("count","200")
xhr.get();
}
else{
xhr.setAccount(login);
xhr.setApi("/api/direct_messages/conversation");
xhr.setParam("uri",newsitemobject.statusnet_conversation_id)
xhr.get();
}
}
function getDateDiffString (seconds){
var timestring="";
if (seconds<60) {timestring= Math.round(seconds) + " " +qsTr("seconds");}
else if (seconds<90){timestring= Math.round(seconds/60) + " " +qsTr("minute") ;}
else if (seconds<3600){timestring= Math.round(seconds/60) + " " +qsTr("minutes");}
else if (seconds<5400){timestring= Math.round(seconds/3600) + " " +qsTr("hour");}
else if (seconds<86400){timestring= Math.round(seconds/3600) + " " +qsTr("hours");}
else if (seconds<129600){timestring= Math.round(seconds/86400) + " " +qsTr("day");}
else if (seconds<3888000){timestring= Math.round(seconds/86400) + " " +qsTr("days");}
else if (seconds<5832000){timestring= Math.round(seconds/3888000) + " " +qsTr("month");}
else if (seconds<69984000){timestring= Math.round(seconds/3888000) + " " +qsTr("months");}
else {timestring= Math.round(seconds/46656000) + " " + qsTr("years");}
return timestring;
}
function getActivitiesView(newsitemobject){
var likeText="";var dislikeText="";var attendyesText="";var attendnoText="";var attendmaybeText=""; var self={};
try{if (newsitemobject.messagetype==0&&newsitemobject.hasOwnProperty('friendica_activities')){
if (newsitemobject.friendica_activities.like.length>0){
if (newsitemobject.friendica_activities.like.length==1){likeText= newsitemobject.friendica_activities.like[0].name+" "+ qsTr("likes this.")}
else {likeText= newsitemobject.friendica_activities.like.length+" "+ qsTr("like this.")}
}
if (newsitemobject.friendica_activities.dislike.length>0){
if (newsitemobject.friendica_activities.dislike.length==1){dislikeText= newsitemobject.friendica_activities.dislike[0].name+" "+ qsTr("doesn't like this.")}
else {dislikeText= newsitemobject.friendica_activities.dislike.length+" "+ qsTr("don't like this.")}
}
if (newsitemobject.friendica_activities.attendyes.length>0){
if (newsitemobject.friendica_activities.attendyes.length==1){attendyesText=newsitemobject.friendica_activities.attendyes[0].name+" "+ qsTr("will attend.")}
else {attendyesText= newsitemobject.friendica_activities.attendyes.length+" "+ qsTr("persons will attend.")}
}
if (newsitemobject.friendica_activities.attendno.length>0){
if (newsitemobject.friendica_activities.attendno.length==1){attendnoText= newsitemobject.friendica_activities.attendno[0].name+" "+ qsTr("will not attend.")}
else {attendnoText= newsitemobject.friendica_activities.attendno.length+" "+ qsTr("persons will not attend.")}
}
if (newsitemobject.friendica_activities.attendmaybe.length>0){
if (newsitemobject.friendica_activities.attendmaybe.length==1){attendmaybeText= newsitemobject.friendica_activities.attendmaybe[0].name+" "+ qsTr("may attend.")}
else {attendmaybeText= newsitemobject.friendica_activities.attendmaybe.length+" "+ qsTr("persons may attend.")}
}
//var friendica_activities_self=JSON.parse(newsitemobject.friendica_activities_self);
}} catch(e){print("Activities "+e+ " "+JSON.stringify(newsitemobject.friendica_activities))}
return {likeText:likeText,dislikeText:dislikeText,attendyesText:attendyesText,attendnoText:attendnoText,attendmaybeText:attendmaybeText}
}
function openMessageSend(messageState,newsitemobject){
var parentId=""
var replyUser=""
if(newsitemobject!=""){
parentId=newsitemobject.id
replyUser=newsitemobject.user.screen_name;
}
// var messageString='import QtQuick 2.15; import QtQuick.Window 2.0; import "qrc:/qml/newsqml";'+
// ' Window{id:messageWindow; title:"Message"; width:root.width; height:root.height; '+
// 'MessageSend{state:"'+messageState+'"} Component.onCompleted: {x=Screen.width/2-width/2; y=Screen.height/2-height/2}}';
// var messageObject=Qt.createQmlObject(messageString,root,"messageOutput");
var messageObject = Qt.createComponent("qrc:/qml/newsqml/MessageSend.qml");
var messageWindow=messageObject.createObject(root, { parentId: parentId, reply_to_user: replyUser, windowstate: messageState });
messageWindow.show();
}
function getIcon(typerequest){
switch (typerequest){
case "Home": return "\uf015"
case "Favorites": return "\uf005";
case "Replies": return "\uf0ec";
case "DirectMessages": return "\uf0e0";
case "Public Timeline": return "\uf0ac";
case "Group News": return "\uf0c0";
case "Search": return "\uf002";
case "Notifications": return "\uf0f3";
}
}
function addToolbutton(buttontype){
var component = Qt.createComponent("qrc:/qml/newsqml/NewsTabbutton.qml");
var tabcomp = component.createObject(newstabbar,{"buttontype":buttontype});
newstabbar.addItem(tabcomp);
}
// CalendarTab{
// visible: wideScreen&&rootstackView.depth<2
// width: newstabitem.width/3
// x: newsSwipeview.width
// //anchors.left: newsSwipeview.right
// //anchors.fill: null
// }
// Rectangle{
// color: "#F8F8F8"
// height: parent.height
// width: 0.5*mm
// anchors.left: newsSwipeview.right
// }
//MessageSend{}
BlueButton{
z:2
anchors.right: parent.right
visible: !wideScreen
fontColor: "grey"
border.color: "transparent"
text: "\uf0c9"
font.pointSize: osSettings.bigFontSize
onClicked:{
leftDrawerAndroid.visible?leftDrawerAndroid.close():leftDrawerAndroid.open()}
}
MButton{
z:2
anchors.right: parent.right
anchors.bottom: parent.bottom
// fontColor: "grey"
// border.color: "transparent"
text: "\uf040"
font.pointSize: osSettings.bigFontSize
onClicked:{
if (newsSwipeview.stacktype=="DirectMessages"){openMessageSend("directmessage","")}
else {openMessageSend("active","")}
}
}
LeftDrawerLinux{
id:leftDrawer
property var newstabstatus: newstab.newstabstatus
visible: wideScreen&&rootstackView.depth<2
width: visible?root.fontFactor*osSettings.systemFontSize*15:0
height: root.height-bar.height
}
LeftDrawerAndroid{
id: leftDrawerAndroid
}
TabBar {
id: newstabbar
x: leftDrawer.width
width: newsSwipeview.width
height: contentHeight+2
spacing: 1
position: TabBar.Header
onCurrentIndexChanged: {
newsSwipeview.currentIndex=newstabbar.currentIndex;
}
clip: true
}
SwipeView{
id: newsSwipeview
property string stacktype:"Home"
currentIndex: 0
width: wideScreen&&rootstackView.depth<2?newstabitem.width-leftDrawer.width:newstabitem.width//newstabitem.width/3*2:newstabitem.width
height: newstabitem.height-newstabbar.height
x: leftDrawer.width
y: newstabbar.height
function onDirectMessage(friend){currentIndex=2}
onCurrentIndexChanged: {
if(newstypes[currentIndex]){stacktype=newstypes[currentIndex]}
else{stacktype="Home"}
}
Loader{
source:(newsSwipeview.currentIndex==0)? "qrc:/qml/newsqml/NewsStack.qml":""
}
Loader{
source:(newsSwipeview.currentIndex==1)? "qrc:/qml/newsqml/NewsStack.qml":""
}
Loader{
//property var friend:({})
source:(newsSwipeview.currentIndex==2)? "qrc:/qml/newsqml/NewsStack.qml":""
}
Loader{
source:(newsSwipeview.currentIndex==3)? "qrc:/qml/newsqml/NewsStack.qml":""
}
}
PageIndicator {
id: swipeIndicator
z:5
height: root.fontFactor*osSettings.bigFontSize
font.pointSize: osSettings.systemFontSize
count: newsSwipeview.count
currentIndex: newsSwipeview.currentIndex
anchors.bottom: newsSwipeview.bottom
anchors.horizontalCenter: parent.horizontalCenter
}
Connections{
target: root
function onGlobaloptionsChanged(){
newstypes=globaloptions.defaultNewsTypes;
while (newstabbar.count>0){
newstabbar.removeItem(newstabbar.contentData[0]);
}
for (let view in newstypes){
addToolbutton(newstypes[view])
}
}
}
Component.onCompleted: {
root.directmessageSignal.connect(newsSwipeview.onDirectMessage)
}
}