From 166d17e61da080ee7b83317b1a97ec2046960706 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 22 May 2021 15:23:11 +0300 Subject: Implement libdeltachat API for HTML view HTML API: - Context::getMessageHtml() - DcMessage::getSubject() - DcMessage::hasHtml() Also implemented: - DcMessage::getFilemime() - DcMessage::getShowPadlock() - DcMessage::getError() --- context.cpp | 9 +++++++++ context.h | 1 + message.cpp | 39 +++++++++++++++++++++++++++++++++++++++ message.h | 9 +++++++-- 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/context.cpp b/context.cpp index 89a7937..e7742f6 100644 --- a/context.cpp +++ b/context.cpp @@ -173,6 +173,15 @@ Context::getMessageInfo(uint32_t msgId) return result; } +QString +Context::getMessageHtml(uint32_t msgId) +{ + char *html = dc_get_msg_html(m_context, msgId); + QString result{html}; + dc_str_unref(html); + return result; +} + uint32_t Context::sendTextMessage(uint32_t chatId, QString textToSend) { diff --git a/context.h b/context.h index aaeb76d..df3fbfb 100644 --- a/context.h +++ b/context.h @@ -44,6 +44,7 @@ public: Q_INVOKABLE QString getConfig(QString key); Q_INVOKABLE bool setChatMuteDuration(uint32_t chatId, int64_t duration); Q_INVOKABLE QString getMessageInfo(uint32_t msgId); + Q_INVOKABLE QString getMessageHtml(uint32_t msgId); Q_INVOKABLE uint32_t decideOnContactRequest(uint32_t msgId, int decision); private: diff --git a/message.cpp b/message.cpp index ff4bab9..cf29dae 100644 --- a/message.cpp +++ b/message.cpp @@ -55,6 +55,15 @@ DcMessage::getText() return result; } +QString +DcMessage::getSubject() +{ + char *subject = dc_msg_get_subject(m_message); + QString result{subject}; + dc_str_unref(subject); + return result; +} + QString DcMessage::getFile() { @@ -73,6 +82,15 @@ DcMessage::getFilename() return result; } +QString +DcMessage::getFilemime() +{ + char *filemime = dc_msg_get_filemime(m_message); + QString result{filemime}; + dc_str_unref(filemime); + return result; +} + int DcMessage::getWidth() { @@ -85,6 +103,12 @@ DcMessage::getHeight() return dc_msg_get_height(m_message); } +bool +DcMessage::getShowPadlock() +{ + return dc_msg_get_showpadlock(m_message); +} + QString DcMessage::getOverrideSenderName() { @@ -100,6 +124,21 @@ DcMessage::isInfo() return dc_msg_is_info(m_message); } +QString +DcMessage::getError() +{ + char *error = dc_msg_get_error(m_message); + QString result{error}; + dc_str_unref(error); + return result; +} + +bool +DcMessage::hasHtml() +{ + return dc_msg_has_html(m_message); +} + QString DcMessage::getQuotedText() { diff --git a/message.h b/message.h index d9f4253..8f7ec9c 100644 --- a/message.h +++ b/message.h @@ -12,6 +12,7 @@ class DcMessage : public QObject { Q_PROPERTY(int viewtype READ getViewtype CONSTANT) Q_PROPERTY(int state READ getState CONSTANT) Q_PROPERTY(QString text READ getText CONSTANT) + Q_PROPERTY(QString subject READ getSubject CONSTANT) Q_PROPERTY(QString file READ getFile CONSTANT) Q_PROPERTY(QString filename READ getFilename CONSTANT) Q_PROPERTY(int width READ getWidth CONSTANT) @@ -19,6 +20,7 @@ class DcMessage : public QObject { Q_PROPERTY(bool isInfo READ isInfo CONSTANT) Q_PROPERTY(QString quotedText READ getQuotedText CONSTANT) Q_PROPERTY(DcMessage *quotedMessage READ getQuotedMessage CONSTANT) + Q_PROPERTY(bool hasHtml READ hasHtml CONSTANT) dc_msg_t *m_message{nullptr}; public: @@ -35,14 +37,15 @@ public: //Q_INVOKABLE int64_t getReceivedTimestamp(); //Q_INVOKABLE int64_t getSortTimestamp(); Q_INVOKABLE QString getText(); + Q_INVOKABLE QString getSubject(); QString getFile(); QString getFilename(); - //QString getFilemime(); + QString getFilemime(); //uint64_t getFilebytes(); int getWidth(); int getHeight(); //int getDuration(); - //bool showPadlock(); + bool getShowPadlock(); //uint32_t getEphemeralTimer(); //int64_t getEphemeralTimestamp(); //... getsummary ... @@ -53,6 +56,8 @@ public: //isStarred //isForwarded bool isInfo(); + Q_INVOKABLE QString getError(); + bool hasHtml(); //isIncreation //isSetupmessage Q_INVOKABLE QString getQuotedText(); -- cgit v1.2.3-70-g09d2