This commit is contained in:
LubuWest 2019-06-25 20:59:10 +02:00
commit d48847d183
135 changed files with 8879 additions and 3693 deletions

View file

@ -31,24 +31,28 @@
// message.qml
// message with buttons
import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick 2.4
import QtQuick.Controls 2.4
//import QtQuick.Dialogs 1.2
import "qrc:/js/helper.js" as Helperjs
import "qrc:/js/smiley.js" as Smileyjs
import "qrc:/js/news.js" as Newsjs
import "qrc:/qml/genericqml"
Rectangle{
color:"white"
// width:root.width-5*mm
// height:root.height-12*mm
//anchors.fill: parent
color:"#EEEEEE"
width:parent.width
height: (newsSwipeview.stacktype!="Notifications")?messageColumn.height+mm:0
id:messageSend
visible:(newsSwipeview.stacktype!="Notifications")?true:false
property string parentId: ""
//property var parentObject:({})
property bool conversation: false
property string reply_to_user:""
property alias bodyMessage: bodyField.text
property var attachImageURLs: [];
property int directmessage: 0;
//property int directmessage: 0;
property var contacts: []
property var groups: []
property var contact_allow:login.permissions[0]
@ -56,14 +60,48 @@ Rectangle{
property var group_allow:login.permissions[2]
property var group_deny:login.permissions[3]
function attachImage(url){ print("attachImage "+url)
onReply_to_userChanged: {
if (reply_to_user!=""){
receiverLabel.visible=true
}
}
function directmessagePrepare(friend){
messageSend.state="active";
reply_to_user=friend.screen_name;
receiverLabel.text=qsTr("to:")+ " "+ friend.screen_name;
}
function sendUrls(urls){
if((urls.length==1 && attachImageURLs.length==0)){
attachImage(urls);
attachImageURLs.push(urls);
messageSend.state="active";
}
}
function sendtext(text){
if(text){
if (text.subject=="undefined"){text.subject=""}
if(text.plaintext.lastIndexOf(".jpg")>-1 || text.plaintext.lastIndexOf(".jpeg")>-1 || text.plaintext.lastIndexOf(".png")>-1 || text.plaintext.lastIndexOf(".gif")>-1){
text.plaintext="<a href="+text.plaintext+"><img src="+text.plaintext+"></a>"}
bodyField.text=text.subject+"\n"+text.plaintext;
messageSend.state="active";
}
}
function attachImage(url){
var imageAttachmentObject=Qt.createQmlObject('import QtQuick 2.0; Image {id:imageAttachment'+attachImageURLs.length+'; source:"'+
url.toString()+'"; x:2*mm; width: 45*mm; height: 45*mm;fillMode: Image.PreserveAspectFit;MouseArea{anchors.fill:parent;onClicked:{attachImageURLs.splice(attachImageURLs.indexOf("'+
url+'"),1); imageAttachment'+attachImageURLs.length+'.destroy()}}}',messageColumn,"attachedImage");
}
}
function statusUpdate(title,status,in_reply_to_status_id,attachImageURL) {
//xhr.url= login.server + "/api/statuses/update.json";
newsBusy.running=true;
xhr.setLogin(login.username+":"+Qt.atob(login.password));
xhr.setUrl(login.server);
xhr.setApi("/api/statuses/update");
@ -81,6 +119,7 @@ Rectangle{
}
function dmUpdate(title,text,replyto,screen_name,attachImageURL) {
newsBusy.running=true;
//xhr.url= login.server + "/api/direct_messages/new.json";
xhr.setLogin(login.username+":"+Qt.atob(login.password));
xhr.setUrl(login.server);
@ -93,103 +132,193 @@ Rectangle{
xhr.post();
}
Flickable{
anchors.fill: parent
contentHeight: messageColumn.height
boundsBehavior: Flickable.StopAtBounds
id:messageSend
function setParent(newsitemobject){
//print("Newsobject "+newsitemobject.id+ " "+JSON.stringify(newsitemobject.user));
if (newsitemobject!=""){
messageSend.state="conversation"
reply_to_user=newsitemobject.user.screen_name;
receiverLabel.text=qsTr("to:")+ " "+ newsitemobject.user.screen_name;
parentId=newsitemobject.id
} else {
messageSend.state=""
reply_to_user="";
receiverLabel.text=qsTr("to:");
parentId="";
bodyField.text="";
attachImageURLs.pop();
try{imageAttachment.destroy()}catch(e){}
}
}
function contactmenu(letter){
Newsjs.listFriends(login,db,function(contacts){
var contactitems="";
for (var i=0;i<contacts.length;i++){
if(Helperjs.getCount(db,login,"contacts","screen_name",contacts[i].screen_name)>1){
contacts[i].screen_name=contacts[i].screen_name+"+"+contacts[i].cid
}
contactitems=contactitems+"MenuItem{text:'"+contacts[i].screen_name+
"'; onTriggered:{if (newsSwipeview.stacktype=='DirectMessages'){reply_to_user='"+
contacts[i].screen_name+"'} else {bodyField.insert("+
bodyField.cursorPosition+",' "+contacts[i].screen_name.substring(1)+" ');bodyField.cursorPosition=bodyField.cursorPosition+"+contacts[i].screen_name.length+"}}}"
//}
}
var menuString="import QtQuick.Controls 2.4; Menu {width:40*mm; font.pixelSize: 3*mm; "+contactitems+"}";
var contactlistObject=Qt.createQmlObject(menuString,messageColumn,"contactmenuOutput");
if (contacts.length>0){contactlistObject.popup()}
},letter);
}
// Flickable{
// anchors.fill: parent
// contentHeight: messageColumn.height
// boundsBehavior: Flickable.StopAtBounds
Column {
y:0.5*mm
id:messageColumn
spacing: 0.5*mm
width: parent.width
height: 10*mm//implicitHeight
Label{
id:receiverLabel
x: 0.5*mm
width: parent.width-mm
font.pixelSize: 3*mm
text: newsSwipeview.stacktype=="DirectMessages"?qsTr("to:")+ " "+ reply_to_user:""
visible:false// ((parentId !== "") || (newsStack.parent.stacktype=="DirectMessages"))
MouseArea{
anchors.fill: parent
onClicked:{}
}
}
TextField {
id: titleField
width: parent.width
x: 0.5*mm
width: parent.width-mm
font.pixelSize: 3*mm
placeholderText: qsTr("Title (optional)")
visible: parentId === ""
visible: false//(parentId === "") && (bodyField.length>1)
onVisibleChanged: if ((visible==true)&&(conversation==true)){
conversationView.contentY=conversationView.contentY+titleField.height
}
}
Rectangle{
color: "white"
radius: 0.5*mm
x:mm
width: parent.width-2*mm
height:Math.max(bodyField.contentHeight+2*mm,10*mm)
height:Math.max(bodyField.contentHeight+4*mm,10*mm)
TextArea {
id: bodyField
anchors.fill: parent
font.pixelSize: 3*mm
font.family: "Noto Sans"
wrapMode: Text.Wrap
selectByMouse: true
placeholderText: conversation?"": qsTr("What's on your mind?")
textFormat: TextEdit.RichText //TextEdit.PlainText
onLineCountChanged: (conversation==true)?conversationView.contentY=conversationView.contentY+3*mm:newsView.contentY=newsView.contentY+3*mm
onLinkActivated:{Qt.openUrlExternally(link)}
}
}
Row{
spacing: 2
width: parent.width
CheckBox{
id:dmCheckbox
text:"DM"
enabled: false
checked: (directmessage==1)?true:false
onClicked:{
if(dmCheckbox.checkedState==Qt.Checked){directmessage=1}
else if(dmCheckbox.checkedState==Qt.Unchecked){directmessage=0}
}
}
BlueButton{
text:"\uf0c1"
onClicked: {
if(bodyField.selectedText==""){Helperjs.showMessage("Error","No text selected",messageSend)}
else{urlTextEdit.text="";
urlRectangle.visible=true}}
}
}
Rectangle{
id:urlRectangle
height: 7*mm //parent.height
width:parent.width-2*mm
visible:false
TextField{
id:urlTextEdit
width:parent.width-7*mm
height:parent.height
}
BlueButton{
anchors.left:urlTextEdit.right
anchors.leftMargin:mm
text:"\u2713"
onClicked: {if(urlTextEdit.text!=""){
var start = bodyField.selectionStart;
var text=bodyField.selectedText
if(text.lastIndexOf(".jpg")>-1 || text.lastIndexOf(".jpeg")>-1 || text.lastIndexOf(".png")>-1){text="<img src="+text+">"}
text = "[url="+urlTextEdit.text+"]" + text + "[/url]";
bodyField.remove(start,bodyField.selectionEnd);
bodyField.insert(start,text);}
urlRectangle.visible=false}
onActiveFocusChanged:{
if (activeFocus==true){
if (conversation==true){
setParent(conversationModel.get(0).newsitemobject);
messageSend.state="conversation"
} else{
messageSend.state="active"
}
}
}
Row{
spacing:2
BlueButton{id:permButton
visible: (directmessage==1)?false:true
text: ((contact_allow.length==0)&&(contact_deny.length==0)&&(group_allow.length==0)&&(group_deny.length==0))?"\uf09c":"\uf023"
onClicked: { permissionDialog.visible=true;}
onTextChanged:{
if (text!=""){
//print(getText(bodyField.cursorPosition-2,bodyField.cursorPosition) +" preedit: "+ preeditText+cursorPosition);
var regex1 = /@[a-z]/;var regex2 = /![a-z]/;
//print(text.substring(cursorPosition-2,cursorPosition));
//if (regex.test(getText(bodyField.cursorPosition-2,bodyField.cursorPosition)) || regex.test(preeditText) || regex.test(text)){
if (regex1.test(getText(bodyField.cursorPosition-2,bodyField.cursorPosition)+preeditText) || regex2.test(getText(bodyField.cursorPosition-2,bodyField.cursorPosition)+preeditText)){
var letter=(getText(bodyField.cursorPosition-2,bodyField.cursorPosition)).match(/[a-z]/);
contactmenu(letter)
}
}}
}
BlueButton {
}
// Row{
// spacing: 2
// width: parent.width
// CheckBox{
// id:dmCheckbox
// text:"DM"
// enabled: false
// checked: (directmessage==1)?true:false
// onClicked:{
// if(dmCheckbox.checkedState==Qt.Checked){directmessage=1}
// else if(dmCheckbox.checkedState==Qt.Unchecked){directmessage=0}
// }
// }
// Button{
// text:"\uf0c1"
// height:8*mm
// onClicked: {
// if(bodyField.selectedText==""){Helperjs.showMessage("Error","No text selected",messageSend)}
// else{urlTextEdit.text="";
// urlRectangle.visible=true}}
// }
// }
// Rectangle{
// id:urlRectangle
// height: 7*mm //parent.height
// width:parent.width-2*mm
// visible:false
// TextField{
// id:urlTextEdit
// width:parent.width-7*mm
// height:parent.height
// }
// Button{
// anchors.left:urlTextEdit.right
// anchors.leftMargin:mm
// height:8*mm
// text:"\u2713"
// onClicked: {if(urlTextEdit.text!=""){
// var start = bodyField.selectionStart;
// var text=bodyField.selectedText
// if(text.lastIndexOf(".jpg")>-1 || text.lastIndexOf(".jpeg")>-1 || text.lastIndexOf(".png")>-1){text="<img src="+text+">"}
// text = "[url="+urlTextEdit.text+"]" + text + "[/url]";
// bodyField.remove(start,bodyField.selectionEnd);
// bodyField.insert(start,text);}
// urlRectangle.visible=false}
// }
// }
Row{
id:buttonRow
visible:false //(bodyField.length>1)||(attachImageURLs.length>0)
spacing: mm
height: 12*mm
MButton{id:permButton
visible: (newsSwipeview.stacktype!=="DirectMessages")
height: 6*mm
width: 7*mm
text: ((contact_allow.length==0)&&(contact_deny.length==0)&&(group_allow.length==0)&&(group_deny.length==0))?"\uf09c":"\uf023"
onClicked: { if (permissionDialog.visible==false){permissionDialog.visible=true} else{permissionDialog.visible=false}}
}
MButton {
id: attachButton
height: 6*mm
width: 7*mm
text: "\uf03e"
visible:(directmessage==0)
visible:(newsSwipeview.stacktype!="DirectMessages")
onClicked: {
if (attachImageURLs.length>0){//Server currently accepts only one attachment
Helperjs.showMessage( qsTr("Error"),qsTr("Only one attachment supported at the moment.\n Remove other attachment first!"), messageColumn)
}
else{
// root.imagePicking=true;
root.imagePicking=false;
var imagePicker = Qt.createQmlObject('import QtQuick 2.0; import "qrc:/qml/genericqml";'+
osSettings.imagePickQml+'{multiple : false;onReady: {attachImageURLs.push(imageUrl);'+
'attachImage(imageUrl)}}',root,"imagePicker");
@ -197,55 +326,102 @@ Rectangle{
}
}
}
BlueButton{
id:contactButton
text:"\uf234"
visible:(directmessage==0)
onClicked:{
var contactitems="";
for (var i=0;i<contacts.length;i++){
if(contacts[i].network=="dfrn"){
if(Helperjs.getCount(db,login,"contacts","screen_name",contacts[i].screen_name)>1){
contacts[i].screen_name=contacts[i].screen_name+"+"+contacts[i].cid
}
contactitems=contactitems+"MenuItem{text:'"+contacts[i].screen_name+"'; onTriggered: bodyField.insert("+bodyField.cursorPosition+",' @"+contacts[i].screen_name+" ')}"
}}
var menuString="import QtQuick.Controls 1.4; Menu {"+contactitems+"}";
var contactlistObject=Qt.createQmlObject(menuString,messageColumn,"contactmenuOutput")
contactlistObject.popup() }
}
BlueButton{
MButton{
id:smileyButton
text: "\uf118"
onClicked: {smileyDialog.visible=true}
height: 6*mm
width: 7*mm
onClicked: {if (smileyDialog.visible==false){smileyDialog.visible=true} else{smileyDialog.visible=false}}
}
BlueButton {
MButton {
id: cancelButton
height: 6*mm
width: 7*mm
text: "\uf057"
onClicked: {
newstab.newstabstatus=login.newsViewType;
newsStack.pop(null)
bodyField.text="";
messageSend.state="";
permissionDialog.visible=false;
receiverLabel.visible=false;
reply_to_user="";
attachImage("");
attachImageURLs.pop();
}
}
BlueButton {
}
MButton {
id: sendButton
height: 6*mm
width: 7*mm
text: "\uf1d9"
onClicked: {
var title=titleField.text.replace("\"","\'");
var body=bodyField.getFormattedText(0,bodyField.length);
var dmbody=bodyField.getText(0,bodyField.length);
if (directmessage==0){
if (newsSwipeview.stacktype!=="DirectMessages"){
statusUpdate(title,body,parentId,attachImageURLs)}
else {dmUpdate(title,dmbody,parentId,reply_to_user) }
newstab.newstabstatus=login.newsViewType; newsStack.pop(null)
else {
if (reply_to_user!=""){dmUpdate(title,dmbody,parentId,reply_to_user)}
else{Helperjs.showMessage(qsTr("Error"),qsTr("No receiver supplied!"),root)}
}
if (conversation==true){
newstab.newstabstatus=login.newsViewType; newsStack.pop(null)
}
}
}
}
PermissionDialog{id:permissionDialog;x:mm;visible: false}
SmileyDialog{id:smileyDialog;x:mm;visible: false}
}
Component.onCompleted: if(attachImageURLs.length>0){attachImage(attachImageURLs[0])}
}
Component.onCompleted:{
//
//parentId=conversationModel.get(conversationModel.count-1).newsitemobject.id
//if(attachImageURLs.length>0){attachImage(attachImageURLs[0])}
newsStack.replySignal.connect(setParent);
root.directmessageSignal.connect(directmessagePrepare);
root.uploadSignal.connect(sendUrls);
root.sendtextSignal.connect(sendtext);
}
states: [ State {
name: "active"
PropertyChanges {
target: messageColumn; height: implicitHeight
}
PropertyChanges {
target: buttonRow; visible:true
}
PropertyChanges {
target: titleField; visible:(newsSwipeview.stacktype!="DirectMessages")//true
}
PropertyChanges {
target: receiverLabel; visible:(newsSwipeview.stacktype=="DirectMessages");
}
},
State {
name: "conversation"
PropertyChanges {
target: messageColumn; height: implicitHeight
}
PropertyChanges {
target: buttonRow; visible:true
}
PropertyChanges {
target: titleField; visible:(newsSwipeview.stacktype!="DirectMessages")
}
// PropertyChanges {
// target: receiverLabel; visible:true; text:qsTr("to")+": "+ conversationModel.get(0).newsitemobject.user.name
// }
// PropertyChanges {
// target: messageSend; reply_to_user: conversationModel.get(0).newsitemobject.user.screen_name
// }
// PropertyChanges {
// target: messageSend; parentId: conversationModel.get(0).newsitemobject.status_id
// }
} ]
}
//}