1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Refactor Core

Refactor Core's file transfer callbacks into their CoreFile class and files

Move all core*.{h|cpp} into a core/ folder
This commit is contained in:
tux3 2015-04-24 02:32:09 +02:00
parent a70721818e
commit e4859efe18
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
48 changed files with 161 additions and 404 deletions

View File

@ -409,10 +409,6 @@ contains(ENABLE_SYSTRAY_GTK_BACKEND, NO) {
SOURCES += \
src/audio.cpp \
src/core.cpp \
src/coreav.cpp \
src/coreencryption.cpp \
src/corestructs.cpp \
src/historykeeper.cpp \
src/main.cpp \
src/nexus.cpp \
@ -428,14 +424,20 @@ SOURCES += \
src/video/videoframe.cpp \
src/widget/gui.cpp \
src/toxme.cpp \
src/misc/qrwidget.cpp
src/misc/qrwidget.cpp \
src/core/core.cpp \
src/core/coreav.cpp \
src/core/coreencryption.cpp \
src/core/corefile.cpp \
src/core/corestructs.cpp \
HEADERS += \
src/audio.h \
src/core.h \
src/corestructs.h \
src/coredefines.h \
src/coreav.h \
src/core/core.h \
src/core/coreav.h \
src/core/coredefines.h \
src/core/corefile.h \
src/core/corestructs.h \
src/historykeeper.h \
src/nexus.h \
src/misc/cdata.h \
@ -448,6 +450,7 @@ HEADERS += \
src/video/cameraworker.h \
src/video/videoframe.h \
src/video/videosource.h \
src/video/netvideosource.h \
src/widget/gui.h \
src/toxme.h \
src/misc/qrwidget.h
src/misc/qrwidget.h \

View File

@ -24,7 +24,7 @@
#define FIX_SND_PCM_PREPARE_BUG 0
#include "audio.h"
#include "src/core.h"
#include "src/core/core.h"
#include <QDebug>
#include <QThread>

View File

@ -18,7 +18,7 @@
#define CHATMESSAGE_H
#include "chatline.h"
#include "src/corestructs.h"
#include "src/core/corestructs.h"
#include <QDateTime>
class QGraphicsScene;

View File

@ -18,7 +18,7 @@
#include "ui_filetransferwidget.h"
#include "src/nexus.h"
#include "src/core.h"
#include "src/core/core.h"
#include "src/misc/style.h"
#include "src/widget/widget.h"

View File

@ -20,8 +20,8 @@
#include <QWidget>
#include <QTime>
#include "../chatlinecontent.h"
#include "../../corestructs.h"
#include "src/chatlog/chatlinecontent.h"
#include "src/core/corestructs.h"
namespace Ui {

View File

@ -15,13 +15,14 @@
*/
#include "core.h"
#include "nexus.h"
#include "misc/cdata.h"
#include "misc/cstring.h"
#include "misc/settings.h"
#include "widget/gui.h"
#include "historykeeper.h"
#include "src/nexus.h"
#include "src/misc/cdata.h"
#include "src/misc/cstring.h"
#include "src/misc/settings.h"
#include "src/widget/gui.h"
#include "src/historykeeper.h"
#include "src/audio.h"
#include "corefile.h"
#include <tox/tox.h>
@ -70,7 +71,6 @@ Core::Core(Camera* cam, QThread *CoreThread, QString loadPath) :
connect(toxTimer, &QTimer::timeout, this, &Core::process);
//connect(fileTimer, &QTimer::timeout, this, &Core::fileHeartbeat);
connect(&Settings::getInstance(), &Settings::dhtServerListChanged, this, &Core::process);
connect(this, SIGNAL(fileTransferFinished(ToxFile)), this, SLOT(onFileTransferFinished(ToxFile)));
for (int i=0; i<TOXAV_MAX_CALLS;i++)
{
@ -277,17 +277,16 @@ void Core::start()
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_friend_read_receipt(tox, onReadReceiptCallback, 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_friend_read_receipt(tox, onReadReceiptCallback, this);
tox_callback_file_chunk_request(tox, CoreFile::onFileDataCallback, this);
tox_callback_file_recv(tox, CoreFile::onFileReceiveCallback, this);
tox_callback_file_recv_chunk(tox, CoreFile::onFileRecvChunkCallback, this);
tox_callback_file_recv_control(tox, CoreFile::onFileControlCallback, this);
toxav_register_callstate_callback(toxav, onAvInvite, av_OnInvite, this);
toxav_register_callstate_callback(toxav, onAvStart, av_OnStart, this);
@ -566,211 +565,6 @@ void Core::onGroupTitleChange(Tox*, int groupnumber, int peernumber, const uint8
emit core->groupTitleChanged(groupnumber, author, CString::toString(title, len));
}
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);
ToxFile file{filenumber, friendnumber,
CString::toString(filename,filename_length).toUtf8(), "", ToxFile::RECEIVING};
file.filesize = filesize;
fileRecvQueue.append(file);
emit static_cast<Core*>(core)->fileReceiveRequested(fileRecvQueue.last());
}
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};
if (receive_send == 1)
{
for (ToxFile& f : fileSendQueue)
{
if (f.fileNum == filenumber && f.friendId == friendnumber)
{
file = &f;
break;
}
}
}
else
{
for (ToxFile& f : fileRecvQueue)
{
if (f.fileNum == filenumber && f.friendId == friendnumber)
{
file = &f;
break;
}
}
}
if (!file)
{
qWarning("Core::onFileControlCallback: No such file in queue");
return;
}
if (receive_send == 1 && control_type == TOX_FILE_CONTROL_RESUME)
{
file->status = ToxFile::TRANSMITTING;
emit static_cast<Core*>(core)->fileTransferAccepted(*file);
qDebug() << "Core: File control callback, file accepted";
file->sendTimer = new QTimer(static_cast<Core*>(core));
connect(file->sendTimer, &QTimer::timeout, std::bind(sendAllFileData,static_cast<Core*>(core), file));
file->sendTimer->setSingleShot(true);
file->sendTimer->start(TOX_FILE_INTERVAL);
}
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);
file->status = ToxFile::STOPPED;
emit static_cast<Core*>(core)->fileTransferCancelled(*file);
// Wait for sendAllFileData to return before deleting the ToxFile, we MUST ensure this or we'll use after free
if (file->sendTimer)
{
QThread::msleep(1);
qApp->processEvents();
if (file->sendTimer)
{
delete file->sendTimer;
file->sendTimer = nullptr;
}
}
removeFileFromQueue((bool)receive_send, file->friendId, file->fileNum);
}
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);
file->status = ToxFile::STOPPED;
emit static_cast<Core*>(core)->fileTransferFinished(*file);
removeFileFromQueue((bool)receive_send, file->friendId, file->fileNum);
}
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);
file->status = ToxFile::STOPPED;
emit static_cast<Core*>(core)->fileTransferCancelled(*file);
removeFileFromQueue((bool)receive_send, file->friendId, file->fileNum);
}
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*>(core)->fileTransferFinished(*file);
// confirm receive is complete
///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_FILE_CONTROL_RESUME)
{
if (file->status == ToxFile::BROKEN)
{
emit static_cast<Core*>(core)->fileTransferBrokenUnbroken(*file, false);
file->status = ToxFile::TRANSMITTING;
}
emit static_cast<Core*>(core)->fileTransferRemotePausedUnpaused(*file, false);
}
else if ((receive_send == 0 || receive_send == 1) && control_type == TOX_FILE_CONTROL_PAUSE)
{
emit static_cast<Core*>(core)->fileTransferRemotePausedUnpaused(*file, true);
}
else if (receive_send == 1 && control_type == TOX_FILE_CONTROL_RESUME)
{
if (length != sizeof(uint64_t))
return;
qDebug() << "Core::onFileControlCallback: TOX_FILECONTROL_RESUME_BROKEN";
uint64_t resumePos = *reinterpret_cast<const uint64_t*>(data);
if (resumePos >= (unsigned)file->filesize)
{
qWarning() << "Core::onFileControlCallback: invalid resume position";
tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_CANCEL, nullptr); // don't sure about it
return;
}
file->status = ToxFile::TRANSMITTING;
emit static_cast<Core*>(core)->fileTransferBrokenUnbroken(*file, false);
file->bytesSent = resumePos;
tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_RESUME, nullptr);
}
else
{
qDebug() << QString("Core: File control callback, receive_send=%1, control_type=%2")
.arg(receive_send).arg(control_type);
}
}
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)
{
if (f.fileNum == filenumber && f.friendId == friendnumber)
{
file = &f;
break;
}
}
if (!file)
{
qWarning("Core::onFileDataCallback: No such file in queue");
return;
}
file->file->write((char*)data,length);
file->bytesSent += length;
//qDebug() << QString("Core::onFileDataCallback: received %1/%2 bytes").arg(file->bytesSent).arg(file->filesize);
emit static_cast<Core*>(core)->fileTransferInfo(*file);
}
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*>(_core);
if (format == TOX_AVATAR_FORMAT_NONE)
{
//qDebug() << "Core: Got null avatar info from" << core->getFriendUsername(friendnumber);
emit core->friendAvatarRemoved(friendnumber);
QFile::remove(QDir(Settings::getSettingsDirPath()).filePath("avatars/"+core->getFriendAddress(friendnumber).left(64)+".png"));
QFile::remove(QDir(Settings::getSettingsDirPath()).filePath("avatars/"+core->getFriendAddress(friendnumber).left(64)+".hash"));
}
else
{
QByteArray oldHash = Settings::getInstance().getAvatarHash(core->getFriendAddress(friendnumber));
if (QByteArray((char*)hash, TOX_HASH_LENGTH) != oldHash)
// comparison failed miserably if I didn't convert hash to QByteArray
{
qDebug() << "Core: Got new avatar info from" << core->getFriendUsername(friendnumber);
tox_request_avatar_data(core->tox, friendnumber);
}
//else
// qDebug() << "Core: Got same avatar info from" << core->getFriendUsername(friendnumber);
}
*/
}
void Core::onAvatarDataCallback(Tox*, uint32_t friendnumber, uint8_t,
uint8_t *hash, uint8_t *data, uint32_t datalen, void *core)
{
QPixmap pic;
pic.loadFromData((uchar*)data, datalen);
if (!pic.isNull())
{
qDebug() << "Core: Got avatar data from" << static_cast<Core*>(core)->getFriendUsername(friendnumber);
Settings::getInstance().saveAvatar(pic, static_cast<Core*>(core)->getFriendAddress(friendnumber));
Settings::getInstance().saveAvatarHash(QByteArray((char*)hash, TOX_HASH_LENGTH), static_cast<Core*>(core)->getFriendAddress(friendnumber));
emit static_cast<Core*>(core)->friendAvatarChanged(friendnumber, pic);
}
}
void Core::onReadReceiptCallback(Tox*, uint32_t friendnumber, uint32_t receipt, void *core)
{
emit static_cast<Core*>(core)->receiptRecieved(friendnumber, receipt);
@ -1213,14 +1007,6 @@ void Core::setStatus(Status status)
emit statusSet(status);
}
void Core::onFileTransferFinished(ToxFile file)
{
if (file.direction == file.SENDING)
emit fileUploadFinished(file.filePath);
else
emit fileDownloadFinished(file.filePath);
}
QString Core::sanitize(QString name)
{
// these are pretty much Windows banned filename characters
@ -1520,91 +1306,6 @@ void Core::removeFileFromQueue(bool sendQueue, uint32_t friendId, uint32_t fileI
qWarning() << "Core::removeFileFromQueue: No such file in queue";
}
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);
return;
}
else if (file->status == ToxFile::STOPPED)
{
qWarning("Core::sendAllFileData: File is stopped");
file->sendTimer->disconnect();
delete file->sendTimer;
file->sendTimer = nullptr;
return;
}
emit core->fileTransferInfo(*file);
// qApp->processEvents();
long long chunkSize = tox_file_data_size(core->tox, file->friendId);
if (chunkSize == -1)
{
qWarning("Core::fileHeartbeat: Error getting preffered chunk size, aborting file send");
file->status = ToxFile::STOPPED;
emit core->fileTransferCancelled(*file);
tox_file_control(core->tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_CANCEL, nullptr);
removeFileFromQueue(true, file->friendId, file->fileNum);
return;
}
//qDebug() << "chunkSize: " << chunkSize;
chunkSize = std::min(chunkSize, file->filesize);
uint8_t* data = new uint8_t[chunkSize];
file->file->seek(file->bytesSent);
int readSize = file->file->read((char*)data, chunkSize);
if (readSize == -1)
{
qWarning() << QString("Core::sendAllFileData: Error reading from file: %1").arg(file->file->errorString());
delete[] data;
file->status = ToxFile::STOPPED;
emit core->fileTransferCancelled(*file);
tox_file_control(core->tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_CANCEL, nullptr);
removeFileFromQueue(true, file->friendId, file->fileNum);
return;
}
else if (readSize == 0)
{
qWarning() << QString("Core::sendAllFileData: Nothing to read from file: %1").arg(file->file->errorString());
delete[] data;
file->status = ToxFile::STOPPED;
emit core->fileTransferCancelled(*file);
tox_file_control(core->tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_CANCEL, nullptr);
removeFileFromQueue(true, file->friendId, file->fileNum);
return;
}
if (tox_file_send_data(core->tox, file->friendId, file->fileNum, data, readSize) == -1)
{
//qWarning("Core::fileHeartbeat: Error sending data chunk");
//core->process();
delete[] data;
//QThread::msleep(1);
file->sendTimer->start(1+TOX_FILE_INTERVAL);
return;
}
delete[] data;
file->bytesSent += readSize;
//qDebug() << QString("Core::fileHeartbeat: sent %1/%2 bytes").arg(file->bytesSent).arg(file->fileData.size());
if (file->bytesSent < file->filesize)
{
file->sendTimer->start(TOX_FILE_INTERVAL);
return;
}
else
{
//qDebug("Core: File transfer finished");
file->sendTimer->disconnect();
delete file->sendTimer;
file->sendTimer = nullptr;
/// 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(uint32_t friendId, int groupId)
{
tox_invite_friend(tox, friendId, groupId);

View File

@ -226,25 +226,26 @@ signals:
void videoFrameReceived(vpx_image* frame);
private:
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 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 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, 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, uint32_t friendnumber, uint8_t filenumber, uint64_t filesize,
const uint8_t *filename, uint16_t filename_length, void *userdata);
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, 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 onGroupAction(Tox* tox, int groupnumber, int peernumber, const uint8_t * action,
uint16_t length, void* core);
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 groupId, int peerId, uint8_t change, void *core);
static void onGroupTitleChange(Tox*, int groupnumber, int peernumber,
const uint8_t* title, uint8_t len, void* _core);
static void onReadReceiptCallback(Tox *tox, uint32_t friendnumber, uint32_t receipt, void *core);
static void onAvInvite(void* toxav, int32_t call_index, void* core);
@ -261,9 +262,11 @@ private:
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 playCallAudio(void *toxav, int32_t callId, const int16_t *data,
uint16_t samples, void *user_data); // Callback
static void sendCallAudio(int callId, ToxAv* toxav);
static void playAudioBuffer(ALuint alSource, const int16_t *data, int samples, unsigned channels, int sampleRate);
static void playAudioBuffer(ALuint alSource, const int16_t *data, int samples,
unsigned channels, int sampleRate);
static void playCallVideo(void *toxav, int32_t callId, const vpx_image_t* img, void *user_data);
void sendCallVideo(int callId);
@ -275,16 +278,12 @@ private:
void make_tox(QByteArray savedata);
void loadFriends();
static void sendAllFileData(Core* core, ToxFile* file);
static void removeFileFromQueue(bool sendQueue, uint32_t friendId, uint32_t fileId);
void checkLastOnline(uint32_t friendId);
void deadifyTox();
private slots:
void onFileTransferFinished(ToxFile file);
private:
Tox* tox;
ToxAv* toxav;

View File

@ -15,12 +15,12 @@
*/
#include "core.h"
#include "video/camera.h"
#include "audio.h"
#include "src/video/camera.h"
#include "src/audio.h"
#ifdef QTOX_FILTER_AUDIO
#include "audiofilterer.h"
#include "src/audiofilterer.h"
#endif
#include "misc/settings.h"
#include "src/misc/settings.h"
#include <QDebug>
#include <QTimer>
@ -122,7 +122,7 @@ fail: // Centralized error handling
void Core::answerCall(int32_t callId)
{
uint32_t friendId = toxav_get_peer_id(toxav, callId, 0);
int friendId = toxav_get_peer_id(toxav, callId, 0);
if (friendId < 0)
{
qWarning() << "Core: Received invalid AV answer peer ID";
@ -354,7 +354,7 @@ void Core::onAvCancel(void* _toxav, int32_t callId, void* core)
{
ToxAv* toxav = static_cast<ToxAv*>(_toxav);
uint32_t friendId = toxav_get_peer_id(toxav, callId, 0);
int 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*>(_toxav);
uint32_t friendId = toxav_get_peer_id(toxav, callId, 0);
int 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*>(_toxav);
uint32_t friendId = toxav_get_peer_id(toxav, call_index, 0);
int 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*>(_toxav);
uint32_t friendId = toxav_get_peer_id(toxav, call_index, 0);
int 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*>(_toxav);
uint32_t friendId = toxav_get_peer_id(toxav, call_index, 0);
int 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*>(_toxav);
uint32_t friendId = toxav_get_peer_id(toxav, call_index, 0);
int 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*>(_toxav);
uint32_t friendId = toxav_get_peer_id(toxav, call_index, 0);
int 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*>(_toxav);
uint32_t friendId = toxav_get_peer_id(toxav, call_index, 0);
int friendId = toxav_get_peer_id(toxav, call_index, 0);
if (friendId < 0)
{
qWarning() << "Core: Received invalid AV start";

View File

@ -3,7 +3,7 @@
#include <QHash>
#include <tox/toxav.h>
#include "video/netvideosource.h"
#include "src/video/netvideosource.h"
#if defined(__APPLE__) && defined(__MACH__)
#include <OpenAL/al.h>

View File

@ -21,8 +21,8 @@
#include "core.h"
#include "src/widget/gui.h"
#include "src/misc/settings.h"
#include "misc/cstring.h"
#include "historykeeper.h"
#include "src/misc/cstring.h"
#include "src/historykeeper.h"
#include <tox/tox.h>
#include <tox/toxencryptsave.h>
#include <QApplication>

26
src/core/corefile.cpp Normal file
View File

@ -0,0 +1,26 @@
#include "corefile.h"
#include <QDebug>
void CoreFile::onFileReceiveCallback(Tox*, uint32_t friendId, uint32_t fileId, uint32_t kind,
uint64_t filesize, const uint8_t *fname, size_t fnameLen, void *core)
{
qDebug() << QString("Core: Received file request %1:%2").arg(friendId).arg(fileId);
}
void CoreFile::onFileControlCallback(Tox* tox, uint32_t friendnumber, uint32_t filenumber,
TOX_FILE_CONTROL control, void *core)
{
qDebug() << "File control "<<control<<" for file "<<friendnumber<<':'<<filenumber;
}
void CoreFile::onFileDataCallback(Tox *tox, uint32_t friendnumber, uint32_t filenumber,
uint64_t pos, size_t length, void *core)
{
qDebug() << "File data req of "<<length<<" at "<<pos<<" for file "<<friendnumber<<':'<<filenumber;
}
void CoreFile::onFileRecvChunkCallback(Tox *tox, uint32_t friendId, uint32_t fileId, uint64_t position,
const uint8_t *data, size_t length, void *core)
{
qDebug() << QString("Core: Received file chunk for request %1:%2").arg(friendId).arg(fileId);
}

28
src/core/corefile.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef COREFILE_H
#define COREFILE_H
#include <cstdint>
#include <cstddef>
#include <tox/tox.h>
struct Tox;
/// Implements Core's file transfer callbacks
/// Avoids polluting core.h with private internal callbacks
class CoreFile
{
private:
CoreFile()=delete;
public:
static void onFileReceiveCallback(Tox*, uint32_t friendnumber, uint32_t fileId, uint32_t kind,
uint64_t filesize, const uint8_t *fname, size_t fnameLen, void *core);
static void onFileControlCallback(Tox *tox, uint32_t friendnumber, uint32_t filenumber,
TOX_FILE_CONTROL control, void *core);
static void onFileDataCallback(Tox *tox, uint32_t friendnumber, uint32_t filenumber,
uint64_t pos, size_t length, void *core);
static void onFileRecvChunkCallback(Tox *tox, uint32_t friendId, uint32_t fileId, uint64_t position,
const uint8_t *data, size_t length, void *core);
};
#endif // COREFILE_H

View File

@ -1,5 +1,5 @@
#include "src/corestructs.h"
#include "src/core.h"
#include "src/core/corestructs.h"
#include "src/core/core.h"
#include <tox/tox.h>
#include <QFile>
#include <QRegularExpression>

View File

@ -19,7 +19,7 @@
#include "widget/friendwidget.h"
#include "widget/form/chatform.h"
#include "widget/gui.h"
#include "src/core.h"
#include "src/core/core.h"
#include "src/misc/settings.h"
Friend::Friend(uint32_t FriendId, const ToxID &UserId)

View File

@ -19,7 +19,7 @@
#include <QObject>
#include <QString>
#include "corestructs.h"
#include "src/core/corestructs.h"
struct FriendWidget;
class ChatForm;

View File

@ -19,7 +19,7 @@
#include "widget/form/groupchatform.h"
#include "friendlist.h"
#include "friend.h"
#include "core.h"
#include "src/core/core.h"
#include "widget/gui.h"
#include <QDebug>
#include <QTimer>

View File

@ -16,7 +16,7 @@
#include "historykeeper.h"
#include "misc/settings.h"
#include "core.h"
#include "src/core/core.h"
#include <QSqlError>
#include <QFile>

View File

@ -16,7 +16,7 @@
#include "encrypteddb.h"
#include "src/misc/settings.h"
#include "src/core.h"
#include "src/core/core.h"
#include <tox/toxencryptsave.h>

View File

@ -154,18 +154,18 @@ QByteArray rangedSingleToData(float value, float min, float max, int numberOfBit
numberOfBits -= 8;
if (numberOfBits <= 8)
{
data += (unsigned char)source>>8;
data += (unsigned char)(source>>8);
return data;
}
data += (unsigned char)source>>8;
data += (unsigned char)(source>>8);
numberOfBits -= 8;
if (numberOfBits <= 8)
{
data += (unsigned char)source>>16;
data += (unsigned char)(source>>16);
return data;
}
data += (unsigned char)source>>16;
data += (unsigned char)source>>24;
data += (unsigned char)(source>>16);
data += (unsigned char)(source>>24);
return data;
}

View File

@ -16,9 +16,9 @@
#include "settings.h"
#include "smileypack.h"
#include "src/corestructs.h"
#include "src/core/corestructs.h"
#include "src/misc/db/plaindb.h"
#include "src/core.h"
#include "src/core/core.h"
#include "src/widget/gui.h"
#ifdef QTOX_PLATFORM_EXT
#include "src/platform/autorun.h"

View File

@ -1,5 +1,5 @@
#include "nexus.h"
#include "core.h"
#include "src/core/core.h"
#include "misc/settings.h"
#include "video/camera.h"
#include "widget/gui.h"

View File

@ -18,7 +18,7 @@
#include "src/friend.h"
#include "src/historykeeper.h"
#include "src/misc/settings.h"
#include "src/core.h"
#include "src/core/core.h"
#include <QMutexLocker>
#include <QTimer>

View File

@ -18,7 +18,7 @@
#ifndef QTOXDNS_H
#define QTOXDNS_H
#include "src/corestructs.h"
#include "src/core/corestructs.h"
#include <QDnsLookup>
#include <QObject>

View File

@ -1,5 +1,5 @@
#include "toxme.h"
#include "core.h"
#include "src/core/core.h"
#include <QtDebug>
#include <QNetworkAccessManager>
#include <QNetworkReply>

View File

@ -4,7 +4,7 @@
#include <QString>
#include <QMutex>
#include <memory>
#include "corestructs.h"
#include "src/core/corestructs.h"
class QNetworkAccessManager;

View File

@ -2,7 +2,7 @@
#include "ui_android.h"
#include "friendlistwidget.h"
#include "maskablepixmapwidget.h"
#include "src/core.h"
#include "src/core/core.h"
#include "src/friend.h"
#include "src/friendlist.h"
#include "src/group.h"

View File

@ -1,7 +1,7 @@
#ifndef ANDROIDGUI_H
#define ANDROIDGUI_H
#include "src/corestructs.h"
#include "src/core/corestructs.h"
#include <QWidget>
class MaskablePixmapWidget;

View File

@ -23,7 +23,7 @@
#include <tox/tox.h>
#include "ui_mainwindow.h"
#include "src/nexus.h"
#include "src/core.h"
#include "src/core/core.h"
#include "src/misc/cdata.h"
#include "src/toxdns.h"
#include "src/misc/settings.h"

View File

@ -24,7 +24,7 @@
#include <QDragEnterEvent>
#include <QBitmap>
#include "chatform.h"
#include "src/core.h"
#include "src/core/core.h"
#include "src/friend.h"
#include "src/historykeeper.h"
#include "src/misc/style.h"

View File

@ -18,7 +18,7 @@
#define CHATFORM_H
#include "genericchatform.h"
#include "src/corestructs.h"
#include "src/core/corestructs.h"
#include <QSet>
#include <QLabel>
#include <QTimer>

View File

@ -29,7 +29,7 @@
#include "src/misc/settings.h"
#include "src/widget/tool/chattextedit.h"
#include "src/widget/maskablepixmapwidget.h"
#include "src/core.h"
#include "src/core/core.h"
#include "src/grouplist.h"
#include "src/group.h"
#include "src/friendlist.h"

View File

@ -21,7 +21,7 @@
#include <QPoint>
#include <QDateTime>
#include <QMenu>
#include "src/corestructs.h"
#include "src/core/corestructs.h"
#include "src/chatlog/chatmessage.h"
// Spacing in px inserted when the author of the last message changes

View File

@ -21,7 +21,7 @@
#include "src/widget/tool/chattextedit.h"
#include "src/widget/croppinglabel.h"
#include "src/widget/maskablepixmapwidget.h"
#include "src/core.h"
#include "src/core/core.h"
#include "src/misc/style.h"
#include <QPushButton>
#include <QMimeData>

View File

@ -14,7 +14,7 @@
See the COPYING file for more details.
*/
#include "src/core.h"
#include "src/core/core.h"
#include "src/nexus.h"
#include "ui_profileform.h"
#include "profileform.h"

View File

@ -21,7 +21,7 @@
#include <QLabel>
#include <QTimer>
#include <QVBoxLayout>
#include "src/core.h"
#include "src/core/core.h"
#include "src/misc/qrwidget.h"
class CroppingLabel;

View File

@ -20,7 +20,7 @@
#include "src/widget/widget.h"
#include "src/misc/settings.h"
#include "src/misc/smileypack.h"
#include "src/core.h"
#include "src/core/core.h"
#include "src/misc/style.h"
#include <QMessageBox>
#include <QStyleFactory>

View File

@ -19,7 +19,7 @@
#include "src/widget/form/settingswidget.h"
#include "src/misc/settings.h"
#include "src/historykeeper.h"
#include "src/core.h"
#include "src/core/core.h"
#include "src/widget/widget.h"
#include "src/widget/gui.h"
#include "src/widget/form/setpassworddialog.h"

View File

@ -19,7 +19,7 @@
was greatly simplified for use in qTox. */
#include "tabcompleter.h"
#include "src/core.h"
#include "src/core/core.h"
#include "src/group.h"
#include "src/widget/tool/chattextedit.h"
#include <QRegExp>

View File

@ -19,7 +19,7 @@
#include <QWidget>
#include <QHash>
#include "src/corestructs.h"
#include "src/core/corestructs.h"
class QVBoxLayout;
class QGridLayout;

View File

@ -20,7 +20,7 @@
#include "groupwidget.h"
#include "src/friendlist.h"
#include "src/friend.h"
#include "src/core.h"
#include "src/core/core.h"
#include "form/chatform.h"
#include "maskablepixmapwidget.h"
#include "croppinglabel.h"

View File

@ -21,7 +21,7 @@
#include "form/groupchatform.h"
#include "maskablepixmapwidget.h"
#include "src/misc/style.h"
#include "src/core.h"
#include "src/core/core.h"
#include <QPalette>
#include <QMenu>
#include <QContextMenuEvent>

View File

@ -15,7 +15,7 @@
*/
#include "netcamview.h"
#include "src/core.h"
#include "src/core/core.h"
#include "src/widget/videosurface.h"
#include <QLabel>
#include <QHBoxLayout>

View File

@ -16,7 +16,7 @@
#include "toxsave.h"
#include "gui.h"
#include "src/core.h"
#include "src/core/core.h"
#include "src/misc/settings.h"
#include <QCoreApplication>
#include <QDir>

View File

@ -19,7 +19,7 @@
#include "src/toxdns.h"
#include "src/widget/tool/friendrequestdialog.h"
#include "src/nexus.h"
#include "src/core.h"
#include "src/core/core.h"
#include <QByteArray>
#include <QString>
#include <QMessageBox>

View File

@ -16,7 +16,7 @@
#include "widget.h"
#include "ui_mainwindow.h"
#include "src/core.h"
#include "src/core/core.h"
#include "src/misc/settings.h"
#include "src/friend.h"
#include "src/friendlist.h"

View File

@ -25,7 +25,7 @@
#include "form/settingswidget.h"
#include "form/profileform.h"
#include "form/filesform.h"
#include "src/corestructs.h"
#include "src/core/corestructs.h"
#define PIXELS_TO_ACT 7