diff options
-rw-r--r-- | context.cpp | 6 | ||||
-rw-r--r-- | context.h | 2 | ||||
-rw-r--r-- | message.cpp | 7 | ||||
-rw-r--r-- | message.h | 3 | ||||
-rw-r--r-- | qml/ComposePane.qml | 11 |
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); } @@ -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() { @@ -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 = ""; |