aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlink2xt <link2xt@testrun.org>1970-01-01 00:00:00 +0000
committerlink2xt <link2xt@testrun.org>1970-01-01 00:00:00 +0000
commit021d00d9d9148be3c5969ac7834403c695f9258d (patch)
tree7f3da0eeeb9b7f56b333af0fca5dd2a4795322b9
parentd4c66cd1341084b37dfabe3126d13ff8f062fd59 (diff)
downloadkdeltachat-021d00d9d9148be3c5969ac7834403c695f9258d.tar.gz
kdeltachat-021d00d9d9148be3c5969ac7834403c695f9258d.zip
Add Message.setFile method
This allows setting file from JavaScript, so C++ remains a thin wrapper to Delta Chat core API. sendMessage only calls dc_send_msg, and all the attachment logic goes to the JavaScript code.
-rw-r--r--context.cpp6
-rw-r--r--context.h2
-rw-r--r--message.cpp7
-rw-r--r--message.h3
-rw-r--r--qml/ComposePane.qml11
5 files changed, 16 insertions, 13 deletions
diff --git a/context.cpp b/context.cpp
index 1fa24af..802a555 100644
--- a/context.cpp
+++ b/context.cpp
@@ -267,12 +267,8 @@ Context::newMessage(int viewtype)
}
uint32_t
-Context::sendMessage(uint32_t chatId, DcMessage *message, QString attachment)
+Context::sendMessage(uint32_t chatId, DcMessage *message)
{
- if (!attachment.isEmpty()) {
- QByteArray utf8attachFilename = attachment.toUtf8();
- dc_msg_set_file(message->m_message, utf8attachFilename.constData(), NULL);
- }
return dc_send_msg(m_context, chatId, message->m_message);
}
diff --git a/context.h b/context.h
index 95b3275..4e6409a 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, QString attachment);
+ Q_INVOKABLE uint32_t sendMessage(uint32_t chatId, DcMessage *message);
Q_INVOKABLE void importBackup(QString tarfile);
private:
diff --git a/message.cpp b/message.cpp
index fdaae93..4da0fd1 100644
--- a/message.cpp
+++ b/message.cpp
@@ -68,6 +68,13 @@ DcMessage::getText()
return result;
}
+void
+DcMessage::setFile(QString file)
+{
+ QByteArray utf8File = file.toUtf8();
+ return dc_msg_set_file(m_message, utf8File.constData(), NULL);
+}
+
QString
DcMessage::getSubject()
{
diff --git a/message.h b/message.h
index 8930f02..217bba4 100644
--- a/message.h
+++ b/message.h
@@ -17,7 +17,7 @@ class DcMessage : public QObject {
Q_PROPERTY(QDateTime timestamp READ getTimestamp CONSTANT)
Q_PROPERTY(QString text READ getText WRITE setText)
Q_PROPERTY(QString subject READ getSubject CONSTANT)
- Q_PROPERTY(QString file READ getFile CONSTANT)
+ Q_PROPERTY(QString file READ getFile WRITE setFile)
Q_PROPERTY(QString filename READ getFilename CONSTANT)
Q_PROPERTY(int width READ getWidth CONSTANT)
Q_PROPERTY(int height READ getHeight CONSTANT)
@@ -45,6 +45,7 @@ public:
//Q_INVOKABLE int64_t getReceivedTimestamp();
//Q_INVOKABLE int64_t getSortTimestamp();
Q_INVOKABLE void setText(QString);
+ Q_INVOKABLE void setFile(QString);
Q_INVOKABLE QString getText();
Q_INVOKABLE QString getSubject();
QString getFile();
diff --git a/qml/ComposePane.qml b/qml/ComposePane.qml
index a108e9f..2dc24d1 100644
--- a/qml/ComposePane.qml
+++ b/qml/ComposePane.qml
@@ -18,10 +18,12 @@ Pane {
let DC_MSG_TEXT = 10;
let DC_MSG_FILE = 60;
- if (attachFileUrl.length > 0)
+ if (attachFileUrl.length > 0) {
var msg = root.context.newMessage(DC_MSG_FILE);
- else
+ msg.setFile(attachFileUrl)
+ } else
var msg = root.context.newMessage(DC_MSG_TEXT);
+
msg.setText(messageField.text);
return msg;
}
@@ -92,10 +94,7 @@ Pane {
enabled: messageField.length > 0 | attachFileUrl.length > 0
onClicked: {
let msg = root.createMessage();
- if (attachFileUrl.length > 0)
- root.context.sendMessage(root.chatId, msg, attachFileUrl)
- else
- root.context.sendMessage(root.chatId, msg, "")
+ root.context.sendMessage(root.chatId, msg)
attachFileUrl = "";
messageField.text = "";