// This file is part of Friendiqa // https://github.com/lubuwest/Friendiqa // Copyright (C) 2017 Marco R. // // 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 . import QtQuick 2.0 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.4 import QtQuick.Dialogs 1.3 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 Item { Connections{ target:newstab onNewstabstatusChanged:{ newstabstatusButton.text= qsTr(newstab.newstabstatus) // switch(newstab.newstabstatus){ // case "Timeline": newstabstatusCombo.currentIndex=1; break; // case "Conversations":newstabstatusCombo.currentIndex=2; break; // case "Favorites":newstabstatusCombo.currentIndex=3; break; // case "Network":newstabstatusCombo.currentIndex=4; break; // case "Direct Messages":newstabstatusCombo.currentIndex=5; break; // case "Notifications":newstabstatusCombo.currentIndex=6; break; // case "Search":newstabstatusCombo.currentIndex=7; break; // case "Groupnews":newstabstatusCombo.currentIndex=8; break; // } } } Connections{ target:xhr onError:{ Helperjs.showMessage(qsTr("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: { if(newstab.newstabstatus=="Conversation"){ showConversation(newsStack.timelineIndex-1,newsModel.get(0).newsitemobject)} else{ Service.updateView(newstab.newstabstatus) root.contactLoadType="news"; } } } Timer {id:contacttimer; interval: 50; running: false; repeat: false onTriggered: { // downloadNotice.text=downloadNotice.text + "\n contactTimer start "+ Date.now() root.newContacts=Newsjs.findNewContacts(root.news,root.contactlist); Newsjs.storeNews(login,db,root.news,root) } } 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 "+newsStack.appendNews +JSON.stringify(newsToShow)) var msg = {'currentTime': currentTime, 'model': newsModel,'news':newsToShow,'appendnews':newsStack.appendNews}; newsWorker.sendMessage(msg); newsStack.appendNews=false } function showConversation(conversationIndex,newsitemobject){ //newsBusy.running=true; root.contactLoadType="conversation"; newsStack.conversationIndex= conversationIndex; //print(newsitemobject.id); if(newsitemobject.messagetype==0){ xhr.clearParams(); xhr.setLogin(login.username+":"+Qt.atob(login.password)); xhr.setUrl(login.server); xhr.setApi("/api/conversation/show"); xhr.setParam("id",newsitemobject.id) xhr.get(); } else{ xhr.clearParams(); xhr.setLogin(login.username+":"+Qt.atob(login.password)); xhr.setUrl(login.server); xhr.setApi("/api/direct_messages/conversation"); xhr.setParam("uri",newsitemobject.statusnet_conversation_id) xhr.get(); } } function showContact(contact){ var component = Qt.createComponent("qrc:/qml/contactqml/ContactDetailsComponent.qml"); if (component.status== Component.Ready){ var contactDetails = component.createObject(newstab,{"contact": contact}) } } function search(term){//print("Search "+term) if (term!=""){ newstab.newstabstatus="Search"; newsBusy.running=true; xhr.setLogin(login.username+":"+Qt.atob(login.password)); xhr.setUrl(login.server); xhr.setApi("/api/search"); xhr.clearParams(); xhr.setParam("q",term) xhr.get();} newsSearch.visible=false; newsView.anchors.topMargin=7*mm } function onFriendsMessages(friend){ newstab.newstabstatus="Contact" Newsjs.newsfromdb(db,root.login.username, function(dbnews){ if (dbnews.length==0){ Newsjs.newsfromdb(db,login.username,function(forumnews){ showNews(forumnews) },friend.url) } else showNews(dbnews) },friend.id) } function onDirectMessage(friend){ newstab.newstabstatus="SendMessage" newsStack.push({item:"qrc:/qml/newsqml/MessageSend.qml",properties:{"reply_to_user": friend,"directmessage":1,"login":root.login}}); } function sendUrls(urls){ if((urls.length==1)&&(newsStack.depth<2)){ newsStack.push([newslistRectangle,{item:"qrc:/qml/newsqml/MessageSend.qml",properties:{attachImageURLs:urls}}]) } } function sendtext(text){ if(text&&(newsStack.depth<2)){ if (text.subject=="undefined"){text.subject=""} newsStack.push([newslistRectangle,{item:"qrc:/qml/newsqml/MessageSend.qml",properties:{bodyMessage:text.subject+"\n"+text.plaintext}}]) } } StackView{ id: newsStack anchors.fill:parent property int conversationIndex: 0 property bool appendNews: false property var allchats: ({}) initialItem:Rectangle { id:newslistRectangle y:1 color: "white" // ComboBox{ // id:newstabstatusCombo // anchors.top: parent.top // anchors.topMargin: 0.5*mm // width: 1/3*root.width // height: 5*mm; // style: // ComboBoxStyle{ // background: Rectangle { // color:"light blue" // radius: 0.5*mm // } // label: Text { // verticalAlignment: Text.AlignVCenter // horizontalAlignment: Text.AlignHCenter // text: control.currentText // } // } // model: ListModel { // id: newscomboItems // ListElement { type: "Timeline"; text: qsTr("Timeline")} // ListElement { type: "Conversations";text: qsTr("Conversations")} // ListElement { type: "Favorites";text: qsTr("Favorites") } // ListElement { type: "PublicTimeline";text: qsTr("Public timeline") } // ListElement { type: "DirectMessages";text: qsTr("Direct Messages") } // ListElement { type: "Notifications";text: qsTr("Notifications") } // ListElement { type: "Search";text: qsTr("Search") } // ListElement { type: "Groupnews"; text: qsTr("Group News") } // ListElement { type: "Quit";text: qsTr("Quit") } // } // currentIndex:(login.newsViewType=="Timeline")?0:1 // onCurrentIndexChanged:{ // //onActivated:{ // print(newscomboItems.get(currentIndex).type); // switch(newscomboItems.get(currentIndex).type){ // case "Timeline": // newstab.newstabstatus="Timeline"; // newsModel.clear(); // try{ Newsjs.newsfromdb(root.db,root.login.username, function(dbnews){ // showNews(dbnews) // })}catch(e){Helperjs.showMessage("Error",e,root)} // break; // case "Conversations": // newsModel.clear(); // newstab.newstabstatus="Conversations"; // Newsjs.chatsfromdb(db,root.login.username,function(news){showNews(news)}) // break; // case "Favorites": // newstab.newstabstatus="Favorites"; // root.contactLoadType="favorites"; // Service.updateView("Favorites"); // break; // case "PublicTimeline": // newstab.newstabstatus="Network"; // Service.updateView("Network"); // break; // case "DirectMessages": // newstab.newstabstatus="DirectMessages"; // Service.updateView("DirectMessages"); // break; // case "Notifications": // newstab.newstabstatus="Notifications"; // Service.updateView("Notifications"); // break; // case "Search": // newsView.anchors.topMargin=18*mm; // newsSearch.visible=true // break; // case "Groupnews": // Service.showGroups(); // break; // case "Quit": // Service.cleanNews(root.db,function(){ // Service.cleanContacts(root.login,root.db,function(){ // Qt.quit()}) // }) // } // } // } BlueButton{ id:newstabstatusButton anchors.top: parent.top anchors.topMargin: 0.5*mm text: qsTr(newstab.newstabstatus) onClicked: {newstabmenu.popup()} Menu{id:newstabmenu MenuItem { text: qsTr("Timeline") onTriggered: { newstab.newstabstatus="Timeline"; newsModel.clear(); try{ Newsjs.newsfromdb(root.db,root.login.username, function(dbnews){ showNews(dbnews) })}catch(e){Helperjs.showMessage("Error",e,root)}} } MenuItem { text: qsTr("Conversations") onTriggered:{ newsModel.clear(); newstab.newstabstatus="Conversations"; Newsjs.chatsfromdb(db,root.login.username,function(news){showNews(news)}) } } MenuItem { text: qsTr("Favorites") onTriggered:{ newstab.newstabstatus="Favorites"; // root.contactLoadType="favorites"; Service.updateView("Favorites") } } MenuItem { text: qsTr("Public timeline") onTriggered:{ newstab.newstabstatus="Public Timeline"; Service.updateView("Public Timeline") } } MenuItem { text: qsTr("Direct Messages") onTriggered:{ newstab.newstabstatus="Direct Messages"; Service.updateView("Direct Messages") } } MenuItem { text: qsTr("Notifications") onTriggered:{ newstab.newstabstatus="Notifications"; Service.updateView("Notifications") } } MenuItem { text: qsTr("Group news") onTriggered:Service.showGroups(); } MenuItem { 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 BlueButton { id: searchButton text: "\uf002" onClicked: { if (newsSearch.visible==false){ newsView.anchors.topMargin=18*mm; newsSearch.visible=true} else{ newsSearch.visible=false; newsView.anchors.topMargin=7*mm; } } } BlueButton { id: newMessageButton text: "\uf040" 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({item:"qrc:/qml/newsqml/MessageSend.qml",properties:{"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() }) // })} // } BlueButton { id: update text: "\uf021" onClicked: { root.contactLoadType="news"; Service.updateView(newstab.newstabstatus) } } } 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; if(newstab.newstabstatus=="Timeline"){ Newsjs.newsfromdb(root.db,root.login.username, function(news){ var msg = {'currentTime': currentTime, 'model': newsModel,'news':news,'appendnews':true}; newsWorker.sendMessage(msg); },false,lastnews_id)} if(newstab.newstabstatus=="Conversations"){ Newsjs.chatsfromdb(root.db,root.login.username, function(news){ var msg = {'currentTime': currentTime, 'model': newsModel,'news':news,'appendnews':true}; newsWorker.sendMessage(msg); },lastnews_id)} else if(newstab.newstabstatus=="Contact"){ Newsjs.newsfromdb(root.db,root.login.username, 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() }} } } } Rectangle{ id: newsSearch color: "#FFFAFA" y:8*mm width:root.width height: 8*mm visible:false Search{ anchors.fill: parent anchors.margins: mm } } ListView { id: newsView anchors.fill: parent anchors.topMargin: 7*root.mm anchors.leftMargin: 3*root.mm; anchors.rightMargin: root.mm anchors.bottomMargin: 1*root.mm clip: true spacing: 0 footer: footerComponent model: newsModel delegate: Newsitem{} //onContentYChanged:{if(contentY<-8*mm&&contentY>(-8*mm-1)){print("refreshing"); onDragEnded:{if(contentY<-5*mm){//print("refreshing"); root.contactLoadType="news"; var onlynew=true; Service.updateView(newstab.newstabstatus) }} } ListModel{id: newsModel} WorkerScript { id: newsWorker source: "qrc:/js/newsworker.js" } BusyIndicator{ id: newsBusy anchors.horizontalCenter: newsView.horizontalCenter anchors.top:newsView.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: newsView.horizontalCenter anchors.bottom:newsView.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: { root.messageSignal.connect(onFriendsMessages); root.directmessageSignal.connect(onDirectMessage); root.newsSignal.connect(showNews); root.uploadSignal.connect(sendUrls); root.sendtextSignal.connect(sendtext); try{newsModel.clear()} catch(e){} xhr.setLogin(login.username+":"+Qt.atob(login.password)); xhr.setUrl(login.server); if(root.news.length>0){showNews(root.news)} else{ newstab.newstabstatus=login.newsViewType; if(login.newsViewType=="Timeline"){Newsjs.newsfromdb(db,login.username,function(dbnews){showNews(dbnews)})} else{Newsjs.chatsfromdb(db,login.username,function(dbnews){showNews(dbnews)})} } } } } }