2017-01-26 21:55:31 +01:00
|
|
|
// message.qml
|
|
|
|
// message with buttons
|
|
|
|
import QtQuick 2.0
|
|
|
|
import QtQuick.Controls 1.3
|
|
|
|
import QtQuick.Dialogs 1.2
|
|
|
|
import "qrc:/js/helper.js" as Helperjs
|
2017-03-25 23:36:14 +01:00
|
|
|
import "qrc:/js/smiley.js" as Smileyjs
|
2017-01-26 21:55:31 +01:00
|
|
|
import "qrc:/qml/genericqml"
|
|
|
|
|
2017-03-25 23:36:14 +01:00
|
|
|
|
2017-01-26 21:55:31 +01:00
|
|
|
Flickable{
|
|
|
|
width:root.width-5*mm
|
|
|
|
height:root.height-12*mm
|
|
|
|
contentHeight: messageColumn.height
|
|
|
|
boundsBehavior: Flickable.StopAtBounds
|
|
|
|
id:messageSend
|
|
|
|
property string parentId: ""
|
|
|
|
property string reply_to_user:""
|
2017-05-11 22:15:34 +02:00
|
|
|
property var attachImageURLs: [];
|
2017-01-26 21:55:31 +01:00
|
|
|
property int directmessage: 0;
|
|
|
|
property var contacts: []
|
|
|
|
property var groups: []
|
|
|
|
property var contact_allow:login.permissions[0]
|
|
|
|
property var contact_deny:login.permissions[1]
|
|
|
|
property var group_allow:login.permissions[2]
|
|
|
|
property var group_deny:login.permissions[3]
|
|
|
|
|
2017-05-11 22:15:34 +02:00
|
|
|
function attachImage(url){
|
|
|
|
//onAttachImageURLsChanged: {if(attachImageURL!=""){
|
|
|
|
var imageAttachmentObject=Qt.createQmlObject('import QtQuick 2.0; Image {id:imageAttachment'+attachImageURLs.length+'; source:"'+
|
|
|
|
url.toString()+'"; width: 15*mm; height: 15*mm;fillMode: Image.PreserveAspectFit;MouseArea{anchors.fill:parent;onClicked:{attachImageURLs.splice(attachImageURLs.indexOf("'+url+'",1)); imageAttachment'+attachImageURLs.length+'.destroy()}}}',messageColumn,"attachedImage");
|
|
|
|
console.log("You chose: " + url)
|
|
|
|
}
|
|
|
|
|
2017-01-26 21:55:31 +01:00
|
|
|
function statusUpdate(title,status,in_reply_to_status_id,attachImageURL) {
|
2017-03-25 23:36:14 +01:00
|
|
|
xhr.url= login.server + "/api/statuses/update.json";
|
2017-01-26 21:55:31 +01:00
|
|
|
xhr.setLogin(login.username+":"+Qt.atob(login.password));
|
|
|
|
xhr.clearParams();
|
|
|
|
xhr.setParam("source", "Friendiqa");
|
|
|
|
xhr.setParam("status", status);
|
|
|
|
if (parentId!="") {xhr.setParam("in_reply_to_status_id", parentId)};
|
|
|
|
if (title!=="") {xhr.setParam("title", title)};
|
|
|
|
if (group_allow.length>0) {xhr.setParam("group_allow", Helperjs.cleanArray(group_allow))};
|
|
|
|
if (group_deny.length>0) {xhr.setParam("group_deny", Helperjs.cleanArray(group_deny))};
|
|
|
|
if (contact_allow.length>0) {xhr.setParam("contact_allow", Helperjs.cleanArray(contact_allow))};
|
|
|
|
if (contact_deny.length>0) {xhr.setParam("contact_deny", Helperjs.cleanArray(contact_deny))};
|
2017-05-11 22:15:34 +02:00
|
|
|
if (attachImageURL.length>0) {for (var image in attachImageURL){xhr.setImageFileParam("media", attachImageURL[image] )}};
|
2017-01-26 21:55:31 +01:00
|
|
|
xhr.post();
|
|
|
|
}
|
|
|
|
|
|
|
|
function dmUpdate(title,text,replyto,screen_name,attachImageURL) {
|
2017-03-25 23:36:14 +01:00
|
|
|
xhr.url= login.server + "/api/direct_messages/new.json";
|
2017-01-26 21:55:31 +01:00
|
|
|
xhr.setLogin(login.username+":"+Qt.atob(login.password));
|
|
|
|
xhr.clearParams();
|
|
|
|
xhr.setParam("text", text);
|
|
|
|
xhr.setParam("screen_name", screen_name);
|
|
|
|
if (parentId!="") {xhr.setParam("replyto", replyto)};
|
|
|
|
if (title!=="") {xhr.setParam("title", title)};
|
|
|
|
xhr.post();
|
|
|
|
}
|
|
|
|
|
|
|
|
Column {
|
|
|
|
id:messageColumn
|
|
|
|
spacing: 2
|
|
|
|
width: parent.width
|
|
|
|
TextField {
|
|
|
|
id: titleField
|
|
|
|
width: parent.width
|
|
|
|
placeholderText: qsTr("Title (optional)")
|
|
|
|
visible: messageSend.parentId === ""
|
|
|
|
}
|
|
|
|
|
|
|
|
TextArea {
|
|
|
|
id: bodyField
|
|
|
|
width: parent.width
|
|
|
|
height: 30*mm
|
|
|
|
wrapMode: TextEdit.Wrap
|
|
|
|
textFormat: TextEdit.PlainText
|
|
|
|
}
|
|
|
|
|
|
|
|
Row{
|
|
|
|
spacing: 2
|
|
|
|
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{
|
2017-03-25 23:36:14 +01:00
|
|
|
text:"\uf0c1"
|
2017-01-26 21:55:31 +01:00
|
|
|
onClicked: {
|
|
|
|
if(bodyField.selectedText==""){Helperjs.showMessage("Error","No text selected",messageSend)}
|
|
|
|
else{urlTextEdit.text="";
|
|
|
|
urlRectangle.visible=true}}
|
|
|
|
}
|
|
|
|
Rectangle{
|
|
|
|
id:urlRectangle
|
|
|
|
height:parent.height
|
|
|
|
width:37*mm
|
|
|
|
visible:false
|
|
|
|
TextField{
|
|
|
|
id:urlTextEdit
|
|
|
|
width:30*mm
|
|
|
|
height:parent.height
|
|
|
|
}
|
|
|
|
BlueButton{
|
|
|
|
anchors.left:urlTextEdit.right
|
|
|
|
anchors.leftMargin:mm
|
2017-03-25 23:36:14 +01:00
|
|
|
text:"\u2713"
|
2017-01-26 21:55:31 +01:00
|
|
|
onClicked: {if(urlTextEdit.text!=""){
|
|
|
|
var start = bodyField.selectionStart;
|
|
|
|
var end = bodyField.selectionEnd;
|
|
|
|
var text = bodyField.getText(start,end);
|
|
|
|
text = "[url="+urlTextEdit.text+"]" + text + "[/url]";
|
|
|
|
bodyField.remove(start,end);
|
|
|
|
bodyField.insert(start,text);}
|
|
|
|
urlRectangle.visible=false}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Row{
|
|
|
|
spacing:2
|
2017-03-25 23:36:14 +01:00
|
|
|
BlueButton{id:permButton
|
2017-01-26 21:55:31 +01:00
|
|
|
visible: (directmessage==1)?false:true
|
2017-05-11 22:15:34 +02:00
|
|
|
text: ((contact_allow.length==0)&&(contact_deny.length==0)&&(group_allow.length==0)&&(group_deny.length==0))?"\uf09c":"\uf023"
|
2017-01-26 21:55:31 +01:00
|
|
|
onClicked: {
|
|
|
|
var component = Qt.createComponent("qrc:/qml/newsqml/PermissionDialog.qml");
|
|
|
|
var permissions = component.createObject(messageColumn);
|
|
|
|
}}
|
|
|
|
BlueButton {
|
|
|
|
id: attachButton
|
2017-03-25 23:36:14 +01:00
|
|
|
text: "\uf0c6"
|
2017-01-26 21:55:31 +01:00
|
|
|
visible:(directmessage==0)
|
|
|
|
onClicked: {
|
2017-05-11 22:15:34 +02:00
|
|
|
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{
|
|
|
|
var defaultDirectory="file://"+osSettings.attachImageDir;
|
|
|
|
var component = Qt.createComponent("qrc:/qml/newsqml/ImageDialog.qml");
|
|
|
|
var imagedialog = component.createObject(messageSend,{"directory": defaultDirectory});
|
|
|
|
}
|
2017-01-26 21:55:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
BlueButton{
|
|
|
|
id:contactButton
|
2017-03-25 23:36:14 +01:00
|
|
|
text:"\uf234"
|
2017-01-26 21:55:31 +01:00
|
|
|
visible:(directmessage==0)
|
|
|
|
onClicked:{
|
|
|
|
var contactitems="";
|
|
|
|
for (var i=0;i<contacts.length;i++){
|
2017-03-25 23:36:14 +01:00
|
|
|
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+"';iconSource:'"+contacts[i].profile_image+"'; onTriggered: bodyField.insert(0,' @"+contacts[i].screen_name+"+"+contacts[i].cid+" ')}"
|
|
|
|
}}
|
2017-01-26 21:55:31 +01:00
|
|
|
var menuString="import QtQuick.Controls 1.4; Menu {"+contactitems+"}";
|
|
|
|
var contactlistObject=Qt.createQmlObject(menuString,messageSend,"contactmenuOutput")
|
|
|
|
contactlistObject.popup() }
|
|
|
|
}
|
2017-03-25 23:36:14 +01:00
|
|
|
|
|
|
|
BlueButton{
|
|
|
|
id:smileyButton
|
|
|
|
text: "\uf118"
|
|
|
|
onClicked: {
|
|
|
|
var smileyarray=Smileyjs.smileys
|
|
|
|
//print(JSON.stringify(smileyarray[0]))
|
|
|
|
var component = Qt.createComponent("qrc:/qml/newsqml/SmileyDialog.qml");
|
|
|
|
var smileydialog = component.createObject(messageColumn)
|
|
|
|
}}
|
|
|
|
|
2017-01-26 21:55:31 +01:00
|
|
|
BlueButton {
|
|
|
|
id: cancelButton
|
2017-03-25 23:36:14 +01:00
|
|
|
text: "\uf057"
|
2017-01-26 21:55:31 +01:00
|
|
|
onClicked: {newstab.newstabstatus=login.newsViewType;
|
2017-01-29 17:26:09 +01:00
|
|
|
newsStack.pop()}
|
2017-01-26 21:55:31 +01:00
|
|
|
}
|
|
|
|
BlueButton {
|
|
|
|
id: sendButton
|
2017-03-25 23:36:14 +01:00
|
|
|
text: "\uf1d9"
|
2017-01-26 21:55:31 +01:00
|
|
|
onClicked: {
|
|
|
|
var title=titleField.text.replace("\"","\'");
|
|
|
|
var body=bodyField.getText(0,bodyField.length);
|
|
|
|
if (directmessage==0){
|
2017-05-11 22:15:34 +02:00
|
|
|
statusUpdate(title,body,messageSend.parentId,attachImageURLs)}
|
2017-01-26 21:55:31 +01:00
|
|
|
else {dmUpdate(title,body,"",messageSend.reply_to_user) }
|
2017-01-29 17:26:09 +01:00
|
|
|
newstab.newstabstatus=login.newsViewType; newsStack.pop()
|
2017-01-26 21:55:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-25 23:36:14 +01:00
|
|
|
}
|
2017-01-26 21:55:31 +01:00
|
|
|
}
|