132 lines
4.9 KiB
QML
132 lines
4.9 KiB
QML
// message.qml
|
|
// message with buttons
|
|
import QtQuick 2.0
|
|
import QtQml 2.2
|
|
import QtQuick.Controls 1.3
|
|
import QtQuick.Dialogs 1.2
|
|
import QtQuick.LocalStorage 2.0
|
|
//import "../qml"
|
|
import "qrc:/js/service.js" as Service
|
|
|
|
Item{
|
|
id:messageSend
|
|
property var login
|
|
property string parentId: ""
|
|
property string reply_to_user:""
|
|
property string attachImageURL: "";
|
|
property int directmessage: 0;
|
|
property var contacts: []
|
|
// title: parentId !== "" ? qsTr("Reply to "+reply_to_user) : qsTr("New post")
|
|
|
|
function statusUpdate(title,status,in_reply_to_status_id,attachImageURL) {
|
|
xhr.url= login.server + "/api/statuses/update.xml";
|
|
xhr.setLogin(login.username+":"+Qt.atob(login.password));
|
|
print("login: "+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 (attachImageURL!=="") {xhr.setImageFileParam("media", attachImageURL )};
|
|
xhr.post();
|
|
}
|
|
|
|
function dmUpdate(title,text,replyto,screen_name,attachImageURL) {
|
|
xhr.url= login.server + "/api/direct_messages/new.xml";
|
|
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)};
|
|
if (attachImageURL!=="") {xhr.setImageFileParam("media", attachImageURL )};
|
|
xhr.post();
|
|
}
|
|
|
|
Column {
|
|
id:messageColumn
|
|
spacing: 2
|
|
|
|
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
|
|
}
|
|
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}
|
|
}
|
|
}
|
|
Row{
|
|
spacing:2
|
|
Button {
|
|
id: cancelButton
|
|
text: qsTr("Cancel")
|
|
onClicked: {newsStack.pop()}
|
|
}
|
|
|
|
Button {
|
|
id: attachButton
|
|
text: qsTr("Attach")
|
|
onClicked: {imageAttachmentDialog.open()}
|
|
}
|
|
Button{
|
|
id:contactButton
|
|
text:qsTr("cc")
|
|
visible:(directmessage==0)
|
|
onClicked:{
|
|
var contactitems="";
|
|
for (var i=0;i<contacts.length;i++){
|
|
contactitems=contactitems+"MenuItem{text:'"+contacts[i]+"'; onTriggered: bodyField.append(' @"+contacts[i]+"')}"
|
|
}
|
|
var menuString="import QtQuick.Controls 1.4; Menu {"+contactitems+"}";
|
|
// print(menuString);
|
|
var contactlistObject=Qt.createQmlObject(menuString,messageSend,"contactmenuOutput")
|
|
contactlistObject.popup() }
|
|
}
|
|
|
|
Button {
|
|
id: sendButton
|
|
text: qsTr("Send")
|
|
onClicked: {
|
|
print("login: "+login.server+login.username);
|
|
if (directmessage==0){
|
|
statusUpdate(titleField.text,bodyField.text,messageSend.parentId,attachImageURL.toString());}
|
|
else {dmUpdate( titleField.text,bodyField.text,"",messageSend.reply_to_user) }
|
|
newsStack.pop()
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
FileDialog {
|
|
id: imageAttachmentDialog
|
|
title: "Please choose a picture"
|
|
folder: shortcuts.pictures
|
|
selectFolder: false
|
|
onAccepted: {
|
|
attachImageURL=imageAttachmentDialog.fileUrl;
|
|
var imageAttachementObject=Qt.createQmlObject('import QtQuick 2.0; Image {source:"'+attachImageURL.toString()+'"; width: 30*mm; height: 30*mm;fillMode: Image.PreserveAspectFit}',messageColumn,"attachedImage");
|
|
console.log("You chose: " + attachImageURL)
|
|
|
|
}
|
|
onRejected: {
|
|
console.log("Canceled")
|
|
}
|
|
}
|
|
}
|