diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d630b98c1..022c3f4401 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -314,6 +314,8 @@ set(${PROJECT_NAME}_SOURCES src/core/toxid.h src/core/conferenceid.cpp src/core/conferenceid.h + src/core/conferencetype.cpp + src/core/conferencetype.h src/core/toxlogger.cpp src/core/toxlogger.h src/core/toxoptions.cpp diff --git a/src/core/conferencetype.cpp b/src/core/conferencetype.cpp new file mode 100644 index 0000000000..fa96282ae7 --- /dev/null +++ b/src/core/conferencetype.cpp @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later + * Copyright © 2024 The TokTok team. + */ + +#include "conferencetype.h" + +#include + +QDebug operator<<(QDebug debug, ConferenceType type) +{ + switch (type) { + case ConferenceType::UNKNOWN: + debug << "UNKNOWN"; + break; + case ConferenceType::TEXT: + debug << "TEXT"; + break; + case ConferenceType::AV: + debug << "AV"; + break; + } + return debug; +} diff --git a/src/core/conferencetype.h b/src/core/conferencetype.h new file mode 100644 index 0000000000..9d0a710141 --- /dev/null +++ b/src/core/conferencetype.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later + * Copyright © 2024 The TokTok team. + */ + +#pragma once + +#include + +enum class ConferenceType +{ + UNKNOWN, + TEXT, + AV, +}; +Q_DECLARE_METATYPE(ConferenceType) + +QDebug operator<<(QDebug debug, ConferenceType type); diff --git a/src/core/core.cpp b/src/core/core.cpp index a5092dee7f..16a0c4fa7a 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -10,14 +10,12 @@ #include "src/core/dhtserver.h" #include "src/core/icoresettings.h" -#include "src/core/toxlogger.h" #include "src/core/toxoptions.h" #include "src/core/toxstring.h" #include "src/model/conferenceinvite.h" #include "src/model/ibootstraplistgenerator.h" #include "src/model/status.h" #include "src/persistence/profile.h" -#include "util/strongtype.h" #include "util/toxcoreerrorparser.h" #include @@ -28,6 +26,7 @@ #include #include +#include #include #include @@ -48,8 +47,43 @@ QList shuffleBootstrapNodes(QList bootstrapNodes) return bootstrapNodes; } +struct Tox_Events_Deleter +{ + void operator()(Tox_Events* events) + { + tox_events_free(events); + } +}; + +Tox_Message_Type toToxEnum(Core::MessageType type) +{ + switch (type) { + case Core::MessageType::NORMAL: + return TOX_MESSAGE_TYPE_NORMAL; + case Core::MessageType::ACTION: + return TOX_MESSAGE_TYPE_ACTION; + } + qFatal("Unknown message type: %d", static_cast(type)); +} + +ConferenceType fromToxEnum(Tox_Conference_Type type) +{ + switch (type) { + case TOX_CONFERENCE_TYPE_TEXT: + return ConferenceType::TEXT; + case TOX_CONFERENCE_TYPE_AV: + return ConferenceType::AV; + } + return ConferenceType::UNKNOWN; +} + } // namespace +void Core::Tox_Deleter::operator()(Tox* tox_) const +{ + tox_kill(tox_); +} + Core::Core(QThread* coreThread_, IBootstrapListGenerator& bootstrapListGenerator_, const ICoreSettings& settings_) : tox(nullptr) @@ -80,27 +114,6 @@ Core::~Core() tox.reset(); } -/** - * @brief Registers all toxcore callbacks - * @param tox Tox instance to register the callbacks on - */ -void Core::registerCallbacks(Tox* tox) -{ - tox_callback_friend_request(tox, onFriendRequest); - tox_callback_friend_message(tox, onFriendMessage); - tox_callback_friend_name(tox, onFriendNameChange); - tox_callback_friend_typing(tox, onFriendTypingChange); - tox_callback_friend_status_message(tox, onStatusMessageChanged); - tox_callback_friend_status(tox, onUserStatusChanged); - tox_callback_friend_connection_status(tox, onConnectionStatusChanged); - tox_callback_friend_read_receipt(tox, onReadReceiptCallback); - tox_callback_conference_invite(tox, onConferenceInvite); - tox_callback_conference_message(tox, onConferenceMessage); - tox_callback_conference_peer_list_changed(tox, onConferencePeerListChange); - tox_callback_conference_peer_name(tox, onConferencePeerNameChange); - tox_callback_conference_title(tox, onConferenceTitleChange); -} - /** * @brief Factory method for the Core object * @param savedata empty if new profile or saved data else @@ -223,7 +236,7 @@ ToxCorePtr Core::makeToxCore(const QByteArray& savedata, const ICoreSettings& se return {}; } - registerCallbacks(core->tox.get()); + tox_events_init(core->tox.get()); // connect the thread with the Core connect(thread, &QThread::started, core.get(), &Core::onStarted); @@ -298,6 +311,93 @@ QRecursiveMutex& Core::getCoreLoopLock() const return coreLoopLock; } +void Core::dispatchEvent(const Tox_Event* event) +{ + switch (tox_event_get_type(event)) { + case TOX_EVENT_FRIEND_REQUEST: + return onFriendRequest(tox_event_get_friend_request(event), this); + case TOX_EVENT_FRIEND_CONNECTION_STATUS: + return onFriendConnectionStatus(tox_event_get_friend_connection_status(event), this); + case TOX_EVENT_FRIEND_LOSSY_PACKET: + break; + case TOX_EVENT_FRIEND_LOSSLESS_PACKET: + break; + case TOX_EVENT_FRIEND_NAME: + return onFriendName(tox_event_get_friend_name(event), this); + case TOX_EVENT_FRIEND_STATUS: + return onFriendStatus(tox_event_get_friend_status(event), this); + case TOX_EVENT_FRIEND_STATUS_MESSAGE: + return onFriendStatusMessage(tox_event_get_friend_status_message(event), this); + case TOX_EVENT_FRIEND_MESSAGE: + return onFriendMessage(tox_event_get_friend_message(event), this); + case TOX_EVENT_FRIEND_READ_RECEIPT: + return onFriendReadReceipt(tox_event_get_friend_read_receipt(event), this); + case TOX_EVENT_FRIEND_TYPING: + return onFriendTyping(tox_event_get_friend_typing(event), this); + case TOX_EVENT_FILE_CHUNK_REQUEST: + return CoreFile::onFileChunkRequest(tox_event_get_file_chunk_request(event), this); + case TOX_EVENT_FILE_RECV: + return CoreFile::onFileRecv(tox_event_get_file_recv(event), this); + case TOX_EVENT_FILE_RECV_CHUNK: + return CoreFile::onFileRecvChunk(tox_event_get_file_recv_chunk(event), this); + case TOX_EVENT_FILE_RECV_CONTROL: + return CoreFile::onFileRecvControl(tox_event_get_file_recv_control(event), this); + case TOX_EVENT_CONFERENCE_INVITE: + return onConferenceInvite(tox_event_get_conference_invite(event), this); + case TOX_EVENT_CONFERENCE_CONNECTED: + break; + case TOX_EVENT_CONFERENCE_PEER_LIST_CHANGED: + return onConferencePeerListChanged(tox_event_get_conference_peer_list_changed(event), this); + case TOX_EVENT_CONFERENCE_PEER_NAME: + return onConferencePeerName(tox_event_get_conference_peer_name(event), this); + case TOX_EVENT_CONFERENCE_TITLE: + return onConferenceTitle(tox_event_get_conference_title(event), this); + case TOX_EVENT_CONFERENCE_MESSAGE: + return onConferenceMessage(tox_event_get_conference_message(event), this); + case TOX_EVENT_GROUP_PEER_NAME: + break; + case TOX_EVENT_GROUP_PEER_STATUS: + break; + case TOX_EVENT_GROUP_TOPIC: + break; + case TOX_EVENT_GROUP_PRIVACY_STATE: + break; + case TOX_EVENT_GROUP_VOICE_STATE: + break; + case TOX_EVENT_GROUP_TOPIC_LOCK: + break; + case TOX_EVENT_GROUP_PEER_LIMIT: + break; + case TOX_EVENT_GROUP_PASSWORD: + break; + case TOX_EVENT_GROUP_MESSAGE: + break; + case TOX_EVENT_GROUP_PRIVATE_MESSAGE: + break; + case TOX_EVENT_GROUP_CUSTOM_PACKET: + break; + case TOX_EVENT_GROUP_CUSTOM_PRIVATE_PACKET: + break; + case TOX_EVENT_GROUP_INVITE: + break; + case TOX_EVENT_GROUP_PEER_JOIN: + break; + case TOX_EVENT_GROUP_PEER_EXIT: + break; + case TOX_EVENT_GROUP_SELF_JOIN: + break; + case TOX_EVENT_GROUP_JOIN_FAIL: + break; + case TOX_EVENT_GROUP_MODERATION: + break; + case TOX_EVENT_DHT_GET_NODES_RESPONSE: + break; + default: + qWarning() << "Unknown event type" << tox_event_type_to_string(tox_event_get_type(event)); + break; + } +} + /** * @brief Processes toxcore events and ensure we stay connected, called by its own timer */ @@ -307,7 +407,16 @@ void Core::process() ASSERT_CORE_THREAD; - tox_iterate(tox.get(), this); + Tox_Err_Events_Iterate err; + std::unique_ptr events{tox_events_iterate(tox.get(), true, &err)}; + if (err != TOX_ERR_EVENTS_ITERATE_OK) { + PARSE_ERR(err); + } else if (events != nullptr) { + for (uint32_t i = 0; i < tox_events_get_size(events.get()); ++i) { + const Tox_Event* event = tox_events_get(events.get(), i); + dispatchEvent(event); + } + } #ifdef DEBUG // we want to see the debug messages immediately @@ -409,51 +518,63 @@ void Core::bootstrapDht() } } -void Core::onFriendRequest(Tox* tox, const uint8_t* cFriendPk, const uint8_t* cMessage, - size_t cMessageSize, void* core) +void Core::onFriendRequest(const Tox_Event_Friend_Request* event, void* vCore) { - std::ignore = tox; - const ToxPk friendPk(cFriendPk); - const QString requestMessage = ToxString(cMessage, cMessageSize).getQString(); - emit static_cast(core)->friendRequestReceived(friendPk, requestMessage); + Core* core = static_cast(vCore); + const ToxPk friendPk(tox_event_friend_request_get_public_key(event)); + const QString requestMessage = ToxString(tox_event_friend_request_get_message(event), + tox_event_friend_request_get_message_length(event)) + .getQString(); + emit core->friendRequestReceived(friendPk, requestMessage); } -void Core::onFriendMessage(Tox* tox, uint32_t friendId, Tox_Message_Type type, - const uint8_t* cMessage, size_t cMessageSize, void* core) +void Core::onFriendMessage(const Tox_Event_Friend_Message* event, void* vCore) { - std::ignore = tox; + Core* core = static_cast(vCore); + const auto friendId = tox_event_friend_message_get_friend_number(event); + const auto type = tox_event_friend_message_get_type(event); + const auto message = tox_event_friend_message_get_message(event); + const auto length = tox_event_friend_message_get_message_length(event); const bool isAction = (type == TOX_MESSAGE_TYPE_ACTION); - const QString msg = ToxString(cMessage, cMessageSize).getQString(); - emit static_cast(core)->friendMessageReceived(friendId, msg, isAction); + const QString msg = ToxString(message, length).getQString(); + emit core->friendMessageReceived(friendId, msg, isAction); } -void Core::onFriendNameChange(Tox* tox, uint32_t friendId, const uint8_t* cName, size_t cNameSize, - void* core) +void Core::onFriendName(const Tox_Event_Friend_Name* event, void* vCore) { - std::ignore = tox; - const QString newName = ToxString(cName, cNameSize).getQString(); + Core* core = static_cast(vCore); + const auto friendId = tox_event_friend_name_get_friend_number(event); + const auto name = tox_event_friend_name_get_name(event); + const auto length = tox_event_friend_name_get_name_length(event); + const QString newName = ToxString(name, length).getQString(); // no saveRequest, this callback is called on every connection, not just on name change - emit static_cast(core)->friendUsernameChanged(friendId, newName); + emit core->friendUsernameChanged(friendId, newName); } -void Core::onFriendTypingChange(Tox* tox, uint32_t friendId, bool isTyping, void* core) +void Core::onFriendTyping(const Tox_Event_Friend_Typing* event, void* vCore) { - std::ignore = tox; - emit static_cast(core)->friendTypingChanged(friendId, isTyping); + Core* core = static_cast(vCore); + const auto friendId = tox_event_friend_typing_get_friend_number(event); + const auto isTyping = tox_event_friend_typing_get_typing(event); + emit core->friendTypingChanged(friendId, isTyping); } -void Core::onStatusMessageChanged(Tox* tox, uint32_t friendId, const uint8_t* cMessage, - size_t cMessageSize, void* core) +void Core::onFriendStatusMessage(const Tox_Event_Friend_Status_Message* event, void* vCore) { - std::ignore = tox; - const QString message = ToxString(cMessage, cMessageSize).getQString(); + Core* core = static_cast(vCore); + const auto friendId = tox_event_friend_status_message_get_friend_number(event); + const auto message = tox_event_friend_status_message_get_message(event); + const auto length = tox_event_friend_status_message_get_message_length(event); + const QString msg = ToxString(message, length).getQString(); // no saveRequest, this callback is called on every connection, not just on name change - emit static_cast(core)->friendStatusMessageChanged(friendId, message); + emit core->friendStatusMessageChanged(friendId, msg); } -void Core::onUserStatusChanged(Tox* tox, uint32_t friendId, Tox_User_Status userstatus, void* core) +void Core::onFriendStatus(const Tox_Event_Friend_Status* event, void* vCore) { - std::ignore = tox; + Core* core = static_cast(vCore); + const auto friendId = tox_event_friend_status_get_friend_number(event); + const auto userstatus = tox_event_friend_status_get_status(event); Status::Status status; switch (userstatus) { case TOX_USER_STATUS_AWAY: @@ -470,13 +591,14 @@ void Core::onUserStatusChanged(Tox* tox, uint32_t friendId, Tox_User_Status user } // no saveRequest, this callback is called on every connection, not just on name change - emit static_cast(core)->friendStatusChanged(friendId, status); + emit core->friendStatusChanged(friendId, status); } -void Core::onConnectionStatusChanged(Tox* tox, uint32_t friendId, Tox_Connection status, void* vCore) +void Core::onFriendConnectionStatus(const Tox_Event_Friend_Connection_Status* event, void* vCore) { - std::ignore = tox; Core* core = static_cast(vCore); + const auto friendId = tox_event_friend_connection_status_get_friend_number(event); + const auto status = tox_event_friend_connection_status_get_connection_status(event); Status::Status friendStatus = Status::Status::Offline; switch (status) { case TOX_CONNECTION_NONE: @@ -504,78 +626,88 @@ void Core::onConnectionStatusChanged(Tox* tox, uint32_t friendId, Tox_Connection } } -void Core::onConferenceInvite(Tox* tox, uint32_t friendId, Tox_Conference_Type type, - const uint8_t* cookie, size_t length, void* vCore) +void Core::onConferenceInvite(const Tox_Event_Conference_Invite* event, void* vCore) { - std::ignore = tox; Core* core = static_cast(vCore); + const auto friendId = tox_event_conference_invite_get_friend_number(event); + const auto type = tox_event_conference_invite_get_type(event); + const auto cookie = tox_event_conference_invite_get_cookie(event); + const auto length = tox_event_conference_invite_get_cookie_length(event); const QByteArray data(reinterpret_cast(cookie), length); - const ConferenceInvite inviteInfo(friendId, type, data); - switch (type) { - case TOX_CONFERENCE_TYPE_TEXT: + const ConferenceInvite inviteInfo(friendId, fromToxEnum(type), data); + switch (fromToxEnum(type)) { + case ConferenceType::TEXT: qDebug() << "Text conference invite by" << friendId; emit core->conferenceInviteReceived(inviteInfo); break; - case TOX_CONFERENCE_TYPE_AV: + case ConferenceType::AV: qDebug() << "AV conference invite by" << friendId; emit core->conferenceInviteReceived(inviteInfo); break; - default: - qWarning() << "Conference invite with unknown type" << type; + case ConferenceType::UNKNOWN: + qCritical() << "Conference invite with unknown type" << type; + break; } } -void Core::onConferenceMessage(Tox* tox, uint32_t conferenceId, uint32_t peerId, Tox_Message_Type type, - const uint8_t* cMessage, size_t length, void* vCore) +void Core::onConferenceMessage(const Tox_Event_Conference_Message* event, void* vCore) { - std::ignore = tox; Core* core = static_cast(vCore); - const bool isAction = type == TOX_MESSAGE_TYPE_ACTION; - const QString message = ToxString(cMessage, length).getQString(); - emit core->conferenceMessageReceived(conferenceId, peerId, message, isAction); + const auto conferenceId = tox_event_conference_message_get_conference_number(event); + const auto peerId = tox_event_conference_message_get_peer_number(event); + const auto type = tox_event_conference_message_get_type(event); + const auto message = tox_event_conference_message_get_message(event); + const auto length = tox_event_conference_message_get_message_length(event); + bool isAction = type == TOX_MESSAGE_TYPE_ACTION; + QString msg = ToxString(message, length).getQString(); + emit core->conferenceMessageReceived(conferenceId, peerId, msg, isAction); } -void Core::onConferencePeerListChange(Tox* tox, uint32_t conferenceId, void* vCore) +void Core::onConferencePeerListChanged(const Tox_Event_Conference_Peer_List_Changed* event, void* vCore) { - std::ignore = tox; - const auto core = static_cast(vCore); + Core* core = static_cast(vCore); + const auto conferenceId = tox_event_conference_peer_list_changed_get_conference_number(event); qDebug("Conference %u peerlist changed", conferenceId); - // no saveRequest, this callback is called on every connection to conference peer, not just on brand new peers emit core->conferencePeerlistChanged(conferenceId); } -void Core::onConferencePeerNameChange(Tox* tox, uint32_t conferenceId, uint32_t peerId, - const uint8_t* name, size_t length, void* vCore) +void Core::onConferencePeerName(const Tox_Event_Conference_Peer_Name* event, void* vCore) { - std::ignore = tox; + Core* core = static_cast(vCore); + const auto conferenceId = tox_event_conference_peer_name_get_conference_number(event); + const auto peerId = tox_event_conference_peer_name_get_peer_number(event); + const auto name = tox_event_conference_peer_name_get_name(event); + const auto length = tox_event_conference_peer_name_get_name_length(event); const auto newName = ToxString(name, length).getQString(); qDebug().nospace() << "Conference " << conferenceId << ", peer " << peerId << ", name " << newName; - auto* core = static_cast(vCore); auto peerPk = core->getConferencePeerPk(conferenceId, peerId); emit core->conferencePeerNameChanged(conferenceId, peerPk, newName); } -void Core::onConferenceTitleChange(Tox* tox, uint32_t conferenceId, uint32_t peerId, - const uint8_t* cTitle, size_t length, void* vCore) +void Core::onConferenceTitle(const Tox_Event_Conference_Title* event, void* vCore) { - std::ignore = tox; Core* core = static_cast(vCore); + const auto conferenceId = tox_event_conference_title_get_conference_number(event); + const auto peerId = tox_event_conference_title_get_peer_number(event); + const auto title = tox_event_conference_title_get_title(event); + const auto length = tox_event_conference_title_get_title_length(event); QString author; // from tox.h: "If peer_number == UINT32_MAX, then author is unknown (e.g. initial joining the conference)." if (peerId != std::numeric_limits::max()) { author = core->getConferencePeerName(conferenceId, peerId); } emit core->saveRequest(); - emit core->conferenceTitleChanged(conferenceId, author, ToxString(cTitle, length).getQString()); + emit core->conferenceTitleChanged(conferenceId, author, ToxString(title, length).getQString()); } - -void Core::onReadReceiptCallback(Tox* tox, uint32_t friendId, uint32_t receipt, void* core) +void Core::onFriendReadReceipt(const Tox_Event_Friend_Read_Receipt* event, void* vCore) { - std::ignore = tox; - emit static_cast(core)->receiptReceived(friendId, ReceiptNum{receipt}); + Core* core = static_cast(vCore); + const auto friendId = tox_event_friend_read_receipt_get_friend_number(event); + const auto receipt = tox_event_friend_read_receipt_get_message_id(event); + emit core->receiptReceived(friendId, ReceiptNum{receipt}); } void Core::acceptFriendRequest(const ToxPk& friendPk) @@ -648,11 +780,11 @@ void Core::requestFriendship(const ToxId& friendId, const QString& message) } } -bool Core::sendMessageWithType(uint32_t friendId, const QString& message, Tox_Message_Type type, +bool Core::sendMessageWithType(uint32_t friendId, const QString& message, MessageType type, ReceiptNum& receipt) { const int size = message.toUtf8().size(); - auto maxSize = static_cast(getMaxMessageSize()); + const auto maxSize = static_cast(getMaxMessageSize()); if (size > maxSize) { assert(false); qCritical() << "Core::sendMessageWithType called with message of size:" << size @@ -662,8 +794,8 @@ bool Core::sendMessageWithType(uint32_t friendId, const QString& message, Tox_Me const ToxString cMessage(message); Tox_Err_Friend_Send_Message error; - receipt = ReceiptNum{tox_friend_send_message(tox.get(), friendId, type, cMessage.data(), - cMessage.size(), &error)}; + receipt = ReceiptNum{tox_friend_send_message(tox.get(), friendId, toToxEnum(type), + cMessage.data(), cMessage.size(), &error)}; if (PARSE_ERR(error)) { return true; } @@ -673,13 +805,13 @@ bool Core::sendMessageWithType(uint32_t friendId, const QString& message, Tox_Me bool Core::sendMessage(uint32_t friendId, const QString& message, ReceiptNum& receipt) { const QMutexLocker ml(&coreLoopLock); - return sendMessageWithType(friendId, message, TOX_MESSAGE_TYPE_NORMAL, receipt); + return sendMessageWithType(friendId, message, MessageType::NORMAL, receipt); } bool Core::sendAction(uint32_t friendId, const QString& action, ReceiptNum& receipt) { const QMutexLocker ml(&coreLoopLock); - return sendMessageWithType(friendId, action, TOX_MESSAGE_TYPE_ACTION, receipt); + return sendMessageWithType(friendId, action, MessageType::ACTION, receipt); } void Core::sendTyping(uint32_t friendId, bool typing) @@ -693,7 +825,7 @@ void Core::sendTyping(uint32_t friendId, bool typing) } } -void Core::sendConferenceMessageWithType(int conferenceId, const QString& message, Tox_Message_Type type) +void Core::sendConferenceMessageWithType(int conferenceId, const QString& message, MessageType type) { const QMutexLocker ml{&coreLoopLock}; @@ -707,7 +839,8 @@ void Core::sendConferenceMessageWithType(int conferenceId, const QString& messag const ToxString cMsg(message); Tox_Err_Conference_Send_Message error; - tox_conference_send_message(tox.get(), conferenceId, type, cMsg.data(), cMsg.size(), &error); + tox_conference_send_message(tox.get(), conferenceId, toToxEnum(type), cMsg.data(), cMsg.size(), + &error); if (!PARSE_ERR(error)) { emit conferenceSentFailed(conferenceId); return; @@ -718,14 +851,14 @@ void Core::sendConferenceMessage(int conferenceId, const QString& message) { const QMutexLocker ml{&coreLoopLock}; - sendConferenceMessageWithType(conferenceId, message, TOX_MESSAGE_TYPE_NORMAL); + sendConferenceMessageWithType(conferenceId, message, MessageType::NORMAL); } void Core::sendConferenceAction(int conferenceId, const QString& message) { const QMutexLocker ml{&coreLoopLock}; - sendConferenceMessageWithType(conferenceId, message, TOX_MESSAGE_TYPE_ACTION); + sendConferenceMessageWithType(conferenceId, message, MessageType::ACTION); } void Core::changeConferenceTitle(uint32_t conferenceId, const QString& title) @@ -1181,13 +1314,13 @@ uint32_t Core::joinConference(const ConferenceInvite& inviteInfo) const QMutexLocker ml{&coreLoopLock}; const uint32_t friendId = inviteInfo.getFriendId(); - const uint8_t confType = inviteInfo.getType(); + const ConferenceType confType = inviteInfo.getType(); const QByteArray invite = inviteInfo.getInvite(); const uint8_t* const cookie = reinterpret_cast(invite.data()); const size_t cookieLength = invite.length(); uint32_t conferenceNum{std::numeric_limits::max()}; switch (confType) { - case TOX_CONFERENCE_TYPE_TEXT: { + case ConferenceType::TEXT: { qDebug() << "Trying to accept invite for text conference sent by friend" << friendId; Tox_Err_Conference_Join error; conferenceNum = tox_conference_join(tox.get(), friendId, cookie, cookieLength, &error); @@ -1196,7 +1329,7 @@ uint32_t Core::joinConference(const ConferenceInvite& inviteInfo) } break; } - case TOX_CONFERENCE_TYPE_AV: { + case ConferenceType::AV: { qDebug() << "Trying to join AV conference invite sent by friend" << friendId; conferenceNum = toxav_join_av_groupchat(tox.get(), friendId, cookie, cookieLength, CoreAV::conferenceCallCallback, this); @@ -1221,11 +1354,11 @@ void Core::conferenceInviteFriend(uint32_t friendId, int conferenceId) PARSE_ERR(error); } -int Core::createConference(uint8_t type) +int Core::createConference(ConferenceType type) { const QMutexLocker ml{&coreLoopLock}; - if (type == TOX_CONFERENCE_TYPE_TEXT) { + if (type == ConferenceType::TEXT) { Tox_Err_Conference_New error; const uint32_t conferenceId = tox_conference_new(tox.get(), &error); if (PARSE_ERR(error)) { @@ -1235,7 +1368,7 @@ int Core::createConference(uint8_t type) } return std::numeric_limits::max(); } - if (type == TOX_CONFERENCE_TYPE_AV) { + if (type == ConferenceType::AV) { // unlike tox_conference_new, toxav_add_av_groupchat does not have an error enum, so -1 // conference number is our only indication of an error const int conferenceId = diff --git a/src/core/core.h b/src/core/core.h index a644ca102f..b433e847ec 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -7,6 +7,7 @@ #pragma once #include "conferenceid.h" +#include "conferencetype.h" #include "icoreconferencemessagesender.h" #include "icoreconferencequery.h" #include "icorefriendmessagesender.h" @@ -17,7 +18,6 @@ #include "toxpk.h" #include "src/model/status.h" -#include #include #include @@ -35,6 +35,21 @@ class Profile; class Core; class IBootstrapListGenerator; struct DhtServer; +struct Tox; +struct Tox_Event; +struct Tox_Event_Conference_Invite; +struct Tox_Event_Conference_Message; +struct Tox_Event_Friend_Request; +struct Tox_Event_Friend_Message; +struct Tox_Event_Friend_Name; +struct Tox_Event_Friend_Typing; +struct Tox_Event_Friend_Status_Message; +struct Tox_Event_Friend_Status; +struct Tox_Event_Friend_Connection_Status; +struct Tox_Event_Conference_Peer_List_Changed; +struct Tox_Event_Conference_Peer_Name; +struct Tox_Event_Conference_Title; +struct Tox_Event_Friend_Read_Receipt; using ToxCorePtr = std::unique_ptr; @@ -45,7 +60,21 @@ class Core : public QObject, public ICoreConferenceQuery { Q_OBJECT + +private: + struct Tox_Deleter + { + void operator()(Tox* tox) const; + }; + using ToxPtr = std::unique_ptr; + public: + enum class MessageType + { + NORMAL, + ACTION, + }; + enum class ToxCoreErrors { BAD_PROXY, @@ -102,7 +131,7 @@ public slots: void acceptFriendRequest(const ToxPk& friendPk); void requestFriendship(const ToxId& friendId, const QString& message); void conferenceInviteFriend(uint32_t friendId, int conferenceId); - int createConference(uint8_t type = TOX_CONFERENCE_TYPE_AV); + int createConference(ConferenceType type = ConferenceType::AV); void removeFriend(uint32_t friendId); void removeConference(int conferenceId); @@ -184,38 +213,26 @@ public slots: Core(QThread* coreThread_, IBootstrapListGenerator& bootstrapListGenerator_, const ICoreSettings& settings_); - static void onFriendRequest(Tox* tox, const uint8_t* cFriendPk, const uint8_t* cMessage, - size_t cMessageSize, void* core); - static void onFriendMessage(Tox* tox, uint32_t friendId, Tox_Message_Type type, - const uint8_t* cMessage, size_t cMessageSize, void* core); - static void onFriendNameChange(Tox* tox, uint32_t friendId, const uint8_t* cName, - size_t cNameSize, void* core); - static void onFriendTypingChange(Tox* tox, uint32_t friendId, bool isTyping, void* core); - static void onStatusMessageChanged(Tox* tox, uint32_t friendId, const uint8_t* cMessage, - size_t cMessageSize, void* core); - static void onUserStatusChanged(Tox* tox, uint32_t friendId, Tox_User_Status userstatus, - void* core); - static void onConnectionStatusChanged(Tox* tox, uint32_t friendId, Tox_Connection status, - void* vCore); - static void onConferenceInvite(Tox* tox, uint32_t friendId, Tox_Conference_Type type, - const uint8_t* cookie, size_t length, void* vCore); - static void onConferenceMessage(Tox* tox, uint32_t conferenceId, uint32_t peerId, - Tox_Message_Type type, const uint8_t* cMessage, size_t length, - void* vCore); - static void onConferencePeerListChange(Tox* tox, uint32_t conferenceId, void* core); - static void onConferencePeerNameChange(Tox* tox, uint32_t conferenceId, uint32_t peerId, - const uint8_t* name, size_t length, void* core); - static void onConferenceTitleChange(Tox* tox, uint32_t conferenceId, uint32_t peerId, - const uint8_t* cTitle, size_t length, void* vCore); - - static void onReadReceiptCallback(Tox* tox, uint32_t friendId, uint32_t receipt, void* core); - - void sendConferenceMessageWithType(int conferenceId, const QString& message, Tox_Message_Type type); - bool sendMessageWithType(uint32_t friendId, const QString& message, Tox_Message_Type type, + static void onFriendRequest(const Tox_Event_Friend_Request* event, void* vCore); + static void onFriendMessage(const Tox_Event_Friend_Message* event, void* vCore); + static void onFriendName(const Tox_Event_Friend_Name* event, void* vCore); + static void onFriendTyping(const Tox_Event_Friend_Typing* event, void* vCore); + static void onFriendStatusMessage(const Tox_Event_Friend_Status_Message* event, void* vCore); + static void onFriendStatus(const Tox_Event_Friend_Status* event, void* vCore); + static void onFriendConnectionStatus(const Tox_Event_Friend_Connection_Status* event, void* vCore); + static void onConferenceInvite(const Tox_Event_Conference_Invite* event, void* vCore); + static void onConferenceMessage(const Tox_Event_Conference_Message* event, void* vCore); + static void onConferencePeerListChanged(const Tox_Event_Conference_Peer_List_Changed* event, + void* vCore); + static void onConferencePeerName(const Tox_Event_Conference_Peer_Name* event, void* vCore); + static void onConferenceTitle(const Tox_Event_Conference_Title* event, void* vCore); + static void onFriendReadReceipt(const Tox_Event_Friend_Read_Receipt* event, void* vCore); + + void sendConferenceMessageWithType(int conferenceId, const QString& message, MessageType type); + bool sendMessageWithType(uint32_t friendId, const QString& message, MessageType type, ReceiptNum& receipt); bool checkConnection(); - void makeTox(QByteArray savedata, ICoreSettings* s); void loadFriends(); void loadConferences(); void bootstrapDht(); @@ -223,20 +240,14 @@ public slots: void checkLastOnline(uint32_t friendId); QString getFriendRequestErrorMessage(const ToxId& friendId, const QString& message) const; - static void registerCallbacks(Tox* tox); + + void dispatchEvent(const Tox_Event* event); private slots: void process(); void onStarted(); private: - struct ToxDeleter - { - void operator()(Tox* tox_) - { - tox_kill(tox_); - } - }; /* Using the now commented out statements in checkConnection(), I watched how * many ticks disconnects-after-initial-connect lasted. Out of roughly 15 trials, * 5 disconnected; 4 were DCd for less than 20 ticks, while the 5th was ~50 ticks. @@ -246,7 +257,6 @@ private slots: */ #define CORE_DISCONNECT_TOLERANCE 30 - using ToxPtr = std::unique_ptr; ToxPtr tox; std::unique_ptr file; diff --git a/src/core/corefile.cpp b/src/core/corefile.cpp index cbdb552301..48c4073c72 100644 --- a/src/core/corefile.cpp +++ b/src/core/corefile.cpp @@ -10,7 +10,6 @@ #include "toxstring.h" #include "src/model/status.h" #include "src/model/toxclientstandards.h" -#include "src/persistence/settings.h" #include "util/toxcoreerrorparser.h" #include @@ -33,7 +32,6 @@ CoreFilePtr CoreFile::makeCoreFile(Core* core, Tox* tox, QRecursiveMutex& coreLo { assert(core != nullptr); assert(tox != nullptr); - connectCallbacks(*tox); CoreFilePtr result = CoreFilePtr{new CoreFile{tox, coreLoopLock}}; connect(core, &Core::friendStatusChanged, result.get(), &CoreFile::onConnectionStatusChanged); @@ -71,15 +69,6 @@ unsigned CoreFile::corefileIterationInterval() return idleInterval; } -void CoreFile::connectCallbacks(Tox& tox) -{ - // be careful not to to reconnect already used callbacks here - tox_callback_file_chunk_request(&tox, CoreFile::onFileDataCallback); - tox_callback_file_recv(&tox, CoreFile::onFileReceiveCallback); - tox_callback_file_recv_chunk(&tox, CoreFile::onFileRecvChunkCallback); - tox_callback_file_recv_control(&tox, CoreFile::onFileControlCallback); -} - void CoreFile::sendAvatarFile(uint32_t friendId, const QByteArray& data) { const QMutexLocker locker{coreLoopLock}; @@ -316,12 +305,15 @@ QString CoreFile::getCleanFileName(QString filename) return filename; } -void CoreFile::onFileReceiveCallback(Tox* tox, uint32_t friendId, uint32_t fileId, uint32_t kind, - uint64_t filesize, const uint8_t* fname, size_t fnameLen, - void* vCore) +void CoreFile::onFileRecv(const Tox_Event_File_Recv* event, Core* core) { - Core* core = static_cast(vCore); CoreFile* coreFile = core->getCoreFile(); + const uint32_t friendId = tox_event_file_recv_get_friend_number(event); + const uint32_t fileId = tox_event_file_recv_get_file_number(event); + const uint32_t kind = tox_event_file_recv_get_kind(event); + const uint64_t filesize = tox_event_file_recv_get_file_size(event); + const uint8_t* fname = tox_event_file_recv_get_filename(event); + const size_t fnameLen = tox_event_file_recv_get_filename_length(event); auto filename = ToxString(fname, fnameLen); const ToxPk friendPk = core->getFriendPublicKey(friendId); @@ -330,7 +322,7 @@ void CoreFile::onFileReceiveCallback(Tox* tox, uint32_t friendId, uint32_t fileI qDebug("Received empty avatar request %d:%d", friendId, fileId); // Avatars of size 0 means explicitly no avatar Tox_Err_File_Control err; - tox_file_control(tox, friendId, fileId, TOX_FILE_CONTROL_CANCEL, &err); + tox_file_control(core->getTox(), friendId, fileId, TOX_FILE_CONTROL_CANCEL, &err); PARSE_ERR(err); emit core->friendAvatarRemoved(core->getFriendPublicKey(friendId)); return; @@ -341,14 +333,14 @@ void CoreFile::onFileReceiveCallback(Tox* tox, uint32_t friendId, uint32_t fileI friendId, static_cast(filesize), static_cast(ToxClientStandards::MaxAvatarSize)); Tox_Err_File_Control err; - tox_file_control(tox, friendId, fileId, TOX_FILE_CONTROL_CANCEL, &err); + tox_file_control(core->getTox(), friendId, fileId, TOX_FILE_CONTROL_CANCEL, &err); PARSE_ERR(err); return; } Q_ASSERT(tox_hash_length() <= tox_file_id_length()); std::vector avatarHash(tox_file_id_length()); Tox_Err_File_Get fileGetErr; - tox_file_get_file_id(tox, friendId, fileId, avatarHash.data(), &fileGetErr); + tox_file_get_file_id(core->getTox(), friendId, fileId, avatarHash.data(), &fileGetErr); if (!PARSE_ERR(fileGetErr)) { return; } @@ -373,7 +365,7 @@ void CoreFile::onFileReceiveCallback(Tox* tox, uint32_t friendId, uint32_t fileI file.fileKind = kind; file.resumeFileId.resize(tox_file_id_length()); Tox_Err_File_Get fileGetErr; - tox_file_get_file_id(tox, friendId, fileId, + tox_file_get_file_id(core->getTox(), friendId, fileId, reinterpret_cast(file.resumeFileId.data()), &fileGetErr); if (!PARSE_ERR(fileGetErr)) { return; @@ -416,15 +408,15 @@ void CoreFile::handleAvatarOffer(uint32_t friendId, uint32_t fileId, bool accept addFile(friendId, fileId, file); } -void CoreFile::onFileControlCallback(Tox* tox, uint32_t friendId, uint32_t fileId, - Tox_File_Control control, void* vCore) +void CoreFile::onFileRecvControl(const Tox_Event_File_Recv_Control* event, Core* core) { - std::ignore = tox; - Core* core = static_cast(vCore); CoreFile* coreFile = core->getCoreFile(); + const uint32_t friendId = tox_event_file_recv_control_get_friend_number(event); + const uint32_t fileId = tox_event_file_recv_control_get_file_number(event); + const Tox_File_Control control = tox_event_file_recv_control_get_control(event); ToxFile* file = coreFile->findFile(friendId, fileId); if (!file) { - qWarning("onFileControlCallback: No such file in queue"); + qWarning("onFileRecvControl: No such file in queue"); return; } @@ -435,7 +427,7 @@ void CoreFile::onFileControlCallback(Tox* tox, uint32_t friendId, uint32_t fileI emit coreFile->fileTransferCancelled(*file); coreFile->removeFile(friendId, fileId); } else if (control == TOX_FILE_CONTROL_PAUSE) { - qDebug() << "onFileControlCallback: Received pause for file" << friendId << ":" << fileId; + qDebug() << "onFileRecvControl: Received pause for file" << friendId << ":" << fileId; file->pauseStatus.remotePause(); file->status = ToxFile::PAUSED; emit coreFile->fileTransferRemotePausedUnpaused(*file, true); @@ -443,7 +435,7 @@ void CoreFile::onFileControlCallback(Tox* tox, uint32_t friendId, uint32_t fileI if (file->direction == ToxFile::SENDING && file->fileKind == TOX_FILE_KIND_AVATAR) qDebug() << "Avatar transfer" << fileId << "to friend" << friendId << "accepted"; else - qDebug() << "onFileControlCallback: Received resume for file" << friendId << ":" << fileId; + qDebug() << "onFileRecvControl: Received resume for file" << friendId << ":" << fileId; file->pauseStatus.remoteResume(); file->status = file->pauseStatus.paused() ? ToxFile::PAUSED : ToxFile::TRANSMITTING; emit coreFile->fileTransferRemotePausedUnpaused(*file, false); @@ -452,15 +444,16 @@ void CoreFile::onFileControlCallback(Tox* tox, uint32_t friendId, uint32_t fileI } } -void CoreFile::onFileDataCallback(Tox* tox, uint32_t friendId, uint32_t fileId, uint64_t pos, - size_t length, void* vCore) +void CoreFile::onFileChunkRequest(const Tox_Event_File_Chunk_Request* event, Core* core) { - - Core* core = static_cast(vCore); CoreFile* coreFile = core->getCoreFile(); + const uint32_t friendId = tox_event_file_chunk_request_get_friend_number(event); + const uint32_t fileId = tox_event_file_chunk_request_get_file_number(event); + const uint64_t pos = tox_event_file_chunk_request_get_position(event); + const size_t length = tox_event_file_chunk_request_get_length(event); ToxFile* file = coreFile->findFile(friendId, fileId); if (!file) { - qWarning("onFileDataCallback: No such file in queue"); + qWarning("onFileChunkRequest: No such file in queue"); return; } @@ -485,11 +478,11 @@ void CoreFile::onFileDataCallback(Tox* tox, uint32_t friendId, uint32_t fileId, file->file->seek(pos); nread = file->file->read(reinterpret_cast(data.get()), length); if (nread <= 0) { - qWarning("onFileDataCallback: Failed to read from file"); + qWarning("onFileChunkRequest: Failed to read from file"); file->status = ToxFile::CANCELED; emit coreFile->fileTransferCancelled(*file); Tox_Err_File_Send_Chunk err; - tox_file_send_chunk(tox, friendId, fileId, pos, nullptr, 0, &err); + tox_file_send_chunk(core->getTox(), friendId, fileId, pos, nullptr, 0, &err); PARSE_ERR(err); coreFile->removeFile(friendId, fileId); return; @@ -504,7 +497,7 @@ void CoreFile::onFileDataCallback(Tox* tox, uint32_t friendId, uint32_t fileId, } Tox_Err_File_Send_Chunk err; - tox_file_send_chunk(tox, friendId, fileId, pos, data.get(), nread, &err); + tox_file_send_chunk(core->getTox(), friendId, fileId, pos, data.get(), nread, &err); if (!PARSE_ERR(err)) { return; } @@ -513,28 +506,31 @@ void CoreFile::onFileDataCallback(Tox* tox, uint32_t friendId, uint32_t fileId, } } -void CoreFile::onFileRecvChunkCallback(Tox* tox, uint32_t friendId, uint32_t fileId, uint64_t position, - const uint8_t* data, size_t length, void* vCore) +void CoreFile::onFileRecvChunk(const Tox_Event_File_Recv_Chunk* event, Core* core) { - Core* core = static_cast(vCore); CoreFile* coreFile = core->getCoreFile(); + const uint32_t friendId = tox_event_file_recv_chunk_get_friend_number(event); + const uint32_t fileId = tox_event_file_recv_chunk_get_file_number(event); + const uint64_t position = tox_event_file_recv_chunk_get_position(event); + const uint8_t* data = tox_event_file_recv_chunk_get_data(event); + const size_t length = tox_event_file_recv_chunk_get_data_length(event); ToxFile* file = coreFile->findFile(friendId, fileId); if (!file) { - qWarning("onFileRecvChunkCallback: No such file in queue"); + qWarning("onFileRecvChunk: No such file in queue"); Tox_Err_File_Control err; - tox_file_control(tox, friendId, fileId, TOX_FILE_CONTROL_CANCEL, &err); + tox_file_control(core->getTox(), friendId, fileId, TOX_FILE_CONTROL_CANCEL, &err); PARSE_ERR(err); return; } if (file->progress.getBytesSent() != position) { - qWarning("onFileRecvChunkCallback: Received a chunk out-of-order, aborting transfer"); + qWarning("onFileRecvChunk: Received a chunk out-of-order, aborting transfer"); if (file->fileKind != TOX_FILE_KIND_AVATAR) { file->status = ToxFile::CANCELED; emit coreFile->fileTransferCancelled(*file); } Tox_Err_File_Control err; - tox_file_control(tox, friendId, fileId, TOX_FILE_CONTROL_CANCEL, &err); + tox_file_control(core->getTox(), friendId, fileId, TOX_FILE_CONTROL_CANCEL, &err); PARSE_ERR(err); coreFile->removeFile(friendId, fileId); return; diff --git a/src/core/corefile.h b/src/core/corefile.h index a4223c53a6..9da905ac01 100644 --- a/src/core/corefile.h +++ b/src/core/corefile.h @@ -6,8 +6,6 @@ #pragma once -#include // Tox_File_Control - #include "toxfile.h" #include "src/core/toxpk.h" #include "src/model/status.h" @@ -17,11 +15,15 @@ #include #include -#include #include #include struct Tox; +struct Tox_Event_File_Recv; +struct Tox_Event_File_Recv_Control; +struct Tox_Event_File_Chunk_Request; +struct Tox_Event_File_Recv_Chunk; +struct Tox_Dispatch; class Core; class CoreFile; @@ -31,6 +33,8 @@ class CoreFile : public QObject { Q_OBJECT + friend class Core; + public: void handleAvatarOffer(uint32_t friendId, uint32_t fileId, bool accept, uint64_t filesize); static CoreFilePtr makeCoreFile(Core* core, Tox* tox, QRecursiveMutex& coreLoopLock); @@ -70,16 +74,10 @@ class CoreFile : public QObject return (static_cast(friendId) << 32) + fileId; } - static void connectCallbacks(Tox& tox); - static void onFileReceiveCallback(Tox* tox, uint32_t friendId, uint32_t fileId, uint32_t kind, - uint64_t filesize, const uint8_t* fname, size_t fnameLen, - void* vCore); - static void onFileControlCallback(Tox* tox, uint32_t friendId, uint32_t fileId, - Tox_File_Control control, void* vCore); - static void onFileDataCallback(Tox* tox, uint32_t friendId, uint32_t fileId, uint64_t pos, - size_t length, void* vCore); - static void onFileRecvChunkCallback(Tox* tox, uint32_t friendId, uint32_t fileId, uint64_t position, - const uint8_t* data, size_t length, void* vCore); + static void onFileRecv(const Tox_Event_File_Recv* event, Core* core); + static void onFileRecvControl(const Tox_Event_File_Recv_Control* event, Core* core); + static void onFileChunkRequest(const Tox_Event_File_Chunk_Request* event, Core* core); + static void onFileRecvChunk(const Tox_Event_File_Recv_Chunk* event, Core* core); static QString getCleanFileName(QString filename); diff --git a/src/model/conferenceinvite.cpp b/src/model/conferenceinvite.cpp index b7bed39b0a..2c813cbf19 100644 --- a/src/model/conferenceinvite.cpp +++ b/src/model/conferenceinvite.cpp @@ -13,7 +13,7 @@ * @brief This class contains information needed to create a conference invite */ -ConferenceInvite::ConferenceInvite(uint32_t friendId_, uint8_t inviteType, QByteArray data) +ConferenceInvite::ConferenceInvite(uint32_t friendId_, ConferenceType inviteType, QByteArray data) : friendId{friendId_} , type{inviteType} , invite{std::move(data)} @@ -32,7 +32,7 @@ uint32_t ConferenceInvite::getFriendId() const return friendId; } -uint8_t ConferenceInvite::getType() const +ConferenceType ConferenceInvite::getType() const { return type; } diff --git a/src/model/conferenceinvite.h b/src/model/conferenceinvite.h index d15396fa64..0e6aa33c79 100644 --- a/src/model/conferenceinvite.h +++ b/src/model/conferenceinvite.h @@ -5,6 +5,8 @@ #pragma once +#include "src/core/conferencetype.h" + #include #include #include @@ -13,17 +15,17 @@ class ConferenceInvite { public: ConferenceInvite() = default; - ConferenceInvite(uint32_t friendId_, uint8_t inviteType, QByteArray data); + ConferenceInvite(uint32_t friendId_, ConferenceType inviteType, QByteArray data); bool operator==(const ConferenceInvite& other) const; uint32_t getFriendId() const; - uint8_t getType() const; + ConferenceType getType() const; QByteArray getInvite() const; QDateTime getInviteDate() const; private: uint32_t friendId{0}; - uint8_t type{0}; + ConferenceType type{ConferenceType::TEXT}; QByteArray invite; QDateTime date; }; diff --git a/src/persistence/profile.cpp b/src/persistence/profile.cpp index b9be5ba8a4..844f4f6c4a 100644 --- a/src/persistence/profile.cpp +++ b/src/persistence/profile.cpp @@ -14,6 +14,7 @@ #include #include #include +#include // tox_public_key_size #include #include "profile.h" diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 20d34c7b97..1369c8c414 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -46,6 +46,7 @@ #include #include +#include // tox_max_message_length #include /** diff --git a/src/widget/form/conferenceinviteform.cpp b/src/widget/form/conferenceinviteform.cpp index d4596099d7..4531dd10d2 100644 --- a/src/widget/form/conferenceinviteform.cpp +++ b/src/widget/form/conferenceinviteform.cpp @@ -42,7 +42,7 @@ ConferenceInviteForm::ConferenceInviteForm(Settings& settings_, Core& core_) { QVBoxLayout* layout = new QVBoxLayout(this); connect(createButton, &QPushButton::clicked, this, - [this]() { emit conferenceCreate(TOX_CONFERENCE_TYPE_AV); }); + [this]() { emit conferenceCreate(ConferenceType::AV); }); QWidget* innerWidget = new QWidget(scroll); innerWidget->setLayout(new QVBoxLayout()); diff --git a/src/widget/form/conferenceinviteform.h b/src/widget/form/conferenceinviteform.h index 0d22abbbc7..672b5e0086 100644 --- a/src/widget/form/conferenceinviteform.h +++ b/src/widget/form/conferenceinviteform.h @@ -7,6 +7,8 @@ #include +#include "src/core/conferencetype.h" + class ContentLayout; class ConferenceInvite; class ConferenceInviteWidget; @@ -35,7 +37,7 @@ class ConferenceInviteForm : public QWidget bool isShown() const; signals: - void conferenceCreate(uint8_t type); + void conferenceCreate(ConferenceType type); void conferenceInviteAccepted(const ConferenceInvite& inviteInfo); void conferenceInvitesSeen(); diff --git a/src/widget/form/filesform.cpp b/src/widget/form/filesform.cpp index dd5003db85..e769a3d60d 100644 --- a/src/widget/form/filesform.cpp +++ b/src/widget/form/filesform.cpp @@ -25,6 +25,8 @@ #include #include +#include // TOX_FILE_KIND + namespace { QRect pauseRect(const QStyleOptionViewItem& option) { diff --git a/src/widget/form/profileform.cpp b/src/widget/form/profileform.cpp index 871b44b573..b59b77de6d 100644 --- a/src/widget/form/profileform.cpp +++ b/src/widget/form/profileform.cpp @@ -35,6 +35,8 @@ #include #include +#include // tox_max_name_length + namespace { const QMap SET_AVATAR_ERROR = { {IProfileInfo::SetAvatarResult::CanNotOpen, ProfileForm::tr("Unable to open this file.")}, diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 111dd71382..d7a275b1d2 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -6,6 +6,7 @@ #include "widget.h" #include +#include // TOX_CONFERENCE_TYPE_TEXT #include #include @@ -1938,8 +1939,8 @@ void Widget::onConferenceInviteReceived(const ConferenceInvite& inviteInfo) const Friend* f = friendList->findFriend(friendPk); updateFriendActivity(*f); - const uint8_t confType = inviteInfo.getType(); - if (confType == TOX_CONFERENCE_TYPE_TEXT || confType == TOX_CONFERENCE_TYPE_AV) { + const ConferenceType confType = inviteInfo.getType(); + if (confType == ConferenceType::TEXT || confType == ConferenceType::AV) { if (settings.getAutoConferenceInvite(f->getPublicKey())) { onConferenceInviteAccepted(inviteInfo); } else { @@ -1956,7 +1957,7 @@ void Widget::onConferenceInviteReceived(const ConferenceInvite& inviteInfo) } } } else { - qWarning() << "onConferenceInviteReceived: Unknown conference type:" << confType; + qWarning() << "onConferenceInviteReceived: Unknown conference type"; return; } } diff --git a/util/include/util/toxcoreerrorparser.h b/util/include/util/toxcoreerrorparser.h index 60c841bcce..ccc9676929 100644 --- a/util/include/util/toxcoreerrorparser.h +++ b/util/include/util/toxcoreerrorparser.h @@ -8,6 +8,7 @@ #include #include +#include #include /** @@ -46,4 +47,5 @@ bool parseErr(Toxav_Err_Bit_Rate_Set error, const char* file, int line, const ch bool parseErr(Toxav_Err_Call_Control error, const char* file, int line, const char* func); bool parseErr(Toxav_Err_Call error, const char* file, int line, const char* func); bool parseErr(Tox_Err_Options_New error, const char* file, int line, const char* func); +bool parseErr(Tox_Err_Events_Iterate error, const char* file, int line, const char* func); } // namespace ToxcoreErrorParser diff --git a/util/src/toxcoreerrorparser.cpp b/util/src/toxcoreerrorparser.cpp index 1ecc2853b6..aa0c961206 100644 --- a/util/src/toxcoreerrorparser.cpp +++ b/util/src/toxcoreerrorparser.cpp @@ -685,3 +685,18 @@ bool ToxcoreErrorParser::parseErr(Tox_Err_Options_New error, const char* file, i qCriticalFrom(file, line, func) << "Unknown Tox_Err_Options_New error code:" << error; return false; } + +bool ToxcoreErrorParser::parseErr(Tox_Err_Events_Iterate error, const char* file, int line, + const char* func) +{ + switch (error) { + case TOX_ERR_EVENTS_ITERATE_OK: + return true; + + case TOX_ERR_EVENTS_ITERATE_MALLOC: + qCriticalFrom(file, line, func) << ": Failed to allocate memory"; + return false; + } + qCriticalFrom(file, line, func) << "Unknown Tox_Err_Events_Iterate error code:" << error; + return false; +}