v.0.5
This commit is contained in:
parent
63dfb9b197
commit
d48847d183
135 changed files with 8879 additions and 3693 deletions
579
source-linux/qml/newsqml/NewsStack.qml
Normal file
579
source-linux/qml/newsqml/NewsStack.qml
Normal file
|
@ -0,0 +1,579 @@
|
|||
// This file is part of Friendiqa
|
||||
// https://git.friendi.ca/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.11
|
||||
import QtQuick.Controls 2.4
|
||||
import "qrc:/js/news.js" as Newsjs
|
||||
import "qrc:/js/helper.js" as Helperjs
|
||||
import "qrc:/js/service.js" as Service
|
||||
|
||||
StackView{
|
||||
id: newsStack
|
||||
anchors.fill: parent
|
||||
property string updateMethodNews: "refresh"
|
||||
property var allchats: ({})
|
||||
signal replySignal(var newsobject)
|
||||
property int lastnewsid:0
|
||||
|
||||
function newstypeHandling(newstype){
|
||||
newsBusy.running=true;
|
||||
replySignal("");
|
||||
//messagesend.state="";
|
||||
newsModel.clear();
|
||||
switch(newstype){
|
||||
case "timeline":
|
||||
newstab.newstabstatus="Timeline";
|
||||
try{ Newsjs.newsfromdb(root.db,root.login,0, function(dbnews,lastid){
|
||||
lastnewsid=lastid;
|
||||
showNews(dbnews)
|
||||
})}catch(e){Helperjs.showMessage("Error",e,root)};
|
||||
break;
|
||||
case "conversation":
|
||||
newstab.newstabstatus="Conversations";
|
||||
Newsjs.chatsfromdb(root.db,root.login,0,function(news,lastid){
|
||||
lastnewsid=lastid;
|
||||
showNews(news)});
|
||||
break;
|
||||
case "favorites":
|
||||
newsStack.updateMethodNews="refresh";
|
||||
newstab.newstabstatus="Favorites";
|
||||
Service.updateView("Favorites");
|
||||
break;
|
||||
case "replies":
|
||||
newsStack.updateMethodNews="refresh";
|
||||
newstab.newstabstatus="Replies";
|
||||
Service.updateView("Replies");
|
||||
break;
|
||||
case "publictimeline":
|
||||
newsStack.updateMethodNews="refresh";
|
||||
newstab.newstabstatus="Public Timeline";
|
||||
Service.updateView("Public Timeline");
|
||||
break;
|
||||
case "groupnews":
|
||||
newsStack.updateMethodNews="refresh";
|
||||
Service.showGroups();
|
||||
break;
|
||||
case "search":
|
||||
newsView.anchors.topMargin=7*mm;
|
||||
newsBusy.running=false;
|
||||
var component = Qt.createComponent("qrc:/qml/genericqml/Search.qml");
|
||||
var searchItem = component.createObject(newsStack,{y:mm,width:root.width,height: 5*mm});
|
||||
break;
|
||||
case "refresh":
|
||||
if (newstab.newstabstatus=="Timeline"){
|
||||
newsStack.updateMethodNews="append"
|
||||
} else {newsStack.updateMethodNews="refresh"}
|
||||
//root.contactLoadType="news";
|
||||
if (newsSwipeview.stacktype=="Home"){
|
||||
Service.updateView(newstab.newstabstatus)
|
||||
}
|
||||
else if (newsSwipeview.stacktype=="DirectMessage"){
|
||||
Service.updateView("Direct Messages")
|
||||
}
|
||||
else if (newsSwipeview.stacktype=="Notifications"){
|
||||
Service.updateView("Notifications")
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (newstab.newstabstatus=="Timeline"){
|
||||
newsStack.updateMethodNews="append"
|
||||
} else {newsStack.updateMethodNews="refresh"}
|
||||
//root.contactLoadType="news";
|
||||
if (newsSwipeview.stacktype=="Home"){
|
||||
Service.updateView(newstab.newstabstatus)
|
||||
}
|
||||
else if (newsSwipeview.stacktype=="Directmessage"){
|
||||
Service.updateView("Direct Messages")
|
||||
}
|
||||
else if (newsSwipeview.stacktype=="Notifications"){
|
||||
Service.updateView("Notifications")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function showNews(newsToShow){
|
||||
try{
|
||||
if (newsStack.depth>1){newsStack.pop()}
|
||||
}catch(e){}
|
||||
newsBusy.running=false;
|
||||
var currentTime= new Date();
|
||||
// downloadNotice.text=downloadNotice.text + "\n shownews start "+ Date.now();
|
||||
//print("appendnews "+JSON.stringify(newsToShow))
|
||||
var msg = {'currentTime': currentTime, 'model': newsModel,'news':newsToShow,'method':newsStack.updateMethodNews, 'options':globaloptions};
|
||||
newsWorker.sendMessage(msg);
|
||||
//newsStack.appendNews=false
|
||||
}
|
||||
|
||||
function showContact(contact){ //print(JSON.stringify(contact));
|
||||
//newstab.newstabstatus="Contact";
|
||||
newsStack.push("qrc:/qml/newsqml/ContactPage.qml",{"contact": contact});
|
||||
}
|
||||
|
||||
function search(term){//print("Search "+term)
|
||||
if (term!=""){
|
||||
newstab.newstabstatus="Search";
|
||||
newsBusy.running=true;
|
||||
newsStack.updateMethodNews="refresh";
|
||||
xhr.setLogin(login.username+":"+Qt.atob(login.password));
|
||||
xhr.setUrl(login.server);
|
||||
xhr.setApi("/api/search");
|
||||
xhr.clearParams();
|
||||
xhr.setParam("q",term)
|
||||
xhr.get();}
|
||||
newsView.anchors.topMargin=mm
|
||||
}
|
||||
|
||||
Connections{
|
||||
target:xhr
|
||||
onError:{
|
||||
Helperjs.showMessage(qsTr("Network Error"),"API:\n" +login.server+api+"\n Return: \n"+data,root);
|
||||
}
|
||||
onSuccess:{
|
||||
// downloadNotice.text=downloadNotice.text+ "\n xhr finished "+Date.now();
|
||||
Service.processNews(api,data);
|
||||
}
|
||||
}
|
||||
|
||||
Timer {id:replytimer; interval: 1000; running: false; repeat: false
|
||||
onTriggered: {
|
||||
newsBusy.running=true;
|
||||
if(newstab.newstabstatus=="Conversation"){
|
||||
showConversation(newsStack.timelineIndex-1,newsModel.get(0).newsitemobject)}
|
||||
else{
|
||||
if (newstab.newstabstatus=="Timeline"){
|
||||
newsStack.updateMethodNews="append"
|
||||
} else {newsStack.updateMethodNews="refresh"}
|
||||
if (newsSwipeview.stacktype=="Home"){
|
||||
Service.updateView(newstab.newstabstatus)
|
||||
}
|
||||
else if (newsSwipeview.stacktype=="DirectMessages"){
|
||||
Service.updateView("Direct Messages")
|
||||
}
|
||||
else if (newsSwipeview.stacktype=="Replies"){
|
||||
Service.updateView("Replies")
|
||||
}
|
||||
replySignal("")
|
||||
//Service.updateView(newstab.newstabstatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
initialItem: Rectangle {
|
||||
id:newslistRectangle
|
||||
y:1
|
||||
color: "white"
|
||||
|
||||
// Button{
|
||||
// id:newstabstatusButton
|
||||
// anchors.top: parent.top
|
||||
// anchors.topMargin: 0.5*mm
|
||||
// height: 8*mm
|
||||
// text: qsTr(newstab.newstabstatus)
|
||||
// visible: newsStack.parent.stacktype=="standard"
|
||||
// onClicked: {print(newsStack.parent.stacktype);
|
||||
// newstabmenu.popup(2*mm,6*mm)
|
||||
// }
|
||||
|
||||
// Menu{id:newstabmenu
|
||||
// width: 40*mm
|
||||
|
||||
// delegate:MenuItem{
|
||||
// contentItem: Text{
|
||||
// font.pixelSize: 3.5*mm
|
||||
// text:parent.text
|
||||
// }
|
||||
// background: Rectangle {
|
||||
// implicitWidth: 40*mm; implicitHeight: 5*mm
|
||||
// color: "#ffffff"
|
||||
// border.color: "grey"
|
||||
// }
|
||||
// }
|
||||
// Action {
|
||||
// text: qsTr("Timeline")
|
||||
// onTriggered: {
|
||||
|
||||
// }
|
||||
// Action {
|
||||
// text: qsTr("Conversations")
|
||||
// onTriggered:{
|
||||
// //newsModel.clear();
|
||||
// newstab.newstabstatus="Conversations";
|
||||
// Newsjs.chatsfromdb(db,root.login,function(news){showNews(news)})
|
||||
// }
|
||||
// }
|
||||
// Action {
|
||||
// text: qsTr("Favorites")
|
||||
// onTriggered:{
|
||||
// newsStack.updateMethodNews="refresh";
|
||||
// newstab.newstabstatus="Favorites";
|
||||
// Service.updateView("Favorites")
|
||||
// }
|
||||
// }
|
||||
// Action {
|
||||
// text: qsTr("Replies")
|
||||
// onTriggered:{
|
||||
// newsStack.updateMethodNews="refresh";
|
||||
// newstab.newstabstatus="Replies";
|
||||
// Service.updateView("Replies")
|
||||
// }
|
||||
// }
|
||||
// Action {
|
||||
// text: qsTr("Public timeline")
|
||||
// onTriggered:{
|
||||
// newsStack.updateMethodNews="refresh";
|
||||
// newstab.newstabstatus="Public Timeline";
|
||||
// Service.updateView("Public Timeline")
|
||||
// }
|
||||
// }
|
||||
|
||||
//// Action {
|
||||
//// text: qsTr("Direct Messages")
|
||||
//// onTriggered:{
|
||||
//// newsStack.updateMethodNews="refresh";
|
||||
//// newstab.newstabstatus="Direct Messages";
|
||||
//// Service.updateView("Direct Messages")
|
||||
//// }
|
||||
//// }
|
||||
//// Action {
|
||||
//// text: qsTr("Notifications")
|
||||
//// onTriggered:{
|
||||
//// newsStack.updateMethodNews="refresh";
|
||||
//// newstab.newstabstatus="Notifications";
|
||||
//// Service.updateView("Notifications")
|
||||
//// }
|
||||
//// }
|
||||
// Action {
|
||||
|
||||
// text: qsTr("Group news")
|
||||
// onTriggered:
|
||||
// {
|
||||
// newsStack.updateMethodNews="refresh";
|
||||
// Service.showGroups();
|
||||
// }
|
||||
// }
|
||||
// Action {
|
||||
|
||||
// text: qsTr("Settings")
|
||||
// onTriggered:
|
||||
// {
|
||||
// leftDrawer.open()
|
||||
// }
|
||||
// }
|
||||
|
||||
// Action {
|
||||
// text: qsTr("Quit")
|
||||
// onTriggered:{
|
||||
// Service.cleanNews(root.db,function(){
|
||||
// Service.cleanContacts(root.login,root.db,function(){
|
||||
// Qt.quit()})
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// Row{
|
||||
// spacing: mm
|
||||
// anchors.top: parent.top
|
||||
// anchors.topMargin: 0.5*mm
|
||||
// anchors.right: parent.right
|
||||
|
||||
// Button {
|
||||
// id: searchButton
|
||||
// height: 8*mm
|
||||
// text: "\uf002"
|
||||
// visible: newsStack.parent.stacktype=="standard"
|
||||
// onClicked: {
|
||||
// newsView.anchors.topMargin=18*mm;
|
||||
// var component = Qt.createComponent("qrc:/qml/genericqml/Search.qml");
|
||||
// var searchItem = component.createObject(newsStack,{y:8*mm,width:root.width,height: 8*mm});
|
||||
// }
|
||||
// }
|
||||
|
||||
// Button {
|
||||
// id: newMessageButton
|
||||
// text: "\uf040"
|
||||
// height: 8*mm
|
||||
// onClicked: {
|
||||
// var groups=[];
|
||||
// Helperjs.readData(root.db,"groups",root.login.username,function(groupobject){
|
||||
// groups=groupobject
|
||||
// });
|
||||
// newstab.newstabstatus="SendMessage";
|
||||
// Helperjs.readData(root.db,"contacts",root.login.username,function(friends){
|
||||
// newsStack.push("qrc:/qml/newsqml/MessageSend.qml",{"contacts": friends,"login":root.login})
|
||||
// },"isFriend",1);
|
||||
// }
|
||||
// }
|
||||
// BlueButton {
|
||||
// id: quitButton
|
||||
// text: "\uf08b"
|
||||
// onClicked: {Service.cleanNews(root.db,function(){
|
||||
// Service.cleanContacts(root.login,root.db,function(){
|
||||
// Qt.quit() })
|
||||
// })}
|
||||
// }
|
||||
// Button {
|
||||
// id: update
|
||||
// height: 8*mm
|
||||
// text: "\uf021"
|
||||
// onClicked: {
|
||||
// if (newstab.newstabstatus=="Timeline"){
|
||||
// newsStack.updateMethodNews="append"
|
||||
// } else {newsStack.updateMethodNews="refresh"}
|
||||
// //root.contactLoadType="news";
|
||||
// if (newsStack.parent.stacktype=="standard"){
|
||||
// Service.updateView(newstab.newstabstatus)
|
||||
// }
|
||||
// else if (newsStack.parent.stacktype=="directmessage"){
|
||||
// Service.updateView("Direct Messages")
|
||||
// }
|
||||
// else if (newsStack.parent.stacktype=="notifications"){
|
||||
// Service.updateView("Notifications")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
Component { id:footerComponent
|
||||
Rectangle{
|
||||
border.color: "#EEEEEE"
|
||||
border.width: 1
|
||||
width:newsView.width
|
||||
height:6*mm
|
||||
Text{
|
||||
font.pixelSize: 1.5*mm
|
||||
anchors.centerIn: parent
|
||||
text:qsTr("More")
|
||||
}
|
||||
MouseArea{anchors.fill:parent
|
||||
onClicked:{
|
||||
var currentTime= new Date();
|
||||
var lastnews_id=newsModel.get(newsModel.count-1).newsitemobject.created_at;
|
||||
var messagetype=0;
|
||||
switch(newsSwipeview.stacktype){
|
||||
case "Home":messagetype=0;break;
|
||||
case "DirectMessages": messagetype=1;break;
|
||||
case "Notifications":messagetype=2;break;
|
||||
case "Replies":messagetype=3;break;
|
||||
default:messagetype=0;
|
||||
}
|
||||
if(newstab.newstabstatus=="Timeline"){
|
||||
Newsjs.newsfromdb(root.db,root.login, messagetype,function(news){
|
||||
var msg = {'currentTime': currentTime, 'model': newsModel,'news':news,'appendnews':true, 'options':globaloptions};
|
||||
newsWorker.sendMessage(msg);
|
||||
},false,lastnews_id)}
|
||||
if(newstab.newstabstatus=="Conversations"){
|
||||
Newsjs.chatsfromdb(root.db,root.login, messagetype,function(news){
|
||||
var msg = {'currentTime': currentTime, 'model': newsModel,'news':news,'appendnews':true, 'options':globaloptions};
|
||||
newsWorker.sendMessage(msg);
|
||||
},lastnews_id)}
|
||||
// else if(newstab.newstabstatus=="Contact"){
|
||||
// Newsjs.newsfromdb(root.db,root.login, function(news){
|
||||
// var msg = {'currentTime': currentTime, 'model': newsModel,'news':news,'appendnews':true};
|
||||
// newsWorker.sendMessage(msg);
|
||||
// },newsModel.get(newsModel.count-1).newsitemobject.uid,lastnews_id)}
|
||||
else if (newstab.newstabstatus=="Notifications"){}
|
||||
else{
|
||||
//newsStack.appendNews=true;
|
||||
xhr.setParam("max_id",newsModel.get(newsModel.count-1).newsitemobject.id-1);
|
||||
xhr.get()
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Label{
|
||||
// text:qsTr(stacktype)
|
||||
// font.pixelSize: 3* mm
|
||||
// anchors.horizontalCenter: parent.horizontalCenter
|
||||
// anchors.margins: mm
|
||||
// }
|
||||
|
||||
ListView {
|
||||
id: newsView
|
||||
property real oldContentY:0
|
||||
property bool viewdragged: false
|
||||
anchors.fill: parent
|
||||
anchors.margins: mm
|
||||
//anchors.topMargin: 6*mm
|
||||
// anchors.leftMargin: mm; anchors.rightMargin: mm
|
||||
// anchors.bottomMargin: mm
|
||||
clip: true
|
||||
spacing: 0
|
||||
header: MessageSend{id:messagesend;onHeightChanged: newsView.positionViewAtBeginning()}
|
||||
footer: footerComponent
|
||||
model: newsModel
|
||||
delegate: Newsitem{}
|
||||
onDragStarted: oldContentY=contentY
|
||||
onDragEnded: {
|
||||
if(verticalOvershoot<-5*mm){
|
||||
viewdragged=true
|
||||
}
|
||||
else{
|
||||
if((contentY-oldContentY)>15*mm){
|
||||
swipeIndicator.visible=false;
|
||||
newsSwipeview.height=rootStackItem.height;
|
||||
newsSwipeview.y=0;
|
||||
rootStackItem.state="fullscreen"
|
||||
}
|
||||
else if ((contentY-oldContentY)<-15*mm){
|
||||
swipeIndicator.visible=true;
|
||||
newsSwipeview.height=rootStackItem.height-12*mm;
|
||||
newsSwipeview.y=5*mm;
|
||||
rootStackItem.state=""
|
||||
}
|
||||
}
|
||||
}
|
||||
onViewdraggedChanged: {
|
||||
if (viewdragged){
|
||||
var onlynew=true;
|
||||
newsBusy.running=true;
|
||||
if (newstab.newstabstatus=="Timeline"){
|
||||
newsStack.updateMethodNews="append"
|
||||
} else {newsStack.updateMethodNews="refresh"}
|
||||
//root.contactLoadType="news";
|
||||
if (newsSwipeview.stacktype=="Home"){
|
||||
Newsjs.getLastNews(root.login,root.db,function(currentlastnews){
|
||||
if (currentlastnews>lastnewsid){
|
||||
if(newstab.newstabstatus=="Timeline"){
|
||||
try{ Newsjs.newsfromdb(root.db,root.login,0, function(dbnews,lastid){
|
||||
lastnewsid=lastid;
|
||||
showNews(dbnews)
|
||||
})}catch(e){Helperjs.showMessage("Error",e,root)};
|
||||
}
|
||||
if(newstab.newstabstatus=="Conversations"){
|
||||
Newsjs.chatsfromdb(db,root.login,0,function(news,lastid){
|
||||
lastnewsid=lastid;
|
||||
showNews(news)});
|
||||
}
|
||||
} else {
|
||||
Service.updateView(newstab.newstabstatus)
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (newsSwipeview.stacktype=="DirectMessages"){
|
||||
Service.updateView("Direct Messages")
|
||||
}
|
||||
else if (newsSwipeview.stacktype=="Notifications"){
|
||||
Service.updateView("Notifications")
|
||||
}
|
||||
else if (newsSwipeview.stacktype=="Replies"){
|
||||
Service.updateView("Replies")
|
||||
}
|
||||
viewdragged=false
|
||||
}}
|
||||
}
|
||||
|
||||
ListModel{id: newsModel}
|
||||
|
||||
WorkerScript {
|
||||
id: newsWorker
|
||||
source: "qrc:/js/newsworker.js"
|
||||
}
|
||||
|
||||
BusyIndicator{
|
||||
id: newsBusy
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top:parent.top
|
||||
anchors.topMargin: 2*mm
|
||||
width:10*mm
|
||||
height: 10*mm
|
||||
}
|
||||
Rectangle{
|
||||
id:downloadNotice
|
||||
property alias text: noticeText.text
|
||||
color:"white"
|
||||
border.color:"grey"
|
||||
z:1
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.bottom:parent.bottom
|
||||
anchors.bottomMargin: 2*mm
|
||||
width: noticeText.width+2*mm
|
||||
height: noticeText.height+2*mm
|
||||
visible: (downloadNotice.text!="")
|
||||
|
||||
Text{
|
||||
id:noticeText
|
||||
color: "grey"
|
||||
anchors.centerIn: parent
|
||||
width: contentWidth
|
||||
height: contentHeight
|
||||
font.pixelSize: 2*mm
|
||||
text:""
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
//print(newsSwipeview.stacktype);
|
||||
root.newstypeSignal.connect(newstypeHandling);
|
||||
root.messageSignal.connect(onFriendsMessages);
|
||||
root.contactdetailsSignal.connect(showContact);
|
||||
root.newsSignal.connect(showNews);
|
||||
|
||||
try{newsModel.clear()} catch(e){}
|
||||
swipeIndicator.visible=true;
|
||||
newsSwipeview.height=rootStackItem.height-12*mm;
|
||||
newsSwipeview.y=5*mm;
|
||||
rootStackItem.state=""
|
||||
|
||||
// xhr.setLogin(login.username+":"+Qt.atob(login.password));
|
||||
// xhr.setUrl(login.server);
|
||||
// if((newsStack.parent.stacktype=="standard") && (root.news.length>0)){
|
||||
// showNews(root.news)
|
||||
// }
|
||||
//else{
|
||||
newstab.newstabstatus=login.newsViewType;
|
||||
var messagetype=0;
|
||||
switch(newsSwipeview.stacktype){
|
||||
case "Home":messagetype=0;break;
|
||||
case "DirectMessages": messagetype=1;break;
|
||||
case "Notifications":messagetype=2;break;
|
||||
case "Replies":messagetype=3;break;
|
||||
default:messagetype=0;
|
||||
}
|
||||
if((login.newsViewType=="Conversations")&&(newsSwipeview.stacktype=="Home")){
|
||||
Newsjs.chatsfromdb(db,login,messagetype,function(dbnews,lastid){
|
||||
lastnewsid=lastid;
|
||||
showNews(dbnews);
|
||||
})
|
||||
}
|
||||
else{Newsjs.newsfromdb(db,login,messagetype,function(dbnews,lastid){
|
||||
lastnewsid=lastid;
|
||||
showNews(dbnews)
|
||||
})}
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue