From 228398d5de5c84f020e912c8fa27d32f3d77a225 Mon Sep 17 00:00:00 2001 From: tux3 Date: Sun, 19 Apr 2015 23:12:44 +0200 Subject: [PATCH] Initial porting to the new Tox API Builds and runs, but some features will be missing, may crash with an assert, or silently fail with broken QObject connections We're back in the game. --- src/core.cpp | 448 ++++++++++++++++-------------- src/core.h | 132 ++++----- src/coreav.cpp | 42 +-- src/coreav.h | 4 +- src/coreencryption.cpp | 68 +++-- src/corestructs.cpp | 6 +- src/corestructs.h | 6 +- src/friend.cpp | 4 +- src/friend.h | 6 +- src/friendlist.h | 2 +- src/group.h | 2 +- src/misc/cdata.cpp | 2 +- src/misc/db/encrypteddb.cpp | 2 +- src/nexus.cpp | 5 +- src/offlinemsgengine.h | 2 +- src/toxdns.cpp | 8 +- src/widget/form/chatform.cpp | 34 +-- src/widget/form/chatform.h | 39 ++- src/widget/form/genericchatform.h | 4 +- src/widget/form/profileform.cpp | 17 +- src/widget/friendlistwidget.cpp | 2 +- src/widget/friendlistwidget.h | 2 +- src/widget/widget.cpp | 31 +-- src/widget/widget.h | 6 +- 24 files changed, 446 insertions(+), 428 deletions(-) diff --git a/src/core.cpp b/src/core.cpp index b407ee2f3..2269039e1 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -133,7 +134,7 @@ Core* Core::getInstance() return Nexus::getCore(); } -void Core::make_tox() +void Core::make_tox(QByteArray savedata) { // IPv6 needed for LAN discovery, but can crash some weird routers. On by default, can be disabled in options. bool enableIPv6 = Settings::getInstance().getEnableIPv6(); @@ -146,12 +147,12 @@ void Core::make_tox() qWarning() << "Core starting with IPv6 disabled. LAN discovery may not work properly."; Tox_Options toxOptions; - toxOptions.ipv6enabled = enableIPv6; - toxOptions.udp_disabled = forceTCP; + toxOptions.ipv6_enabled = enableIPv6; + toxOptions.udp_enabled = !forceTCP; // No proxy by default - toxOptions.proxy_type = TOX_PROXY_NONE; - toxOptions.proxy_address[0] = 0; + toxOptions.proxy_type = TOX_PROXY_TYPE_NONE; + toxOptions.proxy_host = nullptr; toxOptions.proxy_port = 0; if (proxyType != ProxyType::ptNone) @@ -168,25 +169,28 @@ void Core::make_tox() qDebug() << "Core: using proxy" << proxyAddr << ":" << proxyPort; // protection against changings in TOX_PROXY_TYPE enum if (proxyType == ProxyType::ptSOCKS5) - toxOptions.proxy_type = TOX_PROXY_SOCKS5; + toxOptions.proxy_type = TOX_PROXY_TYPE_SOCKS5; else if (proxyType == ProxyType::ptHTTP) - toxOptions.proxy_type = TOX_PROXY_HTTP; - uint16_t sz = CString::fromString(proxyAddr, (unsigned char*)toxOptions.proxy_address); - toxOptions.proxy_address[sz] = 0; + toxOptions.proxy_type = TOX_PROXY_TYPE_HTTP; + QByteArray proxyAddrData = proxyAddr.toUtf8(); + /// TODO: We're leaking a tiny amount of memory there, go fix that later + char* proxyAddrCopy = new char[proxyAddrData.size()+1]; + memcpy(proxyAddrCopy, proxyAddrData.data(), proxyAddrData.size()+1); + toxOptions.proxy_host = proxyAddrCopy; toxOptions.proxy_port = proxyPort; } } - tox = tox_new(&toxOptions); + tox = tox_new(&toxOptions, (uint8_t*)savedata.data(), savedata.size(), nullptr); if (tox == nullptr) { if (enableIPv6) // Fallback to IPv4 { - toxOptions.ipv6enabled = false; - tox = tox_new(&toxOptions); + toxOptions.ipv6_enabled = false; + tox = tox_new(&toxOptions, (uint8_t*)savedata.data(), savedata.size(), nullptr); if (tox == nullptr) { - if (toxOptions.proxy_type != TOX_PROXY_NONE) + if (toxOptions.proxy_type != TOX_PROXY_TYPE_NONE) { qCritical() << "Core: bad proxy! no toxcore!"; emit badProxy(); @@ -201,7 +205,7 @@ void Core::make_tox() else qWarning() << "Core failed to start with IPv6, falling back to IPv4. LAN discovery may not work properly."; } - else if (toxOptions.proxy_type != TOX_PROXY_NONE) + else if (toxOptions.proxy_type != TOX_PROXY_TYPE_NONE) { emit badProxy(); return; @@ -227,29 +231,33 @@ void Core::start() { qDebug() << "Core: Starting up"; - make_tox(); + QByteArray savedata = loadToxSave(loadPath); + + make_tox(savedata); qsrand(time(nullptr)); - if (loadPath != "") + /** TODO: Review this mess. Actually rewrite it all + * I have no idea what the whole fooling around with loadPath bussiness means anymore. + * Let's write something clear that doesn't rely on magic global state instead + * We need to: 1) Find a qTox profile, create if needed 2) Find a tox save, decrypt/create if needed + * Not sure about the order tho. Look into this. + if (true) { - while (!loadConfiguration(loadPath)) + if (loadPath.isEmpty()) { - if (loadPath.isEmpty()) + QString profile; + if ((profile = loadOldInformation()).isEmpty()) { - QString profile; - if ((profile = loadOldInformation()).isEmpty()) - { - qCritical() << "Core: loadConfiguration failed, exiting now"; - emit failedToStart(); - return; - } - else - { - loadPath = QDir(Settings::getSettingsDirPath()).filePath(profile + TOX_EXT); - Settings::getInstance().switchProfile(profile); - HistoryKeeper::resetInstance(); // I'm not actually sure if this is necessary - } + qCritical() << "Core: loadConfiguration failed, exiting now"; + emit failedToStart(); + return; + } + else + { + loadPath = QDir(Settings::getSettingsDirPath()).filePath(profile + TOX_EXT); + Settings::getInstance().switchProfile(profile); + HistoryKeeper::resetInstance(); // I'm not actually sure if this is necessary } } // loadPath is meaningless after this @@ -263,26 +271,45 @@ void Core::start() setStatusMessage(tr("Toxing on qTox")); // this also solves the not updating issue setUsername(tr("qTox User")); } + */ + + // set GUI with user and statusmsg + QString name = getUsername(); + if (!name.isEmpty()) + emit usernameSet(name); + + QString msg = getStatusMessage(); + if (!msg.isEmpty()) + emit statusMessageSet(msg); + + QString id = getSelfId().toString(); + if (!id.isEmpty()) + emit idSet(id); + + // tox core is already decrypted + if (Settings::getInstance().getEnableLogging() && Settings::getInstance().getEncryptLogs()) + checkEncryptedHistory(); + + loadFriends(); tox_callback_friend_request(tox, onFriendRequest, this); tox_callback_friend_message(tox, onFriendMessage, this); - tox_callback_friend_action(tox, onAction, this); - tox_callback_name_change(tox, onFriendNameChange, this); - tox_callback_typing_change(tox, onFriendTypingChange, this); - tox_callback_status_message(tox, onStatusMessageChanged, this); - tox_callback_user_status(tox, onUserStatusChanged, this); - tox_callback_connection_status(tox, onConnectionStatusChanged, this); + tox_callback_friend_name(tox, onFriendNameChange, this); + tox_callback_friend_typing(tox, onFriendTypingChange, this); + tox_callback_friend_status_message(tox, onStatusMessageChanged, this); + tox_callback_friend_status(tox, onUserStatusChanged, this); + tox_callback_friend_connection_status(tox, onConnectionStatusChanged, this); tox_callback_group_invite(tox, onGroupInvite, this); tox_callback_group_message(tox, onGroupMessage, this); tox_callback_group_namelist_change(tox, onGroupNamelistChange, this); tox_callback_group_title(tox, onGroupTitleChange, this); tox_callback_group_action(tox, onGroupAction, this); - tox_callback_file_send_request(tox, onFileSendRequestCallback, this); - tox_callback_file_control(tox, onFileControlCallback, this); - tox_callback_file_data(tox, onFileDataCallback, this); - tox_callback_avatar_info(tox, onAvatarInfoCallback, this); - tox_callback_avatar_data(tox, onAvatarDataCallback, this); - tox_callback_read_receipt(tox, onReadReceiptCallback, this); + //tox_callback_file_send_request(tox, onFileSendRequestCallback, this); + //tox_callback_file_control(tox, onFileControlCallback, this); + //tox_callback_file_data(tox, onFileDataCallback, this); + //tox_callback_avatar_info(tox, onAvatarInfoCallback, this); + //tox_callback_avatar_data(tox, onAvatarDataCallback, this); + tox_callback_friend_read_receipt(tox, onReadReceiptCallback, this); toxav_register_callstate_callback(toxav, onAvInvite, av_OnInvite, this); toxav_register_callstate_callback(toxav, onAvStart, av_OnStart, this); @@ -306,7 +333,7 @@ void Core::start() buffer.open(QIODevice::WriteOnly); pic.save(&buffer, "PNG"); buffer.close(); - setAvatar(TOX_AVATAR_FORMAT_PNG, data); + setAvatar(data); } else qDebug() << "Core: Error loading self avatar"; @@ -331,7 +358,7 @@ void Core::process() return; static int tolerance = CORE_DISCONNECT_TOLERANCE; - tox_do(tox); + tox_iterate(tox); toxav_do(toxav); #ifdef DEBUG @@ -347,14 +374,14 @@ void Core::process() tolerance = 3*CORE_DISCONNECT_TOLERANCE; } - toxTimer->start(qMin(tox_do_interval(tox), toxav_do_interval(toxav))); + toxTimer->start(qMin(tox_iteration_interval(tox), toxav_do_interval(toxav))); } bool Core::checkConnection() { static bool isConnected = false; //static int count = 0; - bool toxConnected = tox_isconnected(tox); + bool toxConnected = tox_self_get_connection_status(tox) != TOX_CONNECTION_NONE; if (toxConnected && !isConnected) { qDebug() << "Core: Connected to DHT"; @@ -390,8 +417,8 @@ void Core::bootstrapDht() while (i < 2) // i think the more we bootstrap, the more we jitter because the more we overwrite nodes { const Settings::DhtServer& dhtServer = dhtServerList[j % listSize]; - if (tox_bootstrap_from_address(tox, dhtServer.address.toLatin1().data(), - dhtServer.port, CUserId(dhtServer.userId).data()) == 1) + if (tox_bootstrap(tox, dhtServer.address.toLatin1().data(), + dhtServer.port, CUserId(dhtServer.userId).data(), nullptr) == 1) qDebug() << QString("Core: Bootstrapping from ")+dhtServer.name+QString(", addr ")+dhtServer.address.toLatin1().data() +QString(", port ")+QString().setNum(dhtServer.port); else @@ -402,42 +429,47 @@ void Core::bootstrapDht() } } -void Core::onFriendRequest(Tox*/* tox*/, const uint8_t* cUserId, const uint8_t* cMessage, uint16_t cMessageSize, void* core) +void Core::onFriendRequest(Tox*/* tox*/, const uint8_t* cUserId, + const uint8_t* cMessage, size_t cMessageSize, void* core) { - emit static_cast(core)->friendRequestReceived(CUserId::toString(cUserId), CString::toString(cMessage, cMessageSize)); + emit static_cast(core)->friendRequestReceived(CUserId::toString(cUserId), + CString::toString(cMessage, cMessageSize)); } -void Core::onFriendMessage(Tox*/* tox*/, int friendId, const uint8_t* cMessage, uint16_t cMessageSize, void* core) +void Core::onFriendMessage(Tox*/* tox*/, uint32_t friendId, TOX_MESSAGE_TYPE type, + const uint8_t* cMessage, size_t cMessageSize, void* core) { - emit static_cast(core)->friendMessageReceived(friendId, CString::toString(cMessage, cMessageSize), false); + emit static_cast(core)->friendMessageReceived(friendId,CString::toString(cMessage, cMessageSize), false); } -void Core::onFriendNameChange(Tox*/* tox*/, int friendId, const uint8_t* cName, uint16_t cNameSize, void* core) +void Core::onFriendNameChange(Tox*/* tox*/, uint32_t friendId, + const uint8_t* cName, size_t cNameSize, void* core) { emit static_cast(core)->friendUsernameChanged(friendId, CString::toString(cName, cNameSize)); } -void Core::onFriendTypingChange(Tox*/* tox*/, int friendId, uint8_t isTyping, void *core) +void Core::onFriendTypingChange(Tox*/* tox*/, uint32_t friendId, bool isTyping, void *core) { emit static_cast(core)->friendTypingChanged(friendId, isTyping ? true : false); } -void Core::onStatusMessageChanged(Tox*/* tox*/, int friendId, const uint8_t* cMessage, uint16_t cMessageSize, void* core) +void Core::onStatusMessageChanged(Tox*/* tox*/, uint32_t friendId, const uint8_t* cMessage, + size_t cMessageSize, void* core) { emit static_cast(core)->friendStatusMessageChanged(friendId, CString::toString(cMessage, cMessageSize)); } -void Core::onUserStatusChanged(Tox*/* tox*/, int friendId, uint8_t userstatus, void* core) +void Core::onUserStatusChanged(Tox*/* tox*/, uint32_t friendId, TOX_USER_STATUS userstatus, void* core) { Status status; switch (userstatus) { - case TOX_USERSTATUS_NONE: + case TOX_USER_STATUS_NONE: status = Status::Online; break; - case TOX_USERSTATUS_AWAY: + case TOX_USER_STATUS_AWAY: status = Status::Away; break; - case TOX_USERSTATUS_BUSY: + case TOX_USER_STATUS_BUSY: status = Status::Busy; break; default: @@ -445,13 +477,10 @@ void Core::onUserStatusChanged(Tox*/* tox*/, int friendId, uint8_t userstatus, v break; } - if (status == Status::Online || status == Status::Away) - tox_request_avatar_info(static_cast(core)->tox, friendId); - emit static_cast(core)->friendStatusChanged(friendId, status); } -void Core::onConnectionStatusChanged(Tox*/* tox*/, int friendId, uint8_t status, void* core) +void Core::onConnectionStatusChanged(Tox*/* tox*/, uint32_t friendId, TOX_CONNECTION status, void* core) { Status friendStatus = status ? Status::Online : Status::Offline; emit static_cast(core)->friendStatusChanged(friendId, friendStatus); @@ -480,36 +509,31 @@ void Core::onConnectionStatusChanged(Tox*/* tox*/, int friendId, uint8_t status, if (f.friendId == friendId && f.status == ToxFile::BROKEN) { qDebug() << QString("Core::onConnectionStatusChanged: %1: resuming broken filetransfer from position: %2").arg(f.file->fileName()).arg(f.bytesSent); - tox_file_send_control(static_cast(core)->tox, friendId, 1, f.fileNum, TOX_FILECONTROL_RESUME_BROKEN, reinterpret_cast(&f.bytesSent), sizeof(uint64_t)); + tox_file_control(static_cast(core)->tox, friendId, f.fileNum, TOX_FILE_CONTROL_RESUME, nullptr); emit static_cast(core)->fileTransferBrokenUnbroken(f, false); } } } } -void Core::onAction(Tox*/* tox*/, int friendId, const uint8_t *cMessage, uint16_t cMessageSize, void *core) -{ - emit static_cast(core)->friendMessageReceived(friendId, CString::toString(cMessage, cMessageSize), true); -} - void Core::onGroupAction(Tox*, int groupnumber, int peernumber, const uint8_t *action, uint16_t length, void* _core) { Core* core = static_cast(_core); emit core->groupMessageReceived(groupnumber, peernumber, CString::toString(action, length), true); } -void Core::onGroupInvite(Tox*, int friendnumber, uint8_t type, const uint8_t *data, uint16_t length,void *core) +void Core::onGroupInvite(Tox*, int32_t friendNumber, uint8_t type, const uint8_t *data, uint16_t length,void *core) { QByteArray pk((char*)data, length); if (type == TOX_GROUPCHAT_TYPE_TEXT) { - qDebug() << QString("Core: Text group invite by %1").arg(friendnumber); - emit static_cast(core)->groupInviteReceived(friendnumber,type,pk); + qDebug() << QString("Core: Text group invite by %1").arg(friendNumber); + emit static_cast(core)->groupInviteReceived(friendNumber,type,pk); } else if (type == TOX_GROUPCHAT_TYPE_AV) { - qDebug() << QString("Core: AV group invite by %1").arg(friendnumber); - emit static_cast(core)->groupInviteReceived(friendnumber,type,pk); + qDebug() << QString("Core: AV group invite by %1").arg(friendNumber); + emit static_cast(core)->groupInviteReceived(friendNumber,type,pk); } else { @@ -539,7 +563,7 @@ void Core::onGroupTitleChange(Tox*, int groupnumber, int peernumber, const uint8 emit core->groupTitleChanged(groupnumber, author, CString::toString(title, len)); } -void Core::onFileSendRequestCallback(Tox*, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, +void Core::onFileSendRequestCallback(Tox*, uint32_t friendnumber, uint8_t filenumber, uint64_t filesize, const uint8_t *filename, uint16_t filename_length, void *core) { qDebug() << QString("Core: Received file request %1 with friend %2").arg(filenumber).arg(friendnumber); @@ -550,7 +574,7 @@ void Core::onFileSendRequestCallback(Tox*, int32_t friendnumber, uint8_t filenum fileRecvQueue.append(file); emit static_cast(core)->fileReceiveRequested(fileRecvQueue.last()); } -void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber, +void Core::onFileControlCallback(Tox* tox, uint32_t friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type, const uint8_t* data, uint16_t length, void *core) { ToxFile* file{nullptr}; @@ -581,7 +605,7 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive qWarning("Core::onFileControlCallback: No such file in queue"); return; } - if (receive_send == 1 && control_type == TOX_FILECONTROL_ACCEPT) + if (receive_send == 1 && control_type == TOX_FILE_CONTROL_RESUME) { file->status = ToxFile::TRANSMITTING; emit static_cast(core)->fileTransferAccepted(*file); @@ -591,7 +615,7 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive file->sendTimer->setSingleShot(true); file->sendTimer->start(TOX_FILE_INTERVAL); } - else if (receive_send == 1 && control_type == TOX_FILECONTROL_KILL) + else if (receive_send == 1 && control_type == TOX_FILE_CONTROL_CANCEL) { qDebug() << QString("Core::onFileControlCallback: Transfer of file %1 cancelled by friend %2") .arg(file->fileNum).arg(file->friendId); @@ -610,7 +634,7 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive } removeFileFromQueue((bool)receive_send, file->friendId, file->fileNum); } - else if (receive_send == 1 && control_type == TOX_FILECONTROL_FINISHED) + else if (receive_send == 1 && false /* && control_type == TOX_FILECONTROL_FINISHED*/ ) ///TODO: FIXME: Detect finished transfers { qDebug() << QString("Core::onFileControlCallback: Transfer of file %1 to friend %2 is complete") .arg(file->fileNum).arg(file->friendId); @@ -618,7 +642,7 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive emit static_cast(core)->fileTransferFinished(*file); removeFileFromQueue((bool)receive_send, file->friendId, file->fileNum); } - else if (receive_send == 0 && control_type == TOX_FILECONTROL_KILL) + else if (receive_send == 0 && control_type == TOX_FILE_CONTROL_CANCEL) { qDebug() << QString("Core::onFileControlCallback: Transfer of file %1 cancelled by friend %2") .arg(file->fileNum).arg(file->friendId); @@ -626,17 +650,17 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive emit static_cast(core)->fileTransferCancelled(*file); removeFileFromQueue((bool)receive_send, file->friendId, file->fileNum); } - else if (receive_send == 0 && control_type == TOX_FILECONTROL_FINISHED) + else if (receive_send == 0 && false /* && control_type == TOX_FILECONTROL_FINISHED*/ ) ///TODO: FIXME: Detect finished transfers { qDebug() << QString("Core::onFileControlCallback: Reception of file %1 from %2 finished") .arg(file->fileNum).arg(file->friendId); file->status = ToxFile::STOPPED; emit static_cast(core)->fileTransferFinished(*file); // confirm receive is complete - tox_file_send_control(tox, file->friendId, 1, file->fileNum, TOX_FILECONTROL_FINISHED, nullptr, 0); + ///tox_file_control(tox, file->friendId, 1, file->fileNum, TOX_FILECONTROL_FINISHED, nullptr, 0); removeFileFromQueue((bool)receive_send, file->friendId, file->fileNum); } - else if (receive_send == 0 && control_type == TOX_FILECONTROL_ACCEPT) + else if (receive_send == 0 && control_type == TOX_FILE_CONTROL_RESUME) { if (file->status == ToxFile::BROKEN) { @@ -645,11 +669,11 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive } emit static_cast(core)->fileTransferRemotePausedUnpaused(*file, false); } - else if ((receive_send == 0 || receive_send == 1) && control_type == TOX_FILECONTROL_PAUSE) + else if ((receive_send == 0 || receive_send == 1) && control_type == TOX_FILE_CONTROL_PAUSE) { emit static_cast(core)->fileTransferRemotePausedUnpaused(*file, true); } - else if (receive_send == 1 && control_type == TOX_FILECONTROL_RESUME_BROKEN) + else if (receive_send == 1 && control_type == TOX_FILE_CONTROL_RESUME) { if (length != sizeof(uint64_t)) return; @@ -661,7 +685,7 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive if (resumePos >= (unsigned)file->filesize) { qWarning() << "Core::onFileControlCallback: invalid resume position"; - tox_file_send_control(tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0); // don't sure about it + tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_CANCEL, nullptr); // don't sure about it return; } @@ -669,7 +693,7 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive emit static_cast(core)->fileTransferBrokenUnbroken(*file, false); file->bytesSent = resumePos; - tox_file_send_control(tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_ACCEPT, nullptr, 0); + tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_RESUME, nullptr); } else { @@ -678,7 +702,7 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive } } -void Core::onFileDataCallback(Tox*, int32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length, void *core) +void Core::onFileDataCallback(Tox*, uint32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length, void *core) { ToxFile* file{nullptr}; for (ToxFile& f : fileRecvQueue) @@ -701,9 +725,11 @@ void Core::onFileDataCallback(Tox*, int32_t friendnumber, uint8_t filenumber, co emit static_cast(core)->fileTransferInfo(*file); } -void Core::onAvatarInfoCallback(Tox*, int32_t friendnumber, uint8_t format, +void Core::onAvatarInfoCallback(Tox*, uint32_t friendnumber, uint8_t format, uint8_t* hash, void* _core) { + assert(0); + /* TODO: Address this avatar function Core* core = static_cast(_core); if (format == TOX_AVATAR_FORMAT_NONE) @@ -725,9 +751,10 @@ void Core::onAvatarInfoCallback(Tox*, int32_t friendnumber, uint8_t format, //else // qDebug() << "Core: Got same avatar info from" << core->getFriendUsername(friendnumber); } + */ } -void Core::onAvatarDataCallback(Tox*, int32_t friendnumber, uint8_t, +void Core::onAvatarDataCallback(Tox*, uint32_t friendnumber, uint8_t, uint8_t *hash, uint8_t *data, uint32_t datalen, void *core) { QPixmap pic; @@ -741,15 +768,15 @@ void Core::onAvatarDataCallback(Tox*, int32_t friendnumber, uint8_t, } } -void Core::onReadReceiptCallback(Tox*, int32_t friendnumber, uint32_t receipt, void *core) +void Core::onReadReceiptCallback(Tox*, uint32_t friendnumber, uint32_t receipt, void *core) { emit static_cast(core)->receiptRecieved(friendnumber, receipt); } void Core::acceptFriendRequest(const QString& userId) { - int friendId = tox_add_friend_norequest(tox, CUserId(userId).data()); - if (friendId == -1) { + uint32_t friendId = tox_friend_add_norequest(tox, CUserId(userId).data(), nullptr); + if (friendId == UINT32_MAX) { emit failedToAddFriend(userId); } else { saveConfiguration(); @@ -770,8 +797,9 @@ void Core::requestFriendship(const QString& friendAddress, const QString& messag qDebug() << "Core: requesting friendship of "+friendAddress; CString cMessage(message); - int friendId = tox_add_friend(tox, CFriendAddress(friendAddress).data(), cMessage.data(), cMessage.size()); - if (friendId < 0) + uint32_t friendId = tox_friend_add(tox, CFriendAddress(friendAddress).data(), + cMessage.data(), cMessage.size(), nullptr); + if (friendId == UINT32_MAX) { emit failedToAddFriend(userId); } @@ -789,28 +817,30 @@ void Core::requestFriendship(const QString& friendAddress, const QString& messag saveConfiguration(); } -int Core::sendMessage(int friendId, const QString& message) +int Core::sendMessage(uint32_t friendId, const QString& message) { QMutexLocker ml(&messageSendMutex); CString cMessage(message); - int receipt = tox_send_message(tox, friendId, cMessage.data(), cMessage.size()); + int receipt = tox_friend_send_message(tox, friendId, TOX_MESSAGE_TYPE_NORMAL, + cMessage.data(), cMessage.size(), nullptr); emit messageSentResult(friendId, message, receipt); return receipt; } -int Core::sendAction(int friendId, const QString &action) +int Core::sendAction(uint32_t friendId, const QString &action) { QMutexLocker ml(&messageSendMutex); CString cMessage(action); - int receipt = tox_send_action(tox, friendId, cMessage.data(), cMessage.size()); + int receipt = tox_friend_send_message(tox, friendId, TOX_MESSAGE_TYPE_ACTION, + cMessage.data(), cMessage.size(), nullptr); emit messageSentResult(friendId, action, receipt); return receipt; } -void Core::sendTyping(int friendId, bool typing) +void Core::sendTyping(uint32_t friendId, bool typing) { - int ret = tox_set_user_is_typing(tox, friendId, typing); - if (ret == -1) + bool ret = tox_self_set_typing(tox, friendId, typing, nullptr); + if (ret == false) emit failedToSetTyping(typing); } @@ -848,13 +878,14 @@ void Core::changeGroupTitle(int groupId, const QString& title) emit groupTitleChanged(groupId, getUsername(), title); } -void Core::sendFile(int32_t friendId, QString Filename, QString FilePath, long long filesize) +void Core::sendFile(uint32_t friendId, QString Filename, QString FilePath, long long filesize) { QMutexLocker mlocker(&fileSendMutex); QByteArray fileName = Filename.toUtf8(); - int fileNum = tox_new_file_sender(tox, friendId, filesize, (uint8_t*)fileName.data(), fileName.size()); - if (fileNum == -1) + uint32_t fileNum = tox_file_send(tox, friendId, TOX_FILE_KIND_DATA, filesize, nullptr, + (uint8_t*)fileName.data(), fileName.size(), nullptr); + if (fileNum == UINT32_MAX) { qWarning() << "Core::sendFile: Can't create the Tox file sender"; emit fileSendFailed(friendId, Filename); @@ -873,7 +904,7 @@ void Core::sendFile(int32_t friendId, QString Filename, QString FilePath, long l emit fileSendStarted(fileSendQueue.last()); } -void Core::pauseResumeFileSend(int friendId, int fileNum) +void Core::pauseResumeFileSend(uint32_t friendId, uint32_t fileNum) { ToxFile* file{nullptr}; for (ToxFile& f : fileSendQueue) @@ -893,19 +924,19 @@ void Core::pauseResumeFileSend(int friendId, int fileNum) { file->status = ToxFile::PAUSED; emit fileTransferPaused(*file); - tox_file_send_control(tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_PAUSE, nullptr, 0); + tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_PAUSE, nullptr); } else if (file->status == ToxFile::PAUSED) { file->status = ToxFile::TRANSMITTING; emit fileTransferAccepted(*file); - tox_file_send_control(tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_ACCEPT, nullptr, 0); + tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_RESUME, nullptr); } else qWarning() << "Core::pauseResumeFileSend: File is stopped"; } -void Core::pauseResumeFileRecv(int friendId, int fileNum) +void Core::pauseResumeFileRecv(uint32_t friendId, uint32_t fileNum) { ToxFile* file{nullptr}; for (ToxFile& f : fileRecvQueue) @@ -925,19 +956,19 @@ void Core::pauseResumeFileRecv(int friendId, int fileNum) { file->status = ToxFile::PAUSED; emit fileTransferPaused(*file); - tox_file_send_control(tox, file->friendId, 1, file->fileNum, TOX_FILECONTROL_PAUSE, nullptr, 0); + tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_PAUSE, nullptr); } else if (file->status == ToxFile::PAUSED) { file->status = ToxFile::TRANSMITTING; emit fileTransferAccepted(*file); - tox_file_send_control(tox, file->friendId, 1, file->fileNum, TOX_FILECONTROL_ACCEPT, nullptr, 0); + tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_RESUME, nullptr); } else qWarning() << "Core::pauseResumeFileRecv: File is stopped or broken"; } -void Core::cancelFileSend(int friendId, int fileNum) +void Core::cancelFileSend(uint32_t friendId, uint32_t fileNum) { ToxFile* file{nullptr}; for (ToxFile& f : fileSendQueue) @@ -955,12 +986,12 @@ void Core::cancelFileSend(int friendId, int fileNum) } file->status = ToxFile::STOPPED; emit fileTransferCancelled(*file); - tox_file_send_control(tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0); + tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_CANCEL, nullptr); while (file->sendTimer) QThread::msleep(1); // Wait until sendAllFileData returns before deleting removeFileFromQueue(true, friendId, fileNum); } -void Core::cancelFileRecv(int friendId, int fileNum) +void Core::cancelFileRecv(uint32_t friendId, uint32_t fileNum) { ToxFile* file{nullptr}; for (ToxFile& f : fileRecvQueue) @@ -978,11 +1009,11 @@ void Core::cancelFileRecv(int friendId, int fileNum) } file->status = ToxFile::STOPPED; emit fileTransferCancelled(*file); - tox_file_send_control(tox, file->friendId, 1, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0); + tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_CANCEL, nullptr); removeFileFromQueue(true, friendId, fileNum); } -void Core::rejectFileRecvRequest(int friendId, int fileNum) +void Core::rejectFileRecvRequest(uint32_t friendId, uint32_t fileNum) { ToxFile* file{nullptr}; for (ToxFile& f : fileRecvQueue) @@ -1000,11 +1031,11 @@ void Core::rejectFileRecvRequest(int friendId, int fileNum) } file->status = ToxFile::STOPPED; emit fileTransferCancelled(*file); - tox_file_send_control(tox, file->friendId, 1, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0); + tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_CANCEL, nullptr); removeFileFromQueue(false, friendId, fileNum); } -void Core::acceptFileRecvRequest(int friendId, int fileNum, QString path) +void Core::acceptFileRecvRequest(uint32_t friendId, uint32_t fileNum, QString path) { ToxFile* file{nullptr}; for (ToxFile& f : fileRecvQueue) @@ -1028,14 +1059,14 @@ void Core::acceptFileRecvRequest(int friendId, int fileNum, QString path) } file->status = ToxFile::TRANSMITTING; emit fileTransferAccepted(*file); - tox_file_send_control(tox, file->friendId, 1, file->fileNum, TOX_FILECONTROL_ACCEPT, nullptr, 0); + tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_RESUME, nullptr); } -void Core::removeFriend(int friendId, bool fake) +void Core::removeFriend(uint32_t friendId, bool fake) { if (!isReady() || fake) return; - if (tox_del_friend(tox, friendId) == -1) { + if (tox_friend_delete(tox, friendId, nullptr) == false) { emit failedToRemoveFriend(friendId); } else { saveConfiguration(); @@ -1056,10 +1087,10 @@ void Core::removeGroup(int groupId, bool fake) QString Core::getUsername() const { QString sname; - int size = tox_get_self_name_size(tox); + int size = tox_self_get_name_size(tox); uint8_t* name = new uint8_t[size]; - if (tox_get_self_name(tox, name) == size) - sname = CString::toString(name, size); + tox_self_get_name(tox, name); + sname = CString::toString(name, size); delete[] name; return sname; } @@ -1068,7 +1099,7 @@ void Core::setUsername(const QString& username) { CString cUsername(username); - if (tox_set_name(tox, cUsername.data(), cUsername.size()) == -1) { + if (tox_self_set_name(tox, cUsername.data(), cUsername.size(), nullptr) == false) { emit failedToSetUsername(username); } else { emit usernameSet(username); @@ -1076,13 +1107,9 @@ void Core::setUsername(const QString& username) } } -void Core::setAvatar(uint8_t format, const QByteArray& data) +void Core::setAvatar(const QByteArray& data) { - if (tox_set_avatar(tox, format, (uint8_t*)data.constData(), data.size()) != 0) - { - qWarning() << "Core: Failed to set self avatar"; - return; - } + /// TODO: Review this function, toxcore doesn't handle avatars anymore apparently. Good. QPixmap pic; pic.loadFromData(data); @@ -1091,15 +1118,15 @@ void Core::setAvatar(uint8_t format, const QByteArray& data) // Broadcast our new avatar! // according to tox.h, we need not broadcast this ourselves, but initial testing indicated elsewise - const uint32_t friendCount = tox_count_friendlist(tox);; + const uint32_t friendCount = tox_self_get_friend_list_size(tox); for (unsigned i=0; i Core::getKeypair() const if (!tox) return keypair; - char buf[2*TOX_PUBLIC_KEY_SIZE]; - tox_get_keys(tox, (uint8_t*)buf, (uint8_t*)buf+TOX_PUBLIC_KEY_SIZE); + char buf[std::max(TOX_PUBLIC_KEY_SIZE, TOX_SECRET_KEY_SIZE)]; + tox_self_get_public_key(tox, (uint8_t*)buf); keypair.first = QByteArray(buf, TOX_PUBLIC_KEY_SIZE); - keypair.second = QByteArray(buf+TOX_PUBLIC_KEY_SIZE, TOX_PUBLIC_KEY_SIZE); + tox_self_get_secret_key(tox, (uint8_t*)buf); + keypair.second = QByteArray(buf, TOX_SECRET_KEY_SIZE); return keypair; } QString Core::getStatusMessage() const { QString sname; - int size = tox_get_self_status_message_size(tox); + size_t size = tox_self_get_status_message_size(tox); uint8_t* name = new uint8_t[size]; - if (tox_get_self_status_message(tox, name, size) == size) - sname = CString::toString(name, size); + tox_self_get_status_message(tox, name); + sname = CString::toString(name, size); delete[] name; return sname; } @@ -1138,7 +1166,7 @@ void Core::setStatusMessage(const QString& message) { CString cMessage(message); - if (tox_set_status_message(tox, cMessage.data(), cMessage.size()) == -1) { + if (tox_self_set_status_message(tox, cMessage.data(), cMessage.size(), nullptr) == false) { emit failedToSetStatusMessage(message); } else { saveConfiguration(); @@ -1148,28 +1176,24 @@ void Core::setStatusMessage(const QString& message) void Core::setStatus(Status status) { - TOX_USERSTATUS userstatus; + TOX_USER_STATUS userstatus; switch (status) { case Status::Online: - userstatus = TOX_USERSTATUS_NONE; + userstatus = TOX_USER_STATUS_NONE; break; case Status::Away: - userstatus = TOX_USERSTATUS_AWAY; + userstatus = TOX_USER_STATUS_AWAY; break; case Status::Busy: - userstatus = TOX_USERSTATUS_BUSY; + userstatus = TOX_USER_STATUS_BUSY; break; default: - userstatus = TOX_USERSTATUS_INVALID; break; } - if (tox_set_user_status(tox, userstatus) == 0) { - saveConfiguration(); - emit statusSet(status); - } else { - emit failedToSetStatus(status); - } + tox_self_set_status(tox, userstatus); + saveConfiguration(); + emit statusSet(status); } void Core::onFileTransferFinished(ToxFile file) @@ -1194,8 +1218,9 @@ QString Core::sanitize(QString name) return name; } -bool Core::loadConfiguration(QString path) +QByteArray Core::loadToxSave(QString path) { + QByteArray data; loadPath = ""; // if not empty upon return, then user forgot a password and is switching QFile configurationFile(path); @@ -1203,17 +1228,18 @@ bool Core::loadConfiguration(QString path) if (!configurationFile.exists()) { qWarning() << "The Tox configuration file was not found"; - return true; + return data; } if (!configurationFile.open(QIODevice::ReadOnly)) { qCritical() << "File " << path << " cannot be opened"; - return true; + return data; } qint64 fileSize = configurationFile.size(); if (fileSize > 0) { - QByteArray data = configurationFile.readAll(); + data = configurationFile.readAll(); + /* TODO: Clean this up int error = tox_load(tox, reinterpret_cast(data.data()), data.size()); if (error < 0) { @@ -1236,28 +1262,11 @@ bool Core::loadConfiguration(QString path) return false; } } + */ } configurationFile.close(); - // set GUI with user and statusmsg - QString name = getUsername(); - if (!name.isEmpty()) - emit usernameSet(name); - - QString msg = getStatusMessage(); - if (!msg.isEmpty()) - emit statusMessageSet(msg); - - QString id = getSelfId().toString(); - if (!id.isEmpty()) - emit idSet(id); - - // tox core is already decrypted - if (Settings::getInstance().getEnableLogging() && Settings::getInstance().getEncryptLogs()) - checkEncryptedHistory(); - - loadFriends(); - return true; + return data; } void Core::saveConfiguration() @@ -1328,29 +1337,28 @@ void Core::switchConfiguration(const QString& profile) void Core::loadFriends() { - const uint32_t friendCount = tox_count_friendlist(tox); + const uint32_t friendCount = tox_self_get_friend_list_size(tox); if (friendCount > 0) { // assuming there are not that many friends to fill up the whole stack - int32_t *ids = new int32_t[friendCount]; - tox_get_friendlist(tox, ids, friendCount); + uint32_t *ids = new uint32_t[friendCount]; + tox_self_get_friend_list(tox, ids); uint8_t clientId[TOX_PUBLIC_KEY_SIZE]; for (int32_t i = 0; i < static_cast(friendCount); ++i) { - if (tox_get_client_id(tox, ids[i], clientId) == 0) { + if (tox_friend_get_public_key(tox, ids[i], clientId, nullptr)) { emit friendAdded(ids[i], CUserId::toString(clientId)); - const int nameSize = tox_get_name_size(tox, ids[i]); - if (nameSize > 0) { + const size_t nameSize = tox_friend_get_name_size(tox, ids[i], nullptr); + if (nameSize != SIZE_MAX) { uint8_t *name = new uint8_t[nameSize]; - if (tox_get_name(tox, ids[i], name) == nameSize) { + if (tox_friend_get_name(tox, ids[i], name, nullptr)) emit friendUsernameChanged(ids[i], CString::toString(name, nameSize)); - } delete[] name; } - const int statusMessageSize = tox_get_status_message_size(tox, ids[i]); - if (statusMessageSize > 0) { + const size_t statusMessageSize = tox_friend_get_status_message_size(tox, ids[i], nullptr); + if (statusMessageSize != SIZE_MAX) { uint8_t *statusMessage = new uint8_t[statusMessageSize]; - if (tox_get_status_message(tox, ids[i], statusMessage, statusMessageSize) == statusMessageSize) { + if (tox_friend_get_status_message(tox, ids[i], statusMessage, nullptr)) { emit friendStatusMessageChanged(ids[i], CString::toString(statusMessage, statusMessageSize)); } delete[] statusMessage; @@ -1364,9 +1372,9 @@ void Core::loadFriends() } } -void Core::checkLastOnline(int friendId) { - const uint64_t lastOnline = tox_get_last_online(tox, friendId); - if (lastOnline > 0) { +void Core::checkLastOnline(uint32_t friendId) { + const uint64_t lastOnline = tox_friend_get_last_online(tox, friendId, nullptr); + if (lastOnline != UINT64_MAX) { emit friendLastSeenChanged(friendId, QDateTime::fromTime_t(lastOnline)); } } @@ -1453,7 +1461,7 @@ void Core::quitGroupChat(int groupId) const tox_del_groupchat(tox, groupId); } -void Core::removeFileFromQueue(bool sendQueue, int friendId, int fileId) +void Core::removeFileFromQueue(bool sendQueue, uint32_t friendId, uint32_t fileId) { bool found = false; if (sendQueue) @@ -1492,6 +1500,8 @@ void Core::removeFileFromQueue(bool sendQueue, int friendId, int fileId) void Core::sendAllFileData(Core *core, ToxFile* file) { + assert(0); + /** TODO: Reimplement file transfers using tox_file_chunk_request_cb if (file->status == ToxFile::PAUSED) { file->sendTimer->start(5+TOX_FILE_INTERVAL); @@ -1513,7 +1523,7 @@ void Core::sendAllFileData(Core *core, ToxFile* file) qWarning("Core::fileHeartbeat: Error getting preffered chunk size, aborting file send"); file->status = ToxFile::STOPPED; emit core->fileTransferCancelled(*file); - tox_file_send_control(core->tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0); + tox_file_control(core->tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_CANCEL, nullptr); removeFileFromQueue(true, file->friendId, file->fileNum); return; } @@ -1528,7 +1538,7 @@ void Core::sendAllFileData(Core *core, ToxFile* file) delete[] data; file->status = ToxFile::STOPPED; emit core->fileTransferCancelled(*file); - tox_file_send_control(core->tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0); + tox_file_control(core->tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_CANCEL, nullptr); removeFileFromQueue(true, file->friendId, file->fileNum); return; } @@ -1538,7 +1548,7 @@ void Core::sendAllFileData(Core *core, ToxFile* file) delete[] data; file->status = ToxFile::STOPPED; emit core->fileTransferCancelled(*file); - tox_file_send_control(core->tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0); + tox_file_control(core->tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_CANCEL, nullptr); removeFileFromQueue(true, file->friendId, file->fileNum); return; } @@ -1566,12 +1576,14 @@ void Core::sendAllFileData(Core *core, ToxFile* file) file->sendTimer->disconnect(); delete file->sendTimer; file->sendTimer = nullptr; - tox_file_send_control(core->tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_FINISHED, nullptr, 0); + /// TODO: Review this, we can't send finished messages anymore, but maybe we don't need to + ///tox_file_control(core->tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_FINISHED, nullptr, 0); //emit core->fileTransferFinished(*file); } + */ } -void Core::groupInviteFriend(int friendId, int groupId) +void Core::groupInviteFriend(uint32_t friendId, int groupId) { tox_invite_friend(tox, friendId, groupId); } @@ -1595,7 +1607,7 @@ void Core::createGroup(uint8_t type) bool Core::hasFriendWithAddress(const QString &addr) const { // Valid length check - if (addr.length() != (TOX_FRIEND_ADDRESS_SIZE * 2)) + if (addr.length() != (TOX_ADDRESS_SIZE * 2)) { return false; } @@ -1613,11 +1625,11 @@ bool Core::hasFriendWithPublicKey(const QString &pubkey) const } bool found = false; - const uint32_t friendCount = tox_count_friendlist(tox); + const size_t friendCount = tox_self_get_friend_list_size(tox); if (friendCount > 0) { - int32_t *ids = new int32_t[friendCount]; - tox_get_friendlist(tox, ids, friendCount); + uint32_t *ids = new uint32_t[friendCount]; + tox_self_get_friend_list(tox, ids); for (int32_t i = 0; i < static_cast(friendCount); ++i) { // getFriendAddress may return either id (public key) or address @@ -1637,11 +1649,14 @@ bool Core::hasFriendWithPublicKey(const QString &pubkey) const return found; } -QString Core::getFriendAddress(int friendNumber) const +QString Core::getFriendAddress(uint32_t friendNumber) const { // If we don't know the full address of the client, return just the id, otherwise get the full address uint8_t rawid[TOX_PUBLIC_KEY_SIZE]; - tox_get_client_id(tox, friendNumber, rawid); + if (!tox_friend_get_public_key(tox, friendNumber, rawid, nullptr)) { + qWarning() << "Core::getFriendAddress: Getting public key failed"; + return QString(); + } QByteArray data((char*)rawid,TOX_PUBLIC_KEY_SIZE); QString id = data.toHex().toUpper(); @@ -1652,11 +1667,18 @@ QString Core::getFriendAddress(int friendNumber) const return id; } -QString Core::getFriendUsername(int friendnumber) const +QString Core::getFriendUsername(uint32_t friendnumber) const { - uint8_t name[TOX_MAX_NAME_LENGTH]; - tox_get_name(tox, friendnumber, name); - return CString::toString(name, tox_get_name_size(tox, friendnumber)); + size_t namesize = tox_friend_get_name_size(tox, friendnumber, nullptr); + if (namesize == SIZE_MAX) { + qWarning() << "Core::getFriendUsername: Failed to get name size for friend "< Core::splitMessage(const QString &message, int maxLen) @@ -1693,22 +1715,22 @@ QString Core::getPeerName(const ToxID& id) const QString name; CUserId cid(id.toString()); - int friendId = tox_get_friend_number(tox, (uint8_t*)cid.data()); - if (friendId < 0) + uint32_t friendId = tox_friend_by_public_key(tox, (uint8_t*)cid.data(), nullptr); + if (friendId == UINT32_MAX) { qWarning() << "Core::getPeerName: No such peer "+id.toString(); return name; } - const int nameSize = tox_get_name_size(tox, friendId); - if (nameSize <= 0) + const size_t nameSize = tox_friend_get_name_size(tox, friendId, nullptr); + if (nameSize == SIZE_MAX) { //qDebug() << "Core::getPeerName: Can't get name of friend "+QString().setNum(friendId)+" ("+id.toString()+")"; return name; } uint8_t* cname = new uint8_t[nameSize(&nospam); std::reverse(nspm, nspm + 4); - tox_set_nospam(tox, nospam); + tox_self_set_nospam(tox, nospam); } void Core::resetCallSources() diff --git a/src/core.h b/src/core.h index 55094ec32..e1217d364 100644 --- a/src/core.h +++ b/src/core.h @@ -22,6 +22,7 @@ #include #include +#include #include "corestructs.h" #include "coreav.h" @@ -60,8 +61,8 @@ public: QString getGroupPeerName(int groupId, int peerId) const; ///< Get the name of a peer of a group ToxID getGroupPeerToxID(int groupId, int peerId) const; ///< Get the ToxID of a peer of a group QList getGroupPeerNames(int groupId) const; ///< Get the names of the peers of a group - QString getFriendAddress(int friendNumber) const; ///< Get the full address if known, or Tox ID of a friend - QString getFriendUsername(int friendNumber) const; ///< Get the username of a friend + QString getFriendAddress(uint32_t friendNumber) const; ///< Get the full address if known, or Tox ID of a friend + QString getFriendUsername(uint32_t friendNumber) const; ///< Get the username of a friend bool hasFriendWithAddress(const QString &addr) const; ///< Check if we have a friend by address bool hasFriendWithPublicKey(const QString &pubkey) const; ///< Check if we have a friend by public key int joinGroupchat(int32_t friendNumber, uint8_t type, const uint8_t* pubkey,uint16_t length) const; ///< Accept a groupchat invite @@ -93,37 +94,37 @@ public slots: void acceptFriendRequest(const QString& userId); void requestFriendship(const QString& friendAddress, const QString& message); - void groupInviteFriend(int friendId, int groupId); + void groupInviteFriend(uint32_t friendId, int groupId); void createGroup(uint8_t type = TOX_GROUPCHAT_TYPE_AV); - void removeFriend(int friendId, bool fake = false); + void removeFriend(uint32_t friendId, bool fake = false); void removeGroup(int groupId, bool fake = false); void setStatus(Status status); void setUsername(const QString& username); void setStatusMessage(const QString& message); - void setAvatar(uint8_t format, const QByteArray& data); + void setAvatar(const QByteArray& data); - int sendMessage(int friendId, const QString& message); + int sendMessage(uint32_t friendId, const QString& message); void sendGroupMessage(int groupId, const QString& message); void sendGroupAction(int groupId, const QString& message); void changeGroupTitle(int groupId, const QString& title); - int sendAction(int friendId, const QString& action); - void sendTyping(int friendId, bool typing); + int sendAction(uint32_t friendId, const QString& action); + void sendTyping(uint32_t friendId, bool typing); - void sendFile(int32_t friendId, QString Filename, QString FilePath, long long filesize); - void cancelFileSend(int friendId, int fileNum); - void cancelFileRecv(int friendId, int fileNum); - void rejectFileRecvRequest(int friendId, int fileNum); - void acceptFileRecvRequest(int friendId, int fileNum, QString path); - void pauseResumeFileSend(int friendId, int fileNum); - void pauseResumeFileRecv(int friendId, int fileNum); + void sendFile(uint32_t friendId, QString Filename, QString FilePath, long long filesize); + void cancelFileSend(uint32_t friendId, uint32_t fileNum); + void cancelFileRecv(uint32_t friendId, uint32_t fileNum); + void rejectFileRecvRequest(uint32_t friendId, uint32_t fileNum); + void acceptFileRecvRequest(uint32_t friendId, uint32_t fileNum, QString path); + void pauseResumeFileSend(uint32_t friendId, uint32_t fileNum); + void pauseResumeFileRecv(uint32_t friendId, uint32_t fileNum); void answerCall(int callId); void rejectCall(int callId); void hangupCall(int callId); - void startCall(int friendId, bool video=false); - void cancelCall(int callId, int friendId); + void startCall(uint32_t friendId, bool video=false); + void cancelCall(int callId, uint32_t friendId); void micMuteToggle(int callId); void volMuteToggle(int callId); @@ -151,23 +152,23 @@ signals: void blockingClearContacts(); void friendRequestReceived(const QString& userId, const QString& message); - void friendMessageReceived(int friendId, const QString& message, bool isAction); + void friendMessageReceived(uint32_t friendId, const QString& message, bool isAction); - void friendAdded(int friendId, const QString& userId); + void friendAdded(uint32_t friendId, const QString& userId); - void friendStatusChanged(int friendId, Status status); - void friendStatusMessageChanged(int friendId, const QString& message); - void friendUsernameChanged(int friendId, const QString& username); - void friendTypingChanged(int friendId, bool isTyping); - void friendAvatarChanged(int friendId, const QPixmap& pic); - void friendAvatarRemoved(int friendId); + void friendStatusChanged(uint32_t friendId, Status status); + void friendStatusMessageChanged(uint32_t friendId, const QString& message); + void friendUsernameChanged(uint32_t friendId, const QString& username); + void friendTypingChanged(uint32_t friendId, bool isTyping); + void friendAvatarChanged(uint32_t friendId, const QPixmap& pic); + void friendAvatarRemoved(uint32_t friendId); - void friendRemoved(int friendId); + void friendRemoved(uint32_t friendId); - void friendLastSeenChanged(int friendId, const QDateTime& dateTime); + void friendLastSeenChanged(uint32_t friendId, const QDateTime& dateTime); void emptyGroupCreated(int groupnumber); - void groupInviteReceived(int friendnumber, uint8_t type, QByteArray publicKey); + void groupInviteReceived(uint32_t friendNumber, uint8_t type, QByteArray publicKey); void groupMessageReceived(int groupnumber, int peernumber, const QString& message, bool isAction); void groupNamelistChanged(int groupnumber, int peernumber, uint8_t change); void groupTitleChanged(int groupnumber, const QString& author, const QString& title); @@ -179,14 +180,14 @@ signals: void idSet(const QString& id); void selfAvatarChanged(const QPixmap& pic); - void messageSentResult(int friendId, const QString& message, int messageId); + void messageSentResult(uint32_t friendId, const QString& message, int messageId); void groupSentResult(int groupId, const QString& message, int result); - void actionSentResult(int friendId, const QString& action, int success); + void actionSentResult(uint32_t friendId, const QString& action, int success); void receiptRecieved(int friedId, int receipt); void failedToAddFriend(const QString& userId, const QString& errorInfo = QString()); - void failedToRemoveFriend(int friendId); + void failedToRemoveFriend(uint32_t friendId); void failedToSetUsername(const QString& username); void failedToSetStatusMessage(const QString& message); void failedToSetStatus(Status status); @@ -207,45 +208,44 @@ signals: void fileTransferRemotePausedUnpaused(ToxFile file, bool paused); void fileTransferBrokenUnbroken(ToxFile file, bool broken); - void fileSendFailed(int FriendId, const QString& fname); + void fileSendFailed(uint32_t friendId, const QString& fname); - void avInvite(int friendId, int callIndex, bool video); - void avStart(int friendId, int callIndex, bool video); - void avCancel(int friendId, int callIndex); - void avEnd(int friendId, int callIndex); - void avRinging(int friendId, int callIndex, bool video); - void avStarting(int friendId, int callIndex, bool video); - void avEnding(int friendId, int callIndex); - void avRequestTimeout(int friendId, int callIndex); - void avPeerTimeout(int friendId, int callIndex); - void avMediaChange(int friendId, int callIndex, bool videoEnabled); - void avCallFailed(int friendId); - void avRejected(int friendId, int callIndex); + void avInvite(uint32_t friendId, int callIndex, bool video); + void avStart(uint32_t friendId, int callIndex, bool video); + void avCancel(uint32_t friendId, int callIndex); + void avEnd(uint32_t friendId, int callIndex); + void avRinging(uint32_t friendId, int callIndex, bool video); + void avStarting(uint32_t friendId, int callIndex, bool video); + void avEnding(uint32_t friendId, int callIndex); + void avRequestTimeout(uint32_t friendId, int callIndex); + void avPeerTimeout(uint32_t friendId, int callIndex); + void avMediaChange(uint32_t friendId, int callIndex, bool videoEnabled); + void avCallFailed(uint32_t friendId); + void avRejected(uint32_t friendId, int callIndex); void videoFrameReceived(vpx_image* frame); private: - static void onFriendRequest(Tox* tox, const uint8_t* cUserId, const uint8_t* cMessage, uint16_t cMessageSize, void* core); - static void onFriendMessage(Tox* tox, int friendId, const uint8_t* cMessage, uint16_t cMessageSize, void* core); - static void onFriendNameChange(Tox* tox, int friendId, const uint8_t* cName, uint16_t cNameSize, void* core); - static void onFriendTypingChange(Tox* tox, int friendId, uint8_t isTyping, void* core); - static void onStatusMessageChanged(Tox* tox, int friendId, const uint8_t* cMessage, uint16_t cMessageSize, void* core); - static void onUserStatusChanged(Tox* tox, int friendId, uint8_t userstatus, void* core); - static void onConnectionStatusChanged(Tox* tox, int friendId, uint8_t status, void* core); - static void onAction(Tox* tox, int friendId, const uint8_t* cMessage, uint16_t cMessageSize, void* core); + static void onFriendRequest(Tox* tox, const uint8_t* cUserId, 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* core); static void onGroupAction(Tox* tox, int groupnumber, int peernumber, const uint8_t * action, uint16_t length, void* core); - static void onGroupInvite(Tox *tox, int friendnumber, uint8_t type, const uint8_t *data, uint16_t length,void *userdata); + static void onGroupInvite(Tox *tox, int32_t friendNumber, uint8_t type, const uint8_t *data, uint16_t length, void *userdata); static void onGroupMessage(Tox *tox, int groupnumber, int friendgroupnumber, const uint8_t * message, uint16_t length, void *userdata); static void onGroupNamelistChange(Tox *tox, int groupnumber, int peernumber, uint8_t change, void *userdata); static void onGroupTitleChange(Tox*, int groupnumber, int peernumber, const uint8_t* title, uint8_t len, void* _core); - static void onFileSendRequestCallback(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, + static void onFileSendRequestCallback(Tox *tox, uint32_t friendnumber, uint8_t filenumber, uint64_t filesize, const uint8_t *filename, uint16_t filename_length, void *userdata); - static void onFileControlCallback(Tox *tox, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber, + static void onFileControlCallback(Tox *tox, uint32_t friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type, const uint8_t *data, uint16_t length, void *core); - static void onFileDataCallback(Tox *tox, int32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length, void *userdata); - static void onAvatarInfoCallback(Tox* tox, int32_t friendnumber, uint8_t format, uint8_t *hash, void *userdata); - static void onAvatarDataCallback(Tox* tox, int32_t friendnumber, uint8_t format, uint8_t *hash, uint8_t *data, uint32_t datalen, void *userdata); - static void onReadReceiptCallback(Tox *tox, int32_t friendnumber, uint32_t receipt, void *core); + static void onFileDataCallback(Tox *tox, uint32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length, void *userdata); + static void onAvatarInfoCallback(Tox* tox, uint32_t friendnumber, uint8_t format, uint8_t *hash, void *userdata); + static void onAvatarDataCallback(Tox* tox, uint32_t friendnumber, uint8_t format, uint8_t *hash, uint8_t *data, uint32_t datalen, void *userdata); + static void onReadReceiptCallback(Tox *tox, uint32_t friendnumber, uint32_t receipt, void *core); static void onAvInvite(void* toxav, int32_t call_index, void* core); static void onAvStart(void* toxav, int32_t call_index, void* core); @@ -259,7 +259,7 @@ private: static void sendGroupCallAudio(int groupId, ToxAv* toxav); - static void prepareCall(int friendId, int callId, ToxAv *toxav, bool videoEnabled); + static void prepareCall(uint32_t friendId, int callId, ToxAv *toxav, bool videoEnabled); static void cleanupCall(int callId); static void playCallAudio(void *toxav, int32_t callId, const int16_t *data, uint16_t samples, void *user_data); // Callback static void sendCallAudio(int callId, ToxAv* toxav); @@ -269,16 +269,16 @@ private: bool checkConnection(); - bool loadConfiguration(QString path); // Returns false for a critical error, true otherwise + QByteArray loadToxSave(QString path); bool loadEncryptedSave(QByteArray& data); void checkEncryptedHistory(); - void make_tox(); + void make_tox(QByteArray savedata); void loadFriends(); static void sendAllFileData(Core* core, ToxFile* file); - static void removeFileFromQueue(bool sendQueue, int friendId, int fileId); + static void removeFileFromQueue(bool sendQueue, uint32_t friendId, uint32_t fileId); - void checkLastOnline(int friendId); + void checkLastOnline(uint32_t friendId); void deadifyTox(); @@ -302,14 +302,14 @@ private: QMutex fileSendMutex, messageSendMutex; bool ready; - uint8_t* pwsaltedkeys[PasswordType::ptCounter] = {nullptr}; // use the pw's hash as the "pw" + TOX_PASS_KEY* pwsaltedkeys[PasswordType::ptCounter] = {nullptr}; // use the pw's hash as the "pw" // Hack for reloading current profile if switching to an encrypted one fails. // Testing the passwords before killing the current profile is perfectly doable, // however it would require major refactoring; // the Core class as a whole also requires major refactoring (especially to support multiple IDs at once), // so I'm punting on this until then, when it would get fixed anyways - uint8_t* backupkeys[PasswordType::ptCounter] = {nullptr}; + TOX_PASS_KEY* backupkeys[PasswordType::ptCounter] = {nullptr}; QString* backupProfile = nullptr; void saveCurrentInformation(); QString loadOldInformation(); diff --git a/src/coreav.cpp b/src/coreav.cpp index 3e9491bc0..bdd022b00 100644 --- a/src/coreav.cpp +++ b/src/coreav.cpp @@ -39,7 +39,7 @@ bool Core::anyActiveCalls() return false; } -void Core::prepareCall(int friendId, int callId, ToxAv* toxav, bool videoEnabled) +void Core::prepareCall(uint32_t friendId, int32_t callId, ToxAv* toxav, bool videoEnabled) { qDebug() << QString("Core: preparing call %1").arg(callId); calls[callId].callId = callId; @@ -120,9 +120,9 @@ fail: // Centralized error handling return; } -void Core::answerCall(int callId) +void Core::answerCall(int32_t callId) { - int friendId = toxav_get_peer_id(toxav, callId, 0); + uint32_t friendId = toxav_get_peer_id(toxav, callId, 0); if (friendId < 0) { qWarning() << "Core: Received invalid AV answer peer ID"; @@ -152,23 +152,23 @@ void Core::answerCall(int callId) delete transSettings; } -void Core::hangupCall(int callId) +void Core::hangupCall(int32_t callId) { qDebug() << QString("Core: hanging up call %1").arg(callId); calls[callId].active = false; toxav_hangup(toxav, callId); } -void Core::rejectCall(int callId) +void Core::rejectCall(int32_t callId) { qDebug() << QString("Core: rejecting call %1").arg(callId); calls[callId].active = false; toxav_reject(toxav, callId, nullptr); } -void Core::startCall(int friendId, bool video) +void Core::startCall(uint32_t friendId, bool video) { - int callId; + int32_t callId; ToxAvCSettings cSettings = av_DefaultSettings; cSettings.max_video_width = TOXAV_MAX_VIDEO_WIDTH; cSettings.max_video_height = TOXAV_MAX_VIDEO_HEIGHT; @@ -204,14 +204,14 @@ void Core::startCall(int friendId, bool video) } } -void Core::cancelCall(int callId, int friendId) +void Core::cancelCall(int32_t callId, uint32_t friendId) { qDebug() << QString("Core: Cancelling call with %1").arg(friendId); calls[callId].active = false; toxav_cancel(toxav, callId, friendId, nullptr); } -void Core::cleanupCall(int callId) +void Core::cleanupCall(int32_t callId) { qDebug() << QString("Core: cleaning up call %1").arg(callId); calls[callId].active = false; @@ -239,7 +239,7 @@ void Core::playCallAudio(void* toxav, int32_t callId, const int16_t *data, uint1 playAudioBuffer(calls[callId].alSource, data, samples, dest.audio_channels, dest.audio_sample_rate); } -void Core::sendCallAudio(int callId, ToxAv* toxav) +void Core::sendCallAudio(int32_t callId, ToxAv* toxav) { if (!calls[callId].active) return; @@ -303,7 +303,7 @@ void Core::playCallVideo(void*, int32_t callId, const vpx_image_t* img, void *us calls[callId].videoSource.pushVPXFrame(img); } -void Core::sendCallVideo(int callId) +void Core::sendCallVideo(int32_t callId) { if (!calls[callId].active || !calls[callId].videoEnabled) return; @@ -333,7 +333,7 @@ void Core::sendCallVideo(int callId) calls[callId].sendVideoTimer->start(); } -void Core::micMuteToggle(int callId) +void Core::micMuteToggle(int32_t callId) { if (calls[callId].active) { @@ -341,7 +341,7 @@ void Core::micMuteToggle(int callId) } } -void Core::volMuteToggle(int callId) +void Core::volMuteToggle(int32_t callId) { if (calls[callId].active) { @@ -354,7 +354,7 @@ void Core::onAvCancel(void* _toxav, int32_t callId, void* core) { ToxAv* toxav = static_cast(_toxav); - int friendId = toxav_get_peer_id(toxav, callId, 0); + uint32_t friendId = toxav_get_peer_id(toxav, callId, 0); if (friendId < 0) { qWarning() << "Core: Received invalid AV cancel"; @@ -379,7 +379,7 @@ void Core::onAvCancel(void* _toxav, int32_t callId, void* core) void Core::onAvReject(void* _toxav, int32_t callId, void* core) { ToxAv* toxav = static_cast(_toxav); - int friendId = toxav_get_peer_id(toxav, callId, 0); + uint32_t friendId = toxav_get_peer_id(toxav, callId, 0); if (friendId < 0) { qWarning() << "Core: Received invalid AV reject"; @@ -395,7 +395,7 @@ void Core::onAvEnd(void* _toxav, int32_t call_index, void* core) { ToxAv* toxav = static_cast(_toxav); - int friendId = toxav_get_peer_id(toxav, call_index, 0); + uint32_t friendId = toxav_get_peer_id(toxav, call_index, 0); if (friendId < 0) { qWarning() << "Core: Received invalid AV end"; @@ -412,7 +412,7 @@ void Core::onAvRinging(void* _toxav, int32_t call_index, void* core) { ToxAv* toxav = static_cast(_toxav); - int friendId = toxav_get_peer_id(toxav, call_index, 0); + uint32_t friendId = toxav_get_peer_id(toxav, call_index, 0); if (friendId < 0) { qWarning() << "Core: Received invalid AV ringing"; @@ -435,7 +435,7 @@ void Core::onAvRequestTimeout(void* _toxav, int32_t call_index, void* core) { ToxAv* toxav = static_cast(_toxav); - int friendId = toxav_get_peer_id(toxav, call_index, 0); + uint32_t friendId = toxav_get_peer_id(toxav, call_index, 0); if (friendId < 0) { qWarning() << "Core: Received invalid AV request timeout"; @@ -452,7 +452,7 @@ void Core::onAvPeerTimeout(void* _toxav, int32_t call_index, void* core) { ToxAv* toxav = static_cast(_toxav); - int friendId = toxav_get_peer_id(toxav, call_index, 0); + uint32_t friendId = toxav_get_peer_id(toxav, call_index, 0); if (friendId < 0) { qWarning() << "Core: Received invalid AV peer timeout"; @@ -470,7 +470,7 @@ void Core::onAvInvite(void* _toxav, int32_t call_index, void* core) { ToxAv* toxav = static_cast(_toxav); - int friendId = toxav_get_peer_id(toxav, call_index, 0); + uint32_t friendId = toxav_get_peer_id(toxav, call_index, 0); if (friendId < 0) { qWarning() << "Core: Received invalid AV invite"; @@ -504,7 +504,7 @@ void Core::onAvStart(void* _toxav, int32_t call_index, void* core) { ToxAv* toxav = static_cast(_toxav); - int friendId = toxav_get_peer_id(toxav, call_index, 0); + uint32_t friendId = toxav_get_peer_id(toxav, call_index, 0); if (friendId < 0) { qWarning() << "Core: Received invalid AV start"; diff --git a/src/coreav.h b/src/coreav.h index 4e196fc81..48c514808 100644 --- a/src/coreav.h +++ b/src/coreav.h @@ -19,8 +19,8 @@ struct ToxCall { ToxAvCSettings codecSettings; QTimer *sendAudioTimer, *sendVideoTimer; - int callId; - int friendId; + int32_t callId; + uint32_t friendId; bool videoEnabled; bool active; bool muteMic; diff --git a/src/coreencryption.cpp b/src/coreencryption.cpp index a69c1efdb..c77266be4 100644 --- a/src/coreencryption.cpp +++ b/src/coreencryption.cpp @@ -20,17 +20,18 @@ #include "core.h" #include "src/widget/gui.h" -#include -#include #include "src/misc/settings.h" #include "misc/cstring.h" #include "historykeeper.h" +#include +#include #include - #include #include #include #include +#include +#include void Core::setPassword(QString& password, PasswordType passtype, uint8_t* salt) { @@ -38,26 +39,25 @@ void Core::setPassword(QString& password, PasswordType passtype, uint8_t* salt) if (password.isEmpty()) return; - pwsaltedkeys[passtype] = new uint8_t[tox_pass_key_length()]; + pwsaltedkeys[passtype] = new TOX_PASS_KEY; CString str(password); if (salt) - tox_derive_key_with_salt(str.data(), str.size(), salt, pwsaltedkeys[passtype]); + tox_derive_key_with_salt(str.data(), str.size(), salt, pwsaltedkeys[passtype], nullptr); else - tox_derive_key_from_pass(str.data(), str.size(), pwsaltedkeys[passtype]); + tox_derive_key_from_pass(str.data(), str.size(), pwsaltedkeys[passtype], nullptr); password.clear(); } -#include void Core::useOtherPassword(PasswordType type) { clearPassword(type); - pwsaltedkeys[type] = new uint8_t[tox_pass_key_length()]; + pwsaltedkeys[type] = new TOX_PASS_KEY; PasswordType other = (type == ptMain) ? ptHistory : ptMain; - std::copy(pwsaltedkeys[other], pwsaltedkeys[other]+tox_pass_key_length(), pwsaltedkeys[type]); + std::copy(pwsaltedkeys[other], pwsaltedkeys[other]+TOX_PASS_KEY_LENGTH, pwsaltedkeys[type]); } void Core::clearPassword(PasswordType passtype) @@ -71,13 +71,13 @@ void Core::saveCurrentInformation() { if (pwsaltedkeys[ptMain]) { - backupkeys[ptMain] = new uint8_t[tox_pass_key_length()]; - std::copy(pwsaltedkeys[ptMain], pwsaltedkeys[ptMain]+tox_pass_key_length(), backupkeys[ptMain]); + backupkeys[ptMain] = new TOX_PASS_KEY; + std::copy(pwsaltedkeys[ptMain], pwsaltedkeys[ptMain]+TOX_PASS_KEY_LENGTH, backupkeys[ptMain]); } if (pwsaltedkeys[ptHistory]) { - backupkeys[ptHistory] = new uint8_t[tox_pass_key_length()]; - std::copy(pwsaltedkeys[ptHistory], pwsaltedkeys[ptHistory]+tox_pass_key_length(), backupkeys[ptHistory]); + backupkeys[ptHistory] = new TOX_PASS_KEY; + std::copy(pwsaltedkeys[ptHistory], pwsaltedkeys[ptHistory]+TOX_PASS_KEY_LENGTH, backupkeys[ptHistory]); } backupProfile = new QString(Settings::getInstance().getCurrentProfile()); } @@ -107,23 +107,24 @@ QByteArray Core::encryptData(const QByteArray& data, PasswordType passtype) { if (!pwsaltedkeys[passtype]) return QByteArray(); - uint8_t encrypted[data.size() + tox_pass_encryption_extra_length()]; - if (tox_pass_key_encrypt(reinterpret_cast(data.data()), data.size(), pwsaltedkeys[passtype], encrypted) == -1) + uint8_t encrypted[data.size() + TOX_PASS_ENCRYPTION_EXTRA_LENGTH]; + if (!tox_pass_key_encrypt(reinterpret_cast(data.data()), data.size(), + pwsaltedkeys[passtype], encrypted, nullptr)) { qWarning() << "Core::encryptData: encryption failed"; return QByteArray(); } - return QByteArray(reinterpret_cast(encrypted), data.size() + tox_pass_encryption_extra_length()); + return QByteArray(reinterpret_cast(encrypted), data.size() + TOX_PASS_ENCRYPTION_EXTRA_LENGTH); } QByteArray Core::decryptData(const QByteArray& data, PasswordType passtype) { if (!pwsaltedkeys[passtype]) return QByteArray(); - int sz = data.size() - tox_pass_encryption_extra_length(); + int sz = data.size() - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; uint8_t decrypted[sz]; - int decr_size = tox_pass_key_decrypt(reinterpret_cast(data.data()), data.size(), pwsaltedkeys[passtype], decrypted); - if (decr_size != sz) + if (!tox_pass_key_decrypt(reinterpret_cast(data.data()), data.size(), + pwsaltedkeys[passtype], decrypted, nullptr)) { qWarning() << "Core::decryptData: decryption failed"; return QByteArray(); @@ -147,10 +148,10 @@ QByteArray Core::getSaltFromFile(QString filename) qWarning() << "Core: file" << filename << "doesn't exist"; return QByteArray(); } - QByteArray data = file.read(tox_pass_encryption_extra_length()); + QByteArray data = file.read(TOX_PASS_ENCRYPTION_EXTRA_LENGTH); file.close(); - uint8_t *salt = new uint8_t[tox_pass_salt_length()]; + uint8_t *salt = new uint8_t[TOX_PASS_SALT_LENGTH]; int err = tox_get_salt(reinterpret_cast(data.data()), salt); if (err) { @@ -158,13 +159,15 @@ QByteArray Core::getSaltFromFile(QString filename) return QByteArray(); } - QByteArray res = QByteArray::fromRawData(reinterpret_cast(salt), tox_pass_salt_length()); + QByteArray res = QByteArray::fromRawData(reinterpret_cast(salt), TOX_PASS_SALT_LENGTH); delete[] salt; return res; } bool Core::loadEncryptedSave(QByteArray& data) { + assert(0); + /* if (!Settings::getInstance().getEncryptTox()) GUI::showWarning(tr("Encryption error"), tr("The .tox file is encrypted, but encryption was not checked, continuing regardless.")); @@ -186,7 +189,7 @@ bool Core::loadEncryptedSave(QByteArray& data) else dialogtxt = a; - uint8_t salt[tox_pass_salt_length()]; + uint8_t salt[TOX_PASS_SALT_LENGTH]; tox_get_salt(reinterpret_cast(data.data()), salt); do @@ -207,6 +210,7 @@ bool Core::loadEncryptedSave(QByteArray& data) Settings::getInstance().setEncryptTox(true); return true; + */ } void Core::checkEncryptedHistory() @@ -290,11 +294,15 @@ void Core::saveConfiguration(const QString& path) qDebug() << "Core: writing tox_save to " << path; - uint32_t fileSize; bool encrypt = Settings::getInstance().getEncryptTox(); + uint32_t fileSize; + bool encrypt = Settings::getInstance().getEncryptTox(); if (encrypt) - fileSize = tox_encrypted_size(tox); + { + qCritical() << "Encrypted saving not implemented!"; + exit(-1); + } else - fileSize = tox_size(tox); + fileSize = tox_get_savedata_size(tox); if (fileSize > 0 && fileSize <= std::numeric_limits::max()) { uint8_t *data = new uint8_t[fileSize]; @@ -306,20 +314,24 @@ void Core::saveConfiguration(const QString& path) // probably zero chance event GUI::showWarning(tr("NO Password"), tr("Local file encryption is enabled, but there is no password! It will be disabled.")); Settings::getInstance().setEncryptTox(false); - tox_save(tox, data); + tox_get_savedata(tox, data); } else { + qCritical() << "Encryption not implemented"; + exit(-1); + /* int ret = tox_encrypted_key_save(tox, data, pwsaltedkeys[ptMain]); if (ret == -1) { qCritical() << "Core::saveConfiguration: encryption of save file failed!!!"; return; } + */ } } else - tox_save(tox, data); + tox_get_savedata(tox, data); configurationFile.write(reinterpret_cast(data), fileSize); configurationFile.commit(); diff --git a/src/corestructs.cpp b/src/corestructs.cpp index 980fd1301..d58aacfa6 100644 --- a/src/corestructs.cpp +++ b/src/corestructs.cpp @@ -4,9 +4,9 @@ #include #include -#define TOX_ID_LENGTH 2*TOX_FRIEND_ADDRESS_SIZE +#define TOX_HEX_ID_LENGTH 2*TOX_ADDRESS_SIZE -ToxFile::ToxFile(int FileNum, int FriendId, QByteArray FileName, QString FilePath, FileDirection Direction) +ToxFile::ToxFile(uint32_t FileNum, uint32_t FriendId, QByteArray FileName, QString FilePath, FileDirection Direction) : fileNum(FileNum), friendId(FriendId), fileName{FileName}, filePath{FilePath}, file{new QFile(filePath)}, bytesSent{0}, filesize{0}, status{STOPPED}, direction{Direction}, sendTimer{nullptr} { @@ -78,5 +78,5 @@ void ToxID::clear() bool ToxID::isToxId(const QString& value) { const QRegularExpression hexRegExp("^[A-Fa-f0-9]+$"); - return value.length() == TOX_ID_LENGTH && value.contains(hexRegExp); + return value.length() == TOX_HEX_ID_LENGTH && value.contains(hexRegExp); } diff --git a/src/corestructs.h b/src/corestructs.h index 657d58f7b..d6bc81ae3 100644 --- a/src/corestructs.h +++ b/src/corestructs.h @@ -58,7 +58,7 @@ struct ToxFile }; ToxFile()=default; - ToxFile(int FileNum, int FriendId, QByteArray FileName, QString FilePath, FileDirection Direction); + ToxFile(uint32_t FileNum, uint32_t FriendId, QByteArray FileName, QString FilePath, FileDirection Direction); ~ToxFile(){} bool operator==(const ToxFile& other) const; @@ -67,8 +67,8 @@ struct ToxFile void setFilePath(QString path); bool open(bool write); - int fileNum; - int friendId; + uint32_t fileNum; + uint32_t friendId; QByteArray fileName; QString filePath; QFile* file; diff --git a/src/friend.cpp b/src/friend.cpp index 272cdcb1c..767b62010 100644 --- a/src/friend.cpp +++ b/src/friend.cpp @@ -22,7 +22,7 @@ #include "src/core.h" #include "src/misc/settings.h" -Friend::Friend(int FriendId, const ToxID &UserId) +Friend::Friend(uint32_t FriendId, const ToxID &UserId) : userName{Core::getInstance()->getPeerName(UserId)}, userID{UserId}, friendId{FriendId} { @@ -95,7 +95,7 @@ const ToxID &Friend::getToxID() const return userID; } -int Friend::getFriendID() const +uint32_t Friend::getFriendID() const { return friendId; } diff --git a/src/friend.h b/src/friend.h index b6ce04a89..cdf756bf3 100644 --- a/src/friend.h +++ b/src/friend.h @@ -28,7 +28,7 @@ class Friend : public QObject { Q_OBJECT public: - Friend(int FriendId, const ToxID &UserId); + Friend(uint32_t FriendId, const ToxID &UserId); Friend(const Friend& other)=delete; ~Friend(); Friend& operator=(const Friend& other)=delete; @@ -43,7 +43,7 @@ public: int getEventFlag() const; const ToxID &getToxID() const; - int getFriendID() const; + uint32_t getFriendID() const; void setStatus(Status s); Status getStatus() const; @@ -57,7 +57,7 @@ signals: private: QString userAlias, userName; ToxID userID; - int friendId; + uint32_t friendId; int hasNewEvents; Status friendStatus; diff --git a/src/friendlist.h b/src/friendlist.h index 9e6807197..5db698db3 100644 --- a/src/friendlist.h +++ b/src/friendlist.h @@ -19,7 +19,7 @@ template class QList; template class QHash; -struct Friend; +class Friend; class QString; struct ToxID; diff --git a/src/group.h b/src/group.h index f28c32685..bc9fcc73e 100644 --- a/src/group.h +++ b/src/group.h @@ -23,7 +23,7 @@ #define RETRY_PEER_INFO_INTERVAL 500 -struct Friend; +class Friend; class GroupWidget; class GroupChatForm; struct ToxID; diff --git a/src/misc/cdata.cpp b/src/misc/cdata.cpp index 28025de94..9ff8cc722 100644 --- a/src/misc/cdata.cpp +++ b/src/misc/cdata.cpp @@ -72,7 +72,7 @@ QString CUserId::toString(const uint8_t* cUserId) // CFriendAddress -const uint16_t CFriendAddress::SIZE{TOX_FRIEND_ADDRESS_SIZE}; +const uint16_t CFriendAddress::SIZE{TOX_ADDRESS_SIZE}; CFriendAddress::CFriendAddress(const QString &friendAddress) : CData(friendAddress, SIZE) diff --git a/src/misc/db/encrypteddb.cpp b/src/misc/db/encrypteddb.cpp index 709608667..1a8427aef 100644 --- a/src/misc/db/encrypteddb.cpp +++ b/src/misc/db/encrypteddb.cpp @@ -25,7 +25,7 @@ #include qint64 EncryptedDb::encryptedChunkSize = 4096; -qint64 EncryptedDb::plainChunkSize = EncryptedDb::encryptedChunkSize - tox_pass_encryption_extra_length(); +qint64 EncryptedDb::plainChunkSize = EncryptedDb::encryptedChunkSize - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; EncryptedDb::EncryptedDb(const QString &fname, QList initList) : PlainDb(":memory:", initList), fileName(fname) diff --git a/src/nexus.cpp b/src/nexus.cpp index 72ffb96c5..b7207f8df 100644 --- a/src/nexus.cpp +++ b/src/nexus.cpp @@ -47,6 +47,7 @@ void Nexus::start() qRegisterMetaType("vpx_image"); qRegisterMetaType("uint8_t"); qRegisterMetaType("uint16_t"); + qRegisterMetaType("uint32_t"); qRegisterMetaType("const int16_t*"); qRegisterMetaType("int32_t"); qRegisterMetaType("int64_t"); @@ -119,8 +120,8 @@ void Nexus::start() connect(core, &Core::blockingClearContacts, widget, &Widget::clearContactsList, Qt::BlockingQueuedConnection); connect(core, &Core::friendTypingChanged, widget, &Widget::onFriendTypingChanged); - connect(core, SIGNAL(messageSentResult(int,QString,int)), widget, SLOT(onMessageSendResult(int,QString,int))); - connect(core, SIGNAL(groupSentResult(int,QString,int)), widget, SLOT(onGroupSendResult(int,QString,int))); + connect(core, &Core::messageSentResult, widget, &Widget::onMessageSendResult); + connect(core, &Core::groupSentResult, widget, &Widget::onGroupSendResult); connect(widget, &Widget::statusSet, core, &Core::setStatus); connect(widget, &Widget::friendRequested, core, &Core::requestFriendship); diff --git a/src/offlinemsgengine.h b/src/offlinemsgengine.h index 52e1f8dd5..b7f9f6f17 100644 --- a/src/offlinemsgengine.h +++ b/src/offlinemsgengine.h @@ -24,7 +24,7 @@ #include #include "src/chatlog/chatmessage.h" -struct Friend; +class Friend; class QTimer; class OfflineMsgEngine : public QObject diff --git a/src/toxdns.cpp b/src/toxdns.cpp index 11cd1670f..ab08b8e2d 100644 --- a/src/toxdns.cpp +++ b/src/toxdns.cpp @@ -24,7 +24,7 @@ #include #include -#define TOX_ID_LENGTH 2*TOX_FRIEND_ADDRESS_SIZE +#define TOX_HEX_ID_LENGTH 2*TOX_ADDRESS_SIZE const ToxDNS::tox3_server ToxDNS::pinnedServers[] { @@ -128,13 +128,13 @@ QString ToxDNS::queryTox1(const QString& record, bool silent) } idx += 3; - if (entry.length() < idx + static_cast(TOX_ID_LENGTH)) { + if (entry.length() < idx + static_cast(TOX_HEX_ID_LENGTH)) { if (!silent) showWarning(tr("The DNS lookup does not contain a valid Tox ID", "Error with the DNS")); return toxId; } - toxId = entry.mid(idx, TOX_ID_LENGTH); + toxId = entry.mid(idx, TOX_HEX_ID_LENGTH); if (!ToxID::isToxId(toxId)) { if (!silent) showWarning(tr("The DNS lookup does not contain a valid Tox ID", "Error with the DNS")); @@ -201,7 +201,7 @@ QString ToxDNS::queryTox3(const tox3_server& server, const QString &record, bool idx += 3; id = entry.mid(idx).toUtf8(); - uint8_t toxId[TOX_FRIEND_ADDRESS_SIZE]; + uint8_t toxId[TOX_ADDRESS_SIZE]; toxIdSize = tox_decrypt_dns3_TXT(tox_dns3, toxId, (uint8_t*)id.data(), id.size(), request_id); if (toxIdSize < 0) // We can always fallback on tox1 if toxdns3 fails { diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 48208c808..3097eaac8 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -254,7 +254,7 @@ void ChatForm::onFileRecvRequest(ToxFile file) } } -void ChatForm::onAvInvite(int FriendId, int CallId, bool video) +void ChatForm::onAvInvite(uint32_t FriendId, int CallId, bool video) { if (FriendId != f->getFriendID()) return; @@ -306,7 +306,7 @@ void ChatForm::onAvInvite(int FriendId, int CallId, bool video) } } -void ChatForm::onAvStart(int FriendId, int CallId, bool video) +void ChatForm::onAvStart(uint32_t FriendId, int CallId, bool video) { if (FriendId != f->getFriendID()) return; @@ -357,7 +357,7 @@ void ChatForm::onAvStart(int FriendId, int CallId, bool video) startCounter(); } -void ChatForm::onAvCancel(int FriendId, int) +void ChatForm::onAvCancel(uint32_t FriendId, int) { if (FriendId != f->getFriendID()) return; @@ -375,7 +375,7 @@ void ChatForm::onAvCancel(int FriendId, int) addSystemInfoMessage(tr("%1 stopped calling").arg(f->getDisplayedName()), ChatMessage::INFO, QDateTime::currentDateTime()); } -void ChatForm::onAvEnd(int FriendId, int) +void ChatForm::onAvEnd(uint32_t FriendId, int) { if (FriendId != f->getFriendID()) return; @@ -390,7 +390,7 @@ void ChatForm::onAvEnd(int FriendId, int) netcam->hide(); } -void ChatForm::onAvRinging(int FriendId, int CallId, bool video) +void ChatForm::onAvRinging(uint32_t FriendId, int CallId, bool video) { if (FriendId != f->getFriendID()) return; @@ -426,7 +426,7 @@ void ChatForm::onAvRinging(int FriendId, int CallId, bool video) addSystemInfoMessage(tr("Calling to %1").arg(f->getDisplayedName()), ChatMessage::INFO, QDateTime::currentDateTime()); } -void ChatForm::onAvStarting(int FriendId, int CallId, bool video) +void ChatForm::onAvStarting(uint32_t FriendId, int CallId, bool video) { if (FriendId != f->getFriendID()) return; @@ -461,7 +461,7 @@ void ChatForm::onAvStarting(int FriendId, int CallId, bool video) startCounter(); } -void ChatForm::onAvEnding(int FriendId, int) +void ChatForm::onAvEnding(uint32_t FriendId, int) { if (FriendId != f->getFriendID()) return; @@ -477,7 +477,7 @@ void ChatForm::onAvEnding(int FriendId, int) netcam->hide(); } -void ChatForm::onAvRequestTimeout(int FriendId, int) +void ChatForm::onAvRequestTimeout(uint32_t FriendId, int) { if (FriendId != f->getFriendID()) return; @@ -493,7 +493,7 @@ void ChatForm::onAvRequestTimeout(int FriendId, int) netcam->hide(); } -void ChatForm::onAvPeerTimeout(int FriendId, int) +void ChatForm::onAvPeerTimeout(uint32_t FriendId, int) { if (FriendId != f->getFriendID()) return; @@ -509,7 +509,7 @@ void ChatForm::onAvPeerTimeout(int FriendId, int) netcam->hide(); } -void ChatForm::onAvRejected(int FriendId, int) +void ChatForm::onAvRejected(uint32_t FriendId, int) { if (FriendId != f->getFriendID()) return; @@ -526,7 +526,7 @@ void ChatForm::onAvRejected(int FriendId, int) netcam->hide(); } -void ChatForm::onAvMediaChange(int FriendId, int CallId, bool video) +void ChatForm::onAvMediaChange(uint32_t FriendId, int CallId, bool video) { if (FriendId != f->getFriendID() || CallId != callId) return; @@ -601,7 +601,7 @@ void ChatForm::onCallTriggered() audioOutputFlag = true; callButton->disconnect(); videoButton->disconnect(); - emit startCall(f->getFriendID()); + emit startCall(f->getFriendID(), false); } void ChatForm::onVideoCallTriggered() @@ -612,10 +612,10 @@ void ChatForm::onVideoCallTriggered() audioOutputFlag = true; callButton->disconnect(); videoButton->disconnect(); - emit startVideoCall(f->getFriendID(), true); + emit startCall(f->getFriendID(), true); } -void ChatForm::onAvCallFailed(int FriendId) +void ChatForm::onAvCallFailed(uint32_t FriendId) { if (FriendId != f->getFriendID()) return; @@ -737,7 +737,7 @@ void ChatForm::onVolMuteToggle() } } -void ChatForm::onFileSendFailed(int FriendId, const QString &fname) +void ChatForm::onFileSendFailed(uint32_t FriendId, const QString &fname) { if (FriendId != f->getFriendID()) return; @@ -745,7 +745,7 @@ void ChatForm::onFileSendFailed(int FriendId, const QString &fname) addSystemInfoMessage(tr("Failed to send file \"%1\"").arg(fname), ChatMessage::ERROR, QDateTime::currentDateTime()); } -void ChatForm::onAvatarChange(int FriendId, const QPixmap &pic) +void ChatForm::onAvatarChange(uint32_t FriendId, const QPixmap &pic) { if (FriendId != f->getFriendID()) return; @@ -787,7 +787,7 @@ void ChatForm::dropEvent(QDropEvent *ev) } } -void ChatForm::onAvatarRemoved(int FriendId) +void ChatForm::onAvatarRemoved(uint32_t FriendId) { if (FriendId != f->getFriendID()) return; diff --git a/src/widget/form/chatform.h b/src/widget/form/chatform.h index 7be0427b3..0af254646 100644 --- a/src/widget/form/chatform.h +++ b/src/widget/form/chatform.h @@ -25,7 +25,7 @@ #include -struct Friend; +class Friend; class FileTransferInstance; class NetCamView; class QPixmap; @@ -50,12 +50,11 @@ public: virtual void show(Ui::MainWindow &ui); signals: - void sendFile(int32_t friendId, QString, QString, long long); - void startCall(int friendId); - void startVideoCall(int friendId, bool video); + void sendFile(uint32_t friendId, QString, QString, long long); + void startCall(uint32_t FriendId, bool video); void answerCall(int callId); void hangupCall(int callId); - void cancelCall(int callId, int friendId); + void cancelCall(int callId, uint32_t FriendId); void rejectCall(int callId); void micMuteToggle(int callId); void volMuteToggle(int callId); @@ -64,22 +63,22 @@ signals: public slots: void startFileSend(ToxFile file); void onFileRecvRequest(ToxFile file); - void onAvInvite(int FriendId, int CallId, bool video); - void onAvStart(int FriendId, int CallId, bool video); - void onAvCancel(int FriendId, int CallId); - void onAvEnd(int FriendId, int CallId); - void onAvRinging(int FriendId, int CallId, bool video); - void onAvStarting(int FriendId, int CallId, bool video); - void onAvEnding(int FriendId, int CallId); - void onAvRequestTimeout(int FriendId, int CallId); - void onAvPeerTimeout(int FriendId, int CallId); - void onAvMediaChange(int FriendId, int CallId, bool video); - void onAvCallFailed(int FriendId); - void onAvRejected(int FriendId, int CallId); + void onAvInvite(uint32_t FriendId, int CallId, bool video); + void onAvStart(uint32_t FriendId, int CallId, bool video); + void onAvCancel(uint32_t FriendId, int CallId); + void onAvEnd(uint32_t FriendId, int CallId); + void onAvRinging(uint32_t FriendId, int CallId, bool video); + void onAvStarting(uint32_t FriendId, int CallId, bool video); + void onAvEnding(uint32_t FriendId, int CallId); + void onAvRequestTimeout(uint32_t FriendId, int CallId); + void onAvPeerTimeout(uint32_t FriendId, int CallId); + void onAvMediaChange(uint32_t FriendId, int CallId, bool video); + void onAvCallFailed(uint32_t FriendId); + void onAvRejected(uint32_t FriendId, int CallId); void onMicMuteToggle(); void onVolMuteToggle(); - void onAvatarChange(int FriendId, const QPixmap& pic); - void onAvatarRemoved(int FriendId); + void onAvatarChange(uint32_t FriendId, const QPixmap& pic); + void onAvatarRemoved(uint32_t FriendId); private slots: void onSendTriggered(); @@ -91,7 +90,7 @@ private slots: void onHangupCallTriggered(); void onCancelCallTriggered(); void onRejectCallTriggered(); - void onFileSendFailed(int FriendId, const QString &fname); + void onFileSendFailed(uint32_t FriendId, const QString &fname); void onLoadHistory(); void onUpdateTime(); void onEnableCallButtons(); diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 499daee3b..d5bb407a3 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -60,8 +60,8 @@ public: ChatLog* getChatLog() const; signals: - void sendMessage(int, QString); - void sendAction(int, QString); + void sendMessage(uint32_t, QString); + void sendAction(uint32_t, QString); void chatAreaCleared(); public slots: diff --git a/src/widget/form/profileform.cpp b/src/widget/form/profileform.cpp index 7d7d09920..68c5bc06a 100644 --- a/src/widget/form/profileform.cpp +++ b/src/widget/form/profileform.cpp @@ -214,22 +214,7 @@ void ProfileForm::onAvatarClicked() pic.save(&buffer, "PNG"); buffer.close(); - if (bytes.size() >= TOX_AVATAR_MAX_DATA_LENGTH) - { - pic = pic.scaled(64,64, Qt::KeepAspectRatio, Qt::SmoothTransformation); - bytes.clear(); - buffer.open(QIODevice::WriteOnly); - pic.save(&buffer, "PNG"); - buffer.close(); - } - - if (bytes.size() >= TOX_AVATAR_MAX_DATA_LENGTH) - { - GUI::showError(tr("Error"), tr("This image is too big")); - return; - } - - Nexus::getCore()->setAvatar(TOX_AVATAR_FORMAT_PNG, bytes); + Nexus::getCore()->setAvatar(bytes); } void ProfileForm::onLoadClicked() diff --git a/src/widget/friendlistwidget.cpp b/src/widget/friendlistwidget.cpp index ad665666a..5a5e481bb 100644 --- a/src/widget/friendlistwidget.cpp +++ b/src/widget/friendlistwidget.cpp @@ -87,7 +87,7 @@ void FriendListWidget::onGroupchatPositionChanged(bool top) } } -void FriendListWidget::moveWidget(QWidget *w, Status s, int hasNewEvents) +void FriendListWidget::moveWidget(QWidget *w, Status s) { QVBoxLayout* l = getFriendLayout(s); l->removeWidget(w); diff --git a/src/widget/friendlistwidget.h b/src/widget/friendlistwidget.h index 70101b885..56aa4deee 100644 --- a/src/widget/friendlistwidget.h +++ b/src/widget/friendlistwidget.h @@ -37,7 +37,7 @@ signals: public slots: void onGroupchatPositionChanged(bool top); - void moveWidget(QWidget *w, Status s, int hasNewEvents); + void moveWidget(QWidget *w, Status s); private: QHash layouts; diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index fdb4e5591..8e08f1f41 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -580,7 +580,7 @@ void Widget::addFriend(int friendId, const QString &userId) //qDebug() << "Widget: Adding friend with id" << userId; ToxID userToxId = ToxID::fromString(userId); Friend* newfriend = FriendList::addFriend(friendId, userToxId); - contactListWidget->moveWidget(newfriend->getFriendWidget(),Status::Offline,0); + contactListWidget->moveWidget(newfriend->getFriendWidget(),Status::Offline); Core* core = Nexus::getCore(); connect(newfriend, &Friend::displayedNameChanged, contactListWidget, &FriendListWidget::moveWidget); @@ -589,17 +589,16 @@ void Widget::addFriend(int friendId, const QString &userId) connect(newfriend->getFriendWidget(), SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int))); connect(newfriend->getFriendWidget(), SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int))); connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newfriend->getChatForm(), SLOT(focusInput())); - connect(newfriend->getChatForm(), SIGNAL(sendMessage(int,QString)), core, SLOT(sendMessage(int,QString))); + connect(newfriend->getChatForm(), &GenericChatForm::sendMessage, core, &Core::sendMessage); connect(newfriend->getChatForm(), &GenericChatForm::sendAction, core, &Core::sendAction); - connect(newfriend->getChatForm(), SIGNAL(sendFile(int32_t, QString, QString, long long)), core, SLOT(sendFile(int32_t, QString, QString, long long))); - connect(newfriend->getChatForm(), SIGNAL(answerCall(int)), core, SLOT(answerCall(int))); - connect(newfriend->getChatForm(), SIGNAL(hangupCall(int)), core, SLOT(hangupCall(int))); - connect(newfriend->getChatForm(), SIGNAL(rejectCall(int)), core, SLOT(rejectCall(int))); - connect(newfriend->getChatForm(), SIGNAL(startCall(int)), core, SLOT(startCall(int))); - connect(newfriend->getChatForm(), SIGNAL(startVideoCall(int,bool)), core, SLOT(startCall(int,bool))); - connect(newfriend->getChatForm(), SIGNAL(cancelCall(int,int)), core, SLOT(cancelCall(int,int))); - connect(newfriend->getChatForm(), SIGNAL(micMuteToggle(int)), core, SLOT(micMuteToggle(int))); - connect(newfriend->getChatForm(), SIGNAL(volMuteToggle(int)), core, SLOT(volMuteToggle(int))); + connect(newfriend->getChatForm(), &ChatForm::sendFile, core, &Core::sendFile); + connect(newfriend->getChatForm(), &ChatForm::answerCall, core, &Core::answerCall); + connect(newfriend->getChatForm(), &ChatForm::hangupCall, core, &Core::hangupCall); + connect(newfriend->getChatForm(), &ChatForm::rejectCall, core, &Core::rejectCall); + connect(newfriend->getChatForm(), &ChatForm::startCall, core, &Core::startCall); + connect(newfriend->getChatForm(), &ChatForm::cancelCall, core, &Core::cancelCall); + connect(newfriend->getChatForm(), &ChatForm::micMuteToggle, core, &Core::micMuteToggle); + connect(newfriend->getChatForm(), &ChatForm::volMuteToggle, core, &Core::volMuteToggle); connect(newfriend->getChatForm(), &ChatForm::aliasChanged, newfriend->getFriendWidget(), &FriendWidget::setAlias); connect(core, &Core::fileReceiveRequested, newfriend->getChatForm(), &ChatForm::onFileRecvRequest); connect(core, &Core::avInvite, newfriend->getChatForm(), &ChatForm::onAvInvite); @@ -651,11 +650,11 @@ void Widget::onFriendStatusChanged(int friendId, Status status) { if (f->getStatus() == Status::Offline) { - contactListWidget->moveWidget(f->getFriendWidget(), Status::Online, f->getEventFlag()); + contactListWidget->moveWidget(f->getFriendWidget(), Status::Online); } else if (status == Status::Offline) { - contactListWidget->moveWidget(f->getFriendWidget(), Status::Offline, f->getEventFlag()); + contactListWidget->moveWidget(f->getFriendWidget(), Status::Offline); } } @@ -999,8 +998,8 @@ Group *Widget::createGroup(int groupId) connect(newgroup->getGroupWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*))); connect(newgroup->getGroupWidget(), SIGNAL(removeGroup(int)), this, SLOT(removeGroup(int))); connect(newgroup->getGroupWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newgroup->getChatForm(), SLOT(focusInput())); - connect(newgroup->getChatForm(), SIGNAL(sendMessage(int,QString)), core, SLOT(sendGroupMessage(int,QString))); - connect(newgroup->getChatForm(), SIGNAL(sendAction(int,QString)), core, SLOT(sendGroupAction(int,QString))); + connect(newgroup->getChatForm(), &GroupChatForm::sendMessage, core, &Core::sendGroupMessage); + connect(newgroup->getChatForm(), &GroupChatForm::sendAction, core, &Core::sendGroupAction); connect(newgroup->getChatForm(), &GroupChatForm::groupTitleChanged, core, &Core::changeGroupTitle); return newgroup; } @@ -1139,7 +1138,7 @@ void Widget::setStatusBusy() Nexus::getCore()->setStatus(Status::Busy); } -void Widget::onMessageSendResult(int friendId, const QString& message, int messageId) +void Widget::onMessageSendResult(uint32_t friendId, const QString& message, int messageId) { Q_UNUSED(message) Q_UNUSED(messageId) diff --git a/src/widget/widget.h b/src/widget/widget.h index 001b55f2c..73e299d52 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -35,7 +35,7 @@ class MainWindow; class GenericChatroomWidget; class Group; -struct Friend; +class Friend; class QSplitter; class VideoSurface; class QMenu; @@ -104,6 +104,7 @@ public slots: void onFriendUsernameChanged(int friendId, const QString& username); void onFriendMessageReceived(int friendId, const QString& message, bool isAction); void onFriendRequestReceived(const QString& userId, const QString& message); + void onMessageSendResult(uint32_t friendId, const QString& message, int messageId); void onReceiptRecieved(int friendId, int receipt); void onEmptyGroupCreated(int groupId); void onGroupInviteReceived(int32_t friendId, uint8_t type, QByteArray invite); @@ -111,6 +112,7 @@ public slots: void onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t change); void onGroupTitleChanged(int groupnumber, const QString& author, const QString& title); void onGroupPeerAudioPlaying(int groupnumber, int peernumber); + void onGroupSendResult(int groupId, const QString& message, int result); void playRingtone(); void onFriendTypingChanged(int friendId, bool isTyping); void nextContact(); @@ -140,8 +142,6 @@ private slots: void setStatusOnline(); void setStatusAway(); void setStatusBusy(); - void onMessageSendResult(int friendId, const QString& message, int messageId); - void onGroupSendResult(int groupId, const QString& message, int result); void onIconClick(QSystemTrayIcon::ActivationReason); void onUserAwayCheck(); void onEventIconTick();