aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Lionel <lionel@les-miquelots.net>2021-10-14 22:59:57 +0100
committerlink2xt <link2xt@testrun.org>1970-01-01 00:00:00 +0000
commit75043d4d2d90c56ad5d8ef16d69073144238f81c (patch)
treec1398bd5f0bd39113ea8124ea4ae0f6a72c28475
parent1147e7d717f6b7d4fa05e7a7a5519122615a0030 (diff)
downloadkdeltachat-75043d4d2d90c56ad5d8ef16d69073144238f81c.tar.gz
kdeltachat-75043d4d2d90c56ad5d8ef16d69073144238f81c.zip
Make attachment button functional
-rw-r--r--context.cpp17
-rw-r--r--context.h2
-rw-r--r--qml/ComposePane.qml21
3 files changed, 33 insertions, 7 deletions
diff --git a/context.cpp b/context.cpp
index 53cdd82..a138dd7 100644
--- a/context.cpp
+++ b/context.cpp
@@ -1,4 +1,7 @@
#include "context.h"
+#include <strings.h>
+#include <QTextStream>
+#include <QFile>
Context::Context(QObject *parent)
: QObject(parent)
@@ -264,8 +267,20 @@ Context::newMessage(int viewtype)
}
uint32_t
-Context::sendMessage(uint32_t chatId, DcMessage *message)
+Context::sendMessage(uint32_t chatId, DcMessage *message, QString attachment)
{
+ QByteArray utf8attachFilename = attachment.toUtf8();
+ if(strlen(utf8attachFilename.constData()) > 0){
+ dc_msg_set_file(message->m_message, utf8attachFilename.constData(), NULL);
+
+ QString ImgBlobPath;
+ QTextStream (&ImgBlobPath) << dc_get_blobdir(m_context) << "/" << dc_msg_get_filename(message->m_message);
+
+ printf("\nPush it into blob dir :%s\n", ImgBlobPath.toUtf8().constData());
+ QFile::copy(attachment, ImgBlobPath.toUtf8().constData());
+ dc_msg_set_file(message->m_message, ImgBlobPath.toUtf8().constData(), NULL);
+ }
+ dc_prepare_msg(m_context, chatId, message->m_message);
return dc_send_msg(m_context, chatId, message->m_message);
}
diff --git a/context.h b/context.h
index 4e6409a..95b3275 100644
--- a/context.h
+++ b/context.h
@@ -53,7 +53,7 @@ public:
Q_INVOKABLE QString getMessageInfo(uint32_t msgId);
Q_INVOKABLE QString getMessageHtml(uint32_t msgId);
Q_INVOKABLE DcMessage *newMessage(int viewtype);
- Q_INVOKABLE uint32_t sendMessage(uint32_t chatId, DcMessage *message);
+ Q_INVOKABLE uint32_t sendMessage(uint32_t chatId, DcMessage *message, QString attachment);
Q_INVOKABLE void importBackup(QString tarfile);
private:
diff --git a/qml/ComposePane.qml b/qml/ComposePane.qml
index 6bcdec9..a108e9f 100644
--- a/qml/ComposePane.qml
+++ b/qml/ComposePane.qml
@@ -10,12 +10,18 @@ Pane {
required property DcContext context
required property var chatId
required property var chat
+ property var attachFileUrl: ""
property bool canSend: root.chat && root.chat.canSend
property bool isContactRequest: root.chat && root.chat.isContactRequest
function createMessage() {
let DC_MSG_TEXT = 10;
- var msg = root.context.newMessage(DC_MSG_TEXT);
+ let DC_MSG_FILE = 60;
+
+ if (attachFileUrl.length > 0)
+ var msg = root.context.newMessage(DC_MSG_FILE);
+ else
+ var msg = root.context.newMessage(DC_MSG_TEXT);
msg.setText(messageField.text);
return msg;
}
@@ -30,8 +36,8 @@ Pane {
onAccepted: {
var url = attachFileDialog.fileUrl.toString()
if (url.startsWith("file://")) {
- var filename = url.substring(7)
- console.log("Attaching " + filename)
+ attachFileUrl = url.substring(7)
+ console.log("Attaching " + attachFileUrl)
}
}
}
@@ -83,10 +89,15 @@ Pane {
Layout.alignment: Qt.AlignBottom
icon.name: "document-send"
text: qsTr("Send")
- enabled: messageField.length > 0
+ enabled: messageField.length > 0 | attachFileUrl.length > 0
onClicked: {
let msg = root.createMessage();
- root.context.sendMessage(root.chatId, msg);
+ if (attachFileUrl.length > 0)
+ root.context.sendMessage(root.chatId, msg, attachFileUrl)
+ else
+ root.context.sendMessage(root.chatId, msg, "")
+
+ attachFileUrl = "";
messageField.text = "";
root.context.setDraft(chatId, null);
}