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
2020-05-24 21:14:23 +02:00
// Copyright (C) 2020 Marco R. <thomasschmidt45@gmx.net>
2018-02-19 22:36:00 +01:00
//
// 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/>.
2024-04-05 19:28:47 +02:00
import QtQuick 6.3
2023-07-27 21:52:16 +02:00
import QtQuick . Controls 6.3
2019-06-25 20:59:10 +02:00
import "qrc:/qml/newsqml"
2021-05-12 21:41:34 +02:00
import "qrc:/qml/genericqml"
2017-01-26 21:55:31 +01:00
import "qrc:/js/news.js" as Newsjs
import "qrc:/js/helper.js" as Helperjs
import "qrc:/js/service.js" as Service
2023-07-27 21:52:16 +02:00
Page {
2021-05-12 21:41:34 +02:00
id:newstabitem
2021-05-18 21:01:32 +02:00
width: rootstack . width
2023-07-27 21:52:16 +02:00
height: rootstack . height
2023-11-04 18:04:55 +01:00
property var newstypes: globaloptions . hasOwnProperty ( "defaultNewsTypes" ) ? globaloptions.defaultNewsTypes: [ "Home" , "Replies" , "DirectMessages" , "Notifications" ]
2024-04-05 19:28:47 +02:00
property bool expectScreenUpdate: false
2017-03-25 23:36:14 +01:00
2018-07-01 15:09:21 +02:00
Timer { id:contacttimer ; interval: 50 ; running: false ; repeat: false
2019-12-10 21:12:32 +01:00
onTriggered: {
2018-07-01 15:09:21 +02:00
root . newContacts = Newsjs . findNewContacts ( root . news , root . contactlist ) ;
2021-05-12 21:41:34 +02:00
root . onNewContactsChanged ( root . newContacts ) ;
2018-07-01 15:09:21 +02:00
Newsjs . storeNews ( login , db , root . news , root )
}
}
2017-05-11 22:15:34 +02:00
function showConversation ( conversationIndex , newsitemobject ) {
2019-06-25 20:59:10 +02:00
if ( newsitemobject . messagetype == 0 || newsitemobject . messagetype == 3 ) {
2023-05-24 21:40:26 +02:00
xhr . setAccount ( login ) ;
2018-07-01 15:09:21 +02:00
xhr . setApi ( "/api/conversation/show" ) ;
xhr . setParam ( "id" , newsitemobject . id )
2021-05-12 21:41:34 +02:00
xhr . setParam ( "count" , "200" )
2018-07-01 15:09:21 +02:00
xhr . get ( ) ;
}
else {
2023-05-24 21:40:26 +02:00
xhr . setAccount ( login ) ;
2018-07-01 15:09:21 +02:00
xhr . setApi ( "/api/direct_messages/conversation" ) ;
xhr . setParam ( "uri" , newsitemobject . statusnet_conversation_id )
xhr . get ( ) ;
}
2017-03-25 23:36:14 +01:00
}
2020-05-24 21:14:23 +02:00
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' ) ) {
2023-07-27 21:52:16 +02:00
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);
2020-05-24 21:14:23 +02:00
} } catch ( e ) { print ( "Activities " + e + " " + JSON . stringify ( newsitemobject . friendica_activities ) ) }
return { likeText: likeText , dislikeText: dislikeText , attendyesText: attendyesText , attendnoText: attendnoText , attendmaybeText: attendmaybeText }
}
2023-07-27 21:52:16 +02:00
function openMessageSend ( messageState , newsitemobject ) {
var parentId = ""
var replyUser = ""
if ( newsitemobject != "" ) {
parentId = newsitemobject . id
replyUser = newsitemobject . user . screen_name ;
}
2024-04-05 19:28:47 +02:00
// var messageString='import qtquick 6.3; 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");
2023-07-27 21:52:16 +02:00
var messageObject = Qt . createComponent ( "qrc:/qml/newsqml/MessageSend.qml" ) ;
var messageWindow = messageObject . createObject ( root , { parentId: parentId , reply_to_user: replyUser , windowstate: messageState } ) ;
messageWindow . show ( ) ;
}
2024-04-05 19:28:47 +02:00
// 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";
// }
// }
2023-11-04 18:04:55 +01:00
function getIcon ( typerequest ) {
switch ( typerequest ) {
2024-04-05 19:28:47 +02:00
case "Home" : return { iconName: "user-home-symbolic" , iconUrl: "qrc:/assets/icons/home.svg" } ;
case "Favorites" : return { iconName: "starred-symbolic" , iconUrl: "qrc:/assets/icons/star.svg" } ;
2024-04-15 17:24:30 +02:00
case "Replies" : return { iconName: "mail-reply-all-symbolic" , iconUrl: "qrc:/assets/icons/exchange.svg" } ;
2024-04-05 19:28:47 +02:00
case "DirectMessages" : return { iconName: "mail-message" , iconUrl: "qrc:/assets/icons/envelope.svg" } ;
case "Public Timeline" : return { iconName: "globe" , iconUrl: "qrc:/assets/icons/globe.svg" } ;
case "Group News" : return { iconName: "group" , iconUrl: "qrc:/assets/icons/users.svg" } ;
2024-04-15 17:24:30 +02:00
case "Search" : return { iconName: "system-search" , iconUrl: "qrc:/assets/icons/search.svg" } ;
2024-04-05 19:28:47 +02:00
case "Notifications" : return { iconName: "notifications" , iconUrl: "qrc:/assets/icons/bell.svg" } ;
2023-11-04 18:04:55 +01:00
}
}
function addToolbutton ( buttontype ) {
var component = Qt . createComponent ( "qrc:/qml/newsqml/NewsTabbutton.qml" ) ;
2024-04-05 19:28:47 +02:00
var tabcomp = component . createObject ( newstabbar , { buttontype: buttontype , "buttonIcon" : getIcon ( buttontype ) } ) ;
2023-11-04 18:04:55 +01:00
newstabbar . addItem ( tabcomp ) ;
}
2023-07-27 21:52:16 +02:00
// 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
// }
2018-07-01 15:09:21 +02:00
2023-11-04 18:04:55 +01:00
//MessageSend{}
2021-05-12 21:41:34 +02:00
2024-04-05 19:28:47 +02:00
//BlueButton{
2017-01-26 21:55:31 +01:00
2023-07-27 21:52:16 +02:00
MButton {
z: 2
anchors.right: parent . right
2024-04-05 19:28:47 +02:00
anchors.bottom: newsSwipeview . bottom
2023-07-27 21:52:16 +02:00
// fontColor: "grey"
// border.color: "transparent"
2024-04-15 17:24:30 +02:00
icon.name: "document-edit-symbolic" //"open-for-editing"
2024-04-05 19:28:47 +02:00
//text: "o \uf040"
//implicitHeight: root.fontFactor*osSettings.bigFontSize
2023-07-27 21:52:16 +02:00
onClicked: {
if ( newsSwipeview . stacktype == "DirectMessages" ) { openMessageSend ( "directmessage" , "" ) }
else { openMessageSend ( "active" , "" ) }
}
}
2021-05-12 21:41:34 +02:00
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
2018-04-22 21:12:40 +02:00
}
2021-05-12 21:41:34 +02:00
LeftDrawerAndroid {
id: leftDrawerAndroid
2018-04-11 21:50:43 +02:00
}
2021-05-12 21:41:34 +02:00
2023-07-27 21:52:16 +02:00
TabBar {
id: newstabbar
x: leftDrawer . width
width: newsSwipeview . width
2023-11-04 18:04:55 +01:00
height: contentHeight + 2
2023-07-27 21:52:16 +02:00
spacing: 1
position: TabBar . Header
onCurrentIndexChanged: {
newsSwipeview . currentIndex = newstabbar . currentIndex ;
}
2023-11-04 18:04:55 +01:00
clip: true
2023-07-27 21:52:16 +02:00
}
2019-06-25 20:59:10 +02:00
SwipeView {
id: newsSwipeview
property string stacktype: "Home"
2021-05-18 21:01:32 +02:00
width: wideScreen && rootstackView . depth < 2 ? newstabitem . width - leftDrawer.width: newstabitem . width //newstabitem.width/3*2:newstabitem.width
2024-04-05 19:28:47 +02:00
height: newstabitem . height - ( newstabbar . height + root . fontFactor * osSettings . systemFontSize )
2021-05-12 21:41:34 +02:00
x: leftDrawer . width
2023-07-27 21:52:16 +02:00
y: newstabbar . height
2024-04-15 17:24:30 +02:00
//function onDirectMessage(friend){currentIndex=2}
2017-01-26 21:55:31 +01:00
2019-06-25 20:59:10 +02:00
onCurrentIndexChanged: {
2023-11-04 18:04:55 +01:00
if ( newstypes [ currentIndex ] ) { stacktype = newstypes [ currentIndex ] }
else { stacktype = "Home" }
2024-04-15 17:24:30 +02:00
newstabbar . currentIndex = newsSwipeview . currentIndex ;
2017-01-26 21:55:31 +01:00
}
2021-05-12 21:41:34 +02:00
2019-06-25 20:59:10 +02:00
Loader {
source: ( newsSwipeview . currentIndex == 0 ) ? "qrc:/qml/newsqml/NewsStack.qml" : ""
2017-01-26 21:55:31 +01:00
}
2019-06-25 20:59:10 +02:00
Loader {
source: ( newsSwipeview . currentIndex == 1 ) ? "qrc:/qml/newsqml/NewsStack.qml" : ""
2017-01-26 21:55:31 +01:00
}
2019-06-25 20:59:10 +02:00
Loader {
source: ( newsSwipeview . currentIndex == 2 ) ? "qrc:/qml/newsqml/NewsStack.qml" : ""
2017-05-11 22:15:34 +02:00
}
2019-06-25 20:59:10 +02:00
Loader {
source: ( newsSwipeview . currentIndex == 3 ) ? "qrc:/qml/newsqml/NewsStack.qml" : ""
}
}
2023-05-31 20:47:17 +02:00
2024-04-05 19:28:47 +02:00
ToolButton {
z: 2
anchors.right: parent . right
anchors.top: parent . top
anchors.topMargin: newstabbar . height
visible: ! wideScreen
icon.name: "application-menu"
icon.source: "qrc:/assets/icons/bars.svg"
icon.width: root . fontFactor * osSettings . bigFontSize
icon.height: root . fontFactor * osSettings . bigFontSize
onClicked: {
leftDrawerAndroid . visible ? leftDrawerAndroid . close ( ) : leftDrawerAndroid . open ( ) }
}
2019-06-25 20:59:10 +02:00
PageIndicator {
id: swipeIndicator
2021-05-12 21:41:34 +02:00
z: 5
height: root . fontFactor * osSettings . bigFontSize
font.pointSize: osSettings . systemFontSize
2019-06-25 20:59:10 +02:00
count: newsSwipeview . count
currentIndex: newsSwipeview . currentIndex
anchors.bottom: newsSwipeview . bottom
anchors.horizontalCenter: parent . horizontalCenter
}
2017-01-26 21:55:31 +01:00
2023-11-04 18:04:55 +01:00
Connections {
2024-04-05 19:28:47 +02:00
target: root
function onGlobaloptionsChanged ( ) {
newstypes = globaloptions . defaultNewsTypes ;
while ( newstabbar . count > 0 ) {
newstabbar . removeItem ( newstabbar . contentData [ 0 ] ) ;
}
for ( let view in newstypes ) {
addToolbutton ( newstypes [ view ] )
}
2023-11-04 18:04:55 +01:00
}
2023-05-31 20:47:17 +02:00
}
2023-11-04 18:04:55 +01:00
Component.onCompleted: {
2024-04-15 17:24:30 +02:00
root . sendmessageSignal . connect ( openMessageSend ) ;
2024-04-05 19:28:47 +02:00
root . globaloptionsChanged ( ) ;
2023-11-04 18:04:55 +01:00
}
2017-01-26 21:55:31 +01:00
}