From b8762ddb38dd975b0acb217b793594dfed83a824 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 12 Sep 2020 14:10:13 +0300 Subject: Initial commit --- context.cpp | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 context.cpp (limited to 'context.cpp') diff --git a/context.cpp b/context.cpp new file mode 100644 index 0000000..ef657c6 --- /dev/null +++ b/context.cpp @@ -0,0 +1,93 @@ +#include "context.h" + +Context::Context(QObject *parent) + : QObject(parent) +{ +} + +Context::Context(dc_context_t *context) + : QObject(nullptr) + , m_context(context) +{ +} + +Context::~Context() +{ + dc_context_unref(m_context); +} + +void +Context::configure() +{ + dc_configure(m_context); +} + +bool +Context::isConfigured() const +{ + return dc_is_configured(m_context); +} + +QString +Context::getInfo() +{ + char *info = dc_get_info(m_context); + QString result{info}; + dc_str_unref(info); + return result; +} + +DcChatlist * +Context::getChatlist() +{ + dc_chatlist_t *chatlist = dc_get_chatlist(m_context, 0, NULL, 0); + return new DcChatlist{chatlist}; +} + +DcChat * +Context::getChat(uint32_t chatId) +{ + dc_chat_t *chat = dc_get_chat(m_context, chatId); + return new DcChat{chat}; +} + +QVariantList +Context::getMsgIdList(uint32_t chatId) { + QVariantList result; + dc_array_t *msgIdArray = dc_get_chat_msgs(m_context, chatId, 0, 0); + for (size_t i = 0; i < dc_array_get_cnt(msgIdArray); i++) { + result << dc_array_get_id(msgIdArray, i); + } + dc_array_unref(msgIdArray); + return result; +} + +DcMessage * +Context::getMessage(uint32_t msgId) +{ + dc_msg_t *message = dc_get_msg(m_context, msgId); + return new DcMessage{message}; +} + +DcContact * +Context::getContact(uint32_t contactId) +{ + dc_contact_t *contact = dc_get_contact(m_context, contactId); + return new DcContact{contact}; +} + +QString +Context::getBlobdir() +{ + char *blobdir = dc_get_blobdir(m_context); + QString result{blobdir}; + dc_str_unref(blobdir); + return result; +} + +uint32_t +Context::sendTextMessage(uint32_t chatId, QString textToSend) +{ + QByteArray utf8Text = textToSend.toUtf8(); + return dc_send_text_msg(m_context, chatId, utf8Text.constData()); +} -- cgit v1.2.3-70-g09d2