2018-02-19 22:36:00 +01:00
|
|
|
// This file is part of Friendiqa
|
|
|
|
// https://github.com/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/>.
|
|
|
|
|
2017-01-26 21:55:31 +01:00
|
|
|
// message.qml
|
|
|
|
// message with buttons
|
|
|
|
import QtQuick 2.0
|
2018-07-20 21:15:54 +02:00
|
|
|
import QtQuick.Controls 1.4
|
|
|
|
//import QtQuick.Dialogs 1.2
|
2017-01-26 21:55:31 +01:00
|
|
|
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
|
|
|
|
2018-07-01 15:09:21 +02:00
|
|
|
Rectangle{
|
|
|
|
color:"white"
|
2018-07-20 21:15:54 +02:00
|
|
|
// width:root.width-5*mm
|
|
|
|
// height:root.height-12*mm
|
2018-07-01 15:09:21 +02:00
|
|
|
//anchors.fill: parent
|
2017-01-26 21:55:31 +01:00
|
|
|
property string parentId: ""
|
|
|
|
property string reply_to_user:""
|
2018-04-22 21:12:40 +02:00
|
|
|
property alias bodyMessage: bodyField.text
|
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]
|
|
|
|
|
2018-07-01 15:09:21 +02:00
|
|
|
function attachImage(url){ print("attachImage "+url)
|
2018-02-19 22:36:00 +01:00
|
|
|
var imageAttachmentObject=Qt.createQmlObject('import QtQuick 2.0; Image {id:imageAttachment'+attachImageURLs.length+'; source:"'+
|
2018-04-22 21:12:40 +02:00
|
|
|
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");
|
2017-05-11 22:15:34 +02:00
|
|
|
}
|
|
|
|
|
2017-01-26 21:55:31 +01:00
|
|
|
function statusUpdate(title,status,in_reply_to_status_id,attachImageURL) {
|
2018-07-01 15:09:21 +02: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));
|
2018-07-01 15:09:21 +02:00
|
|
|
xhr.setUrl(login.server);
|
|
|
|
xhr.setApi("/api/statuses/update");
|
2017-01-26 21:55:31 +01:00
|
|
|
xhr.clearParams();
|
|
|
|
xhr.setParam("source", "Friendiqa");
|
2018-07-20 21:15:54 +02:00
|
|
|
xhr.setParam("htmlstatus", status);
|
2017-01-26 21:55:31 +01:00
|
|
|
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) {
|
2018-07-01 15:09:21 +02: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));
|
2018-07-01 15:09:21 +02:00
|
|
|
xhr.setUrl(login.server);
|
|
|
|
xhr.setApi("/api/direct_messages/new");
|
2017-01-26 21:55:31 +01:00
|
|
|
xhr.clearParams();
|
|
|
|
xhr.setParam("text", text);
|
|
|
|
xhr.setParam("screen_name", screen_name);
|
|
|
|
if (parentId!="") {xhr.setParam("replyto", replyto)};
|
2018-07-01 15:09:21 +02:00
|
|
|
//if (title!=="") {xhr.setParam("title", title)};
|
2017-01-26 21:55:31 +01:00
|
|
|
xhr.post();
|
|
|
|
}
|
|
|
|
|
2018-07-01 15:09:21 +02:00
|
|
|
Flickable{
|
2018-07-20 21:15:54 +02:00
|
|
|
anchors.fill: parent
|
|
|
|
contentHeight: messageColumn.height
|
|
|
|
boundsBehavior: Flickable.StopAtBounds
|
|
|
|
id:messageSend
|
|
|
|
Column {
|
2017-01-26 21:55:31 +01:00
|
|
|
id:messageColumn
|
2018-04-22 21:12:40 +02:00
|
|
|
spacing: 0.5*mm
|
2017-01-26 21:55:31 +01:00
|
|
|
width: parent.width
|
|
|
|
TextField {
|
|
|
|
id: titleField
|
|
|
|
width: parent.width
|
|
|
|
placeholderText: qsTr("Title (optional)")
|
2018-07-01 15:09:21 +02:00
|
|
|
visible: parentId === ""
|
2017-01-26 21:55:31 +01:00
|
|
|
}
|
|
|
|
|
2018-04-22 21:12:40 +02:00
|
|
|
Rectangle{
|
|
|
|
color: "white"
|
|
|
|
radius: 0.5*mm
|
|
|
|
x:mm
|
|
|
|
width: parent.width-2*mm
|
|
|
|
height:Math.max(bodyField.contentHeight+2*mm,10*mm)
|
|
|
|
TextArea {
|
|
|
|
id: bodyField
|
|
|
|
anchors.fill: parent
|
|
|
|
font.pixelSize: 3*mm
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
selectByMouse: true
|
2018-07-20 21:15:54 +02:00
|
|
|
textFormat: TextEdit.RichText //TextEdit.PlainText
|
|
|
|
onLinkActivated:{Qt.openUrlExternally(link)}
|
2018-04-22 21:12:40 +02:00
|
|
|
}
|
2017-01-26 21:55:31 +01:00
|
|
|
}
|
|
|
|
|
2018-04-22 21:12:40 +02:00
|
|
|
|
2017-01-26 21:55:31 +01:00
|
|
|
Row{
|
|
|
|
spacing: 2
|
2018-07-20 21:15:54 +02:00
|
|
|
width: parent.width
|
2017-01-26 21:55:31 +01:00
|
|
|
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}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-20 21:15:54 +02:00
|
|
|
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
|
2017-01-26 21:55:31 +01:00
|
|
|
height:parent.height
|
2018-07-20 21:15:54 +02:00
|
|
|
}
|
|
|
|
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}
|
2017-01-26 21:55:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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"
|
2018-04-22 21:12:40 +02:00
|
|
|
onClicked: { permissionDialog.visible=true;}
|
|
|
|
}
|
2017-01-26 21:55:31 +01:00
|
|
|
BlueButton {
|
|
|
|
id: attachButton
|
2018-04-22 21:12:40 +02:00
|
|
|
text: "\uf03e"
|
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{
|
2018-02-19 22:36:00 +01:00
|
|
|
var imagePicker = Qt.createQmlObject('import QtQuick 2.0; import "qrc:/qml/genericqml";'+
|
|
|
|
osSettings.imagePickQml+'{multiple : false;onReady: {attachImageURLs.push(imageUrl);'+
|
|
|
|
'attachImage(imageUrl)}}',messageSend,"imagePicker");
|
|
|
|
imagePicker.pickImage()
|
2017-05-11 22:15:34 +02:00
|
|
|
}
|
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
|
|
|
|
}
|
2018-07-20 21:15:54 +02:00
|
|
|
contactitems=contactitems+"MenuItem{text:'"+contacts[i].screen_name+"'; onTriggered: bodyField.insert("+bodyField.cursorPosition+",' @"+contacts[i].screen_name+" ')}"
|
2017-03-25 23:36:14 +01:00
|
|
|
}}
|
2017-01-26 21:55:31 +01:00
|
|
|
var menuString="import QtQuick.Controls 1.4; Menu {"+contactitems+"}";
|
2018-04-22 21:12:40 +02:00
|
|
|
var contactlistObject=Qt.createQmlObject(menuString,messageColumn,"contactmenuOutput")
|
2017-01-26 21:55:31 +01:00
|
|
|
contactlistObject.popup() }
|
|
|
|
}
|
2017-03-25 23:36:14 +01:00
|
|
|
|
|
|
|
BlueButton{
|
|
|
|
id:smileyButton
|
|
|
|
text: "\uf118"
|
2018-04-22 21:12:40 +02:00
|
|
|
onClicked: {smileyDialog.visible=true}
|
|
|
|
}
|
2017-03-25 23:36:14 +01:00
|
|
|
|
2017-01-26 21:55:31 +01:00
|
|
|
BlueButton {
|
|
|
|
id: cancelButton
|
2017-03-25 23:36:14 +01:00
|
|
|
text: "\uf057"
|
2018-04-22 21:12:40 +02:00
|
|
|
onClicked: {
|
|
|
|
newstab.newstabstatus=login.newsViewType;
|
|
|
|
newsStack.pop(null)
|
|
|
|
}
|
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("\"","\'");
|
2018-07-20 21:15:54 +02:00
|
|
|
var body=bodyField.getFormattedText(0,bodyField.length);
|
|
|
|
var dmbody=bodyField.getText(0,bodyField.length);
|
2017-01-26 21:55:31 +01:00
|
|
|
if (directmessage==0){
|
2018-07-20 21:15:54 +02:00
|
|
|
statusUpdate(title,body,parentId,attachImageURLs)}
|
|
|
|
else {dmUpdate(title,dmbody,parentId,reply_to_user) }
|
2018-04-11 21:50:43 +02:00
|
|
|
newstab.newstabstatus=login.newsViewType; newsStack.pop(null)
|
2017-01-26 21:55:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-22 21:12:40 +02:00
|
|
|
PermissionDialog{id:permissionDialog;x:mm;visible: false}
|
|
|
|
SmileyDialog{id:smileyDialog;x:mm;visible: false}
|
2017-03-25 23:36:14 +01:00
|
|
|
}
|
2018-04-11 21:50:43 +02:00
|
|
|
Component.onCompleted: if(attachImageURLs.length>0){attachImage(attachImageURLs[0])}
|
2017-01-26 21:55:31 +01:00
|
|
|
}
|
2018-07-01 15:09:21 +02:00
|
|
|
}
|