mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(core): format code
This commit is contained in:
parent
82a7141e31
commit
24e7c4efd4
|
@ -74,7 +74,8 @@ Core::~Core()
|
||||||
* @brief Registers all toxcore callbacks
|
* @brief Registers all toxcore callbacks
|
||||||
* @param tox Tox instance to register the callbacks on
|
* @param tox Tox instance to register the callbacks on
|
||||||
*/
|
*/
|
||||||
void Core::registerCallbacks(Tox * tox) {
|
void Core::registerCallbacks(Tox* tox)
|
||||||
|
{
|
||||||
tox_callback_friend_request(tox, onFriendRequest);
|
tox_callback_friend_request(tox, onFriendRequest);
|
||||||
tox_callback_friend_message(tox, onFriendMessage);
|
tox_callback_friend_message(tox, onFriendMessage);
|
||||||
tox_callback_friend_name(tox, onFriendNameChange);
|
tox_callback_friend_name(tox, onFriendNameChange);
|
||||||
|
@ -328,7 +329,8 @@ void Core::process()
|
||||||
tolerance = 3 * CORE_DISCONNECT_TOLERANCE;
|
tolerance = 3 * CORE_DISCONNECT_TOLERANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned sleeptime = qMin(tox_iteration_interval(tox.get()), CoreFile::corefileIterationInterval());
|
unsigned sleeptime =
|
||||||
|
qMin(tox_iteration_interval(tox.get()), CoreFile::corefileIterationInterval());
|
||||||
toxTimer.start(sleeptime);
|
toxTimer.start(sleeptime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,8 +458,8 @@ void Core::onConnectionStatusChanged(Tox*, uint32_t friendId, TOX_CONNECTION sta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::onGroupInvite(Tox* tox, uint32_t friendId, TOX_CONFERENCE_TYPE type, const uint8_t* cookie,
|
void Core::onGroupInvite(Tox* tox, uint32_t friendId, TOX_CONFERENCE_TYPE type,
|
||||||
size_t length, void* vCore)
|
const uint8_t* cookie, size_t length, void* vCore)
|
||||||
{
|
{
|
||||||
Core* core = static_cast<Core*>(vCore);
|
Core* core = static_cast<Core*>(vCore);
|
||||||
// static_cast is used twice to replace using unsafe reinterpret_cast
|
// static_cast is used twice to replace using unsafe reinterpret_cast
|
||||||
|
@ -478,8 +480,7 @@ void Core::onGroupInvite(Tox* tox, uint32_t friendId, TOX_CONFERENCE_TYPE type,
|
||||||
qDebug() << QString("AV group invite by %1").arg(friendId);
|
qDebug() << QString("AV group invite by %1").arg(friendId);
|
||||||
if (friendId == UINT32_MAX) {
|
if (friendId == UINT32_MAX) {
|
||||||
// Rejoining existing (persistent) AV conference after disconnect and reconnect.
|
// Rejoining existing (persistent) AV conference after disconnect and reconnect.
|
||||||
toxav_join_av_groupchat(tox, friendId, cookie, length,
|
toxav_join_av_groupchat(tox, friendId, cookie, length, CoreAV::groupCallCallback, core);
|
||||||
CoreAV::groupCallCallback, core);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
emit core->groupInviteReceived(inviteInfo);
|
emit core->groupInviteReceived(inviteInfo);
|
||||||
|
@ -511,8 +512,8 @@ void Core::onGroupPeerListChange(Tox*, uint32_t groupId, void* core)
|
||||||
emit static_cast<Core*>(core)->groupPeerlistChanged(groupId);
|
emit static_cast<Core*>(core)->groupPeerlistChanged(groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::onGroupPeerNameChange(Tox*, uint32_t groupId, uint32_t peerId,
|
void Core::onGroupPeerNameChange(Tox*, uint32_t groupId, uint32_t peerId, const uint8_t* name,
|
||||||
const uint8_t* name, size_t length, void* core)
|
size_t length, void* core)
|
||||||
{
|
{
|
||||||
const auto newName = ToxString(name, length).getQString();
|
const auto newName = ToxString(name, length).getQString();
|
||||||
qDebug() << QString("Group %1, Peer %2, name changed to %3").arg(groupId).arg(peerId).arg(newName);
|
qDebug() << QString("Group %1, Peer %2, name changed to %3").arg(groupId).arg(peerId).arg(newName);
|
||||||
|
@ -622,8 +623,8 @@ int Core::sendMessage(uint32_t friendId, const QString& message)
|
||||||
{
|
{
|
||||||
QMutexLocker ml(coreLoopLock.get());
|
QMutexLocker ml(coreLoopLock.get());
|
||||||
ToxString cMessage(message);
|
ToxString cMessage(message);
|
||||||
int receipt = tox_friend_send_message(tox.get(), friendId, TOX_MESSAGE_TYPE_NORMAL, cMessage.data(),
|
int receipt = tox_friend_send_message(tox.get(), friendId, TOX_MESSAGE_TYPE_NORMAL,
|
||||||
cMessage.size(), nullptr);
|
cMessage.data(), cMessage.size(), nullptr);
|
||||||
emit messageSentResult(friendId, message, receipt);
|
emit messageSentResult(friendId, message, receipt);
|
||||||
return receipt;
|
return receipt;
|
||||||
}
|
}
|
||||||
|
@ -632,8 +633,8 @@ int Core::sendAction(uint32_t friendId, const QString& action)
|
||||||
{
|
{
|
||||||
QMutexLocker ml(coreLoopLock.get());
|
QMutexLocker ml(coreLoopLock.get());
|
||||||
ToxString cMessage(action);
|
ToxString cMessage(action);
|
||||||
int receipt = tox_friend_send_message(tox.get(), friendId, TOX_MESSAGE_TYPE_ACTION, cMessage.data(),
|
int receipt = tox_friend_send_message(tox.get(), friendId, TOX_MESSAGE_TYPE_ACTION,
|
||||||
cMessage.size(), nullptr);
|
cMessage.data(), cMessage.size(), nullptr);
|
||||||
emit messageSentResult(friendId, action, receipt);
|
emit messageSentResult(friendId, action, receipt);
|
||||||
return receipt;
|
return receipt;
|
||||||
}
|
}
|
||||||
|
@ -684,7 +685,8 @@ void Core::sendGroupMessageWithType(int groupId, const QString& message, TOX_MES
|
||||||
for (auto& part : cMessages) {
|
for (auto& part : cMessages) {
|
||||||
ToxString cMsg(part);
|
ToxString cMsg(part);
|
||||||
TOX_ERR_CONFERENCE_SEND_MESSAGE error;
|
TOX_ERR_CONFERENCE_SEND_MESSAGE error;
|
||||||
bool ok = tox_conference_send_message(tox.get(), groupId, type, cMsg.data(), cMsg.size(), &error);
|
bool ok =
|
||||||
|
tox_conference_send_message(tox.get(), groupId, type, cMsg.data(), cMsg.size(), &error);
|
||||||
if (!ok || !parseConferenceSendMessageError(error)) {
|
if (!ok || !parseConferenceSendMessageError(error)) {
|
||||||
emit groupSentFailed(groupId);
|
emit groupSentFailed(groupId);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
#include "toxfile.h"
|
#include "toxfile.h"
|
||||||
#include "toxid.h"
|
#include "toxid.h"
|
||||||
|
|
||||||
#include <tox/tox.h>
|
|
||||||
#include "src/core/dhtserver.h"
|
#include "src/core/dhtserver.h"
|
||||||
|
#include <tox/tox.h>
|
||||||
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
@ -56,8 +56,8 @@ class Core : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
enum class ToxCoreErrors
|
||||||
enum class ToxCoreErrors {
|
{
|
||||||
BAD_PROXY,
|
BAD_PROXY,
|
||||||
INVALID_SAVE,
|
INVALID_SAVE,
|
||||||
FAILED_TO_START,
|
FAILED_TO_START,
|
||||||
|
@ -232,8 +232,8 @@ private:
|
||||||
const uint8_t* cMessage, size_t length, void* vCore);
|
const uint8_t* cMessage, size_t length, void* vCore);
|
||||||
#if TOX_VERSION_IS_API_COMPATIBLE(0, 2, 0)
|
#if TOX_VERSION_IS_API_COMPATIBLE(0, 2, 0)
|
||||||
static void onGroupPeerListChange(Tox*, uint32_t groupId, void* core);
|
static void onGroupPeerListChange(Tox*, uint32_t groupId, void* core);
|
||||||
static void onGroupPeerNameChange(Tox*, uint32_t groupId, uint32_t peerId,
|
static void onGroupPeerNameChange(Tox*, uint32_t groupId, uint32_t peerId, const uint8_t* name,
|
||||||
const uint8_t* name, size_t length, void* core);
|
size_t length, void* core);
|
||||||
#else
|
#else
|
||||||
static void onGroupNamelistChange(Tox* tox, uint32_t groupId, uint32_t peerId,
|
static void onGroupNamelistChange(Tox* tox, uint32_t groupId, uint32_t peerId,
|
||||||
TOX_CONFERENCE_STATE_CHANGE change, void* core);
|
TOX_CONFERENCE_STATE_CHANGE change, void* core);
|
||||||
|
@ -264,9 +264,12 @@ private slots:
|
||||||
void onStarted();
|
void onStarted();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct ToxDeleter
|
||||||
struct ToxDeleter {
|
{
|
||||||
void operator()(Tox* tox) { tox_kill(tox); }
|
void operator()(Tox* tox)
|
||||||
|
{
|
||||||
|
tox_kill(tox);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using ToxPtr = std::unique_ptr<Tox, ToxDeleter>;
|
using ToxPtr = std::unique_ptr<Tox, ToxDeleter>;
|
||||||
|
|
|
@ -797,7 +797,8 @@ void CoreAV::callCallback(ToxAV* toxav, uint32_t friendNum, bool audio, bool vid
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = self->calls.insert(std::pair<uint32_t, ToxFriendCall>(friendNum, ToxFriendCall{friendNum, video, *self}));
|
auto it = self->calls.insert(
|
||||||
|
std::pair<uint32_t, ToxFriendCall>(friendNum, ToxFriendCall{friendNum, video, *self}));
|
||||||
if (it.second == false) {
|
if (it.second == false) {
|
||||||
/// Hanging up from a callback is supposed to be UB,
|
/// Hanging up from a callback is supposed to be UB,
|
||||||
/// but since currently the toxav callbacks are fired from the toxcore thread,
|
/// but since currently the toxav callbacks are fired from the toxcore thread,
|
||||||
|
@ -919,8 +920,7 @@ void CoreAV::audioBitrateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t rat
|
||||||
Q_ARG(uint32_t, rate), Q_ARG(void*, vSelf));
|
Q_ARG(uint32_t, rate), Q_ARG(void*, vSelf));
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Recommended audio bitrate with" << friendNum << " is now " << rate
|
qDebug() << "Recommended audio bitrate with" << friendNum << " is now " << rate << ", ignoring it";
|
||||||
<< ", ignoring it";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreAV::videoBitrateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t rate, void* vSelf)
|
void CoreAV::videoBitrateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t rate, void* vSelf)
|
||||||
|
@ -934,8 +934,7 @@ void CoreAV::videoBitrateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t rat
|
||||||
Q_ARG(uint32_t, rate), Q_ARG(void*, vSelf));
|
Q_ARG(uint32_t, rate), Q_ARG(void*, vSelf));
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Recommended video bitrate with" << friendNum << " is now " << rate
|
qDebug() << "Recommended video bitrate with" << friendNum << " is now " << rate << ", ignoring it";
|
||||||
<< ", ignoring it";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreAV::audioFrameCallback(ToxAV*, uint32_t friendNum, const int16_t* pcm, size_t sampleCount,
|
void CoreAV::audioFrameCallback(ToxAV*, uint32_t friendNum, const int16_t* pcm, size_t sampleCount,
|
||||||
|
|
|
@ -78,8 +78,9 @@ public:
|
||||||
void toggleMuteCallInput(const Friend* f);
|
void toggleMuteCallInput(const Friend* f);
|
||||||
void toggleMuteCallOutput(const Friend* f);
|
void toggleMuteCallOutput(const Friend* f);
|
||||||
#if TOX_VERSION_IS_API_COMPATIBLE(0, 2, 0)
|
#if TOX_VERSION_IS_API_COMPATIBLE(0, 2, 0)
|
||||||
static void groupCallCallback(void* tox, uint32_t group, uint32_t peer, const int16_t* data, unsigned samples,
|
static void groupCallCallback(void* tox, uint32_t group, uint32_t peer, const int16_t* data,
|
||||||
uint8_t channels, uint32_t sample_rate, void* core);
|
unsigned samples, uint8_t channels, uint32_t sample_rate,
|
||||||
|
void* core);
|
||||||
#else
|
#else
|
||||||
static void groupCallCallback(void* tox, int group, int peer, const int16_t* data, unsigned samples,
|
static void groupCallCallback(void* tox, int group, int peer, const int16_t* data, unsigned samples,
|
||||||
uint8_t channels, unsigned sample_rate, void* core);
|
uint8_t channels, unsigned sample_rate, void* core);
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "core.h"
|
|
||||||
#include "corefile.h"
|
#include "corefile.h"
|
||||||
|
#include "core.h"
|
||||||
#include "toxfile.h"
|
#include "toxfile.h"
|
||||||
#include "toxstring.h"
|
#include "toxstring.h"
|
||||||
#include "src/persistence/profile.h"
|
#include "src/persistence/profile.h"
|
||||||
|
@ -27,8 +27,8 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QThread>
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
#include <QThread>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,7 +112,8 @@ void CoreFile::sendAvatarFile(Core* core, uint32_t friendId, const QByteArray& d
|
||||||
file.fileKind = TOX_FILE_KIND_AVATAR;
|
file.fileKind = TOX_FILE_KIND_AVATAR;
|
||||||
file.avatarData = data;
|
file.avatarData = data;
|
||||||
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
||||||
tox_file_get_file_id(core->tox.get(), friendId, fileNum, (uint8_t*)file.resumeFileId.data(), nullptr);
|
tox_file_get_file_id(core->tox.get(), friendId, fileNum, (uint8_t*)file.resumeFileId.data(),
|
||||||
|
nullptr);
|
||||||
addFile(friendId, fileNum, file);
|
addFile(friendId, fileNum, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,8 +123,8 @@ void CoreFile::sendFile(Core* core, uint32_t friendId, QString filename, QString
|
||||||
QMutexLocker mlocker(&fileSendMutex);
|
QMutexLocker mlocker(&fileSendMutex);
|
||||||
|
|
||||||
QByteArray fileName = filename.toUtf8();
|
QByteArray fileName = filename.toUtf8();
|
||||||
uint32_t fileNum = tox_file_send(core->tox.get(), friendId, TOX_FILE_KIND_DATA, filesize, nullptr,
|
uint32_t fileNum = tox_file_send(core->tox.get(), friendId, TOX_FILE_KIND_DATA, filesize,
|
||||||
(uint8_t*)fileName.data(), fileName.size(), nullptr);
|
nullptr, (uint8_t*)fileName.data(), fileName.size(), nullptr);
|
||||||
if (fileNum == std::numeric_limits<uint32_t>::max()) {
|
if (fileNum == std::numeric_limits<uint32_t>::max()) {
|
||||||
qWarning() << "sendFile: Can't create the Tox file sender";
|
qWarning() << "sendFile: Can't create the Tox file sender";
|
||||||
emit core->fileSendFailed(friendId, filename);
|
emit core->fileSendFailed(friendId, filename);
|
||||||
|
@ -134,7 +135,8 @@ void CoreFile::sendFile(Core* core, uint32_t friendId, QString filename, QString
|
||||||
ToxFile file{fileNum, friendId, fileName, filePath, ToxFile::SENDING};
|
ToxFile file{fileNum, friendId, fileName, filePath, ToxFile::SENDING};
|
||||||
file.filesize = filesize;
|
file.filesize = filesize;
|
||||||
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
||||||
tox_file_get_file_id(core->tox.get(), friendId, fileNum, (uint8_t*)file.resumeFileId.data(), nullptr);
|
tox_file_get_file_id(core->tox.get(), friendId, fileNum, (uint8_t*)file.resumeFileId.data(),
|
||||||
|
nullptr);
|
||||||
if (!file.open(false)) {
|
if (!file.open(false)) {
|
||||||
qWarning() << QString("sendFile: Can't open file, error: %1").arg(file.file->errorString());
|
qWarning() << QString("sendFile: Can't open file, error: %1").arg(file.file->errorString());
|
||||||
}
|
}
|
||||||
|
@ -154,11 +156,13 @@ void CoreFile::pauseResumeFileSend(Core* core, uint32_t friendId, uint32_t fileI
|
||||||
if (file->status == ToxFile::TRANSMITTING) {
|
if (file->status == ToxFile::TRANSMITTING) {
|
||||||
file->status = ToxFile::PAUSED;
|
file->status = ToxFile::PAUSED;
|
||||||
emit core->fileTransferPaused(*file);
|
emit core->fileTransferPaused(*file);
|
||||||
tox_file_control(core->tox.get(), file->friendId, file->fileNum, TOX_FILE_CONTROL_PAUSE, nullptr);
|
tox_file_control(core->tox.get(), file->friendId, file->fileNum, TOX_FILE_CONTROL_PAUSE,
|
||||||
|
nullptr);
|
||||||
} else if (file->status == ToxFile::PAUSED) {
|
} else if (file->status == ToxFile::PAUSED) {
|
||||||
file->status = ToxFile::TRANSMITTING;
|
file->status = ToxFile::TRANSMITTING;
|
||||||
emit core->fileTransferAccepted(*file);
|
emit core->fileTransferAccepted(*file);
|
||||||
tox_file_control(core->tox.get(), file->friendId, file->fileNum, TOX_FILE_CONTROL_RESUME, nullptr);
|
tox_file_control(core->tox.get(), file->friendId, file->fileNum, TOX_FILE_CONTROL_RESUME,
|
||||||
|
nullptr);
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "pauseResumeFileSend: File is stopped";
|
qWarning() << "pauseResumeFileSend: File is stopped";
|
||||||
}
|
}
|
||||||
|
@ -174,11 +178,13 @@ void CoreFile::pauseResumeFileRecv(Core* core, uint32_t friendId, uint32_t fileI
|
||||||
if (file->status == ToxFile::TRANSMITTING) {
|
if (file->status == ToxFile::TRANSMITTING) {
|
||||||
file->status = ToxFile::PAUSED;
|
file->status = ToxFile::PAUSED;
|
||||||
emit core->fileTransferPaused(*file);
|
emit core->fileTransferPaused(*file);
|
||||||
tox_file_control(core->tox.get(), file->friendId, file->fileNum, TOX_FILE_CONTROL_PAUSE, nullptr);
|
tox_file_control(core->tox.get(), file->friendId, file->fileNum, TOX_FILE_CONTROL_PAUSE,
|
||||||
|
nullptr);
|
||||||
} else if (file->status == ToxFile::PAUSED) {
|
} else if (file->status == ToxFile::PAUSED) {
|
||||||
file->status = ToxFile::TRANSMITTING;
|
file->status = ToxFile::TRANSMITTING;
|
||||||
emit core->fileTransferAccepted(*file);
|
emit core->fileTransferAccepted(*file);
|
||||||
tox_file_control(core->tox.get(), file->friendId, file->fileNum, TOX_FILE_CONTROL_RESUME, nullptr);
|
tox_file_control(core->tox.get(), file->friendId, file->fileNum, TOX_FILE_CONTROL_RESUME,
|
||||||
|
nullptr);
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "pauseResumeFileRecv: File is stopped or broken";
|
qWarning() << "pauseResumeFileRecv: File is stopped or broken";
|
||||||
}
|
}
|
||||||
|
@ -323,7 +329,8 @@ void CoreFile::onFileReceiveCallback(Tox*, uint32_t friendId, uint32_t fileId, u
|
||||||
file.filesize = filesize;
|
file.filesize = filesize;
|
||||||
file.fileKind = kind;
|
file.fileKind = kind;
|
||||||
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
||||||
tox_file_get_file_id(core->tox.get(), friendId, fileId, (uint8_t*)file.resumeFileId.data(), nullptr);
|
tox_file_get_file_id(core->tox.get(), friendId, fileId, (uint8_t*)file.resumeFileId.data(),
|
||||||
|
nullptr);
|
||||||
addFile(friendId, fileId, file);
|
addFile(friendId, fileId, file);
|
||||||
if (kind != TOX_FILE_KIND_AVATAR)
|
if (kind != TOX_FILE_KIND_AVATAR)
|
||||||
emit core->fileReceiveRequested(file);
|
emit core->fileReceiveRequested(file);
|
||||||
|
@ -336,8 +343,7 @@ void CoreFile::handleAvatarOffer(uint32_t friendId, uint32_t fileId, bool accept
|
||||||
auto core = Core::getInstance();
|
auto core = Core::getInstance();
|
||||||
if (!accept) {
|
if (!accept) {
|
||||||
// If it's an avatar but we already have it cached, cancel
|
// If it's an avatar but we already have it cached, cancel
|
||||||
qDebug() << QString(
|
qDebug() << QString("Received avatar request %1:%2, reject, since we have it in cache.")
|
||||||
"Received avatar request %1:%2, reject, since we have it in cache.")
|
|
||||||
.arg(friendId)
|
.arg(friendId)
|
||||||
.arg(fileId);
|
.arg(fileId);
|
||||||
tox_file_control(core->tox.get(), friendId, fileId, TOX_FILE_CONTROL_CANCEL, nullptr);
|
tox_file_control(core->tox.get(), friendId, fileId, TOX_FILE_CONTROL_CANCEL, nullptr);
|
||||||
|
@ -355,7 +361,8 @@ void CoreFile::handleAvatarOffer(uint32_t friendId, uint32_t fileId, bool accept
|
||||||
file.filesize = 0;
|
file.filesize = 0;
|
||||||
file.fileKind = TOX_FILE_KIND_AVATAR;
|
file.fileKind = TOX_FILE_KIND_AVATAR;
|
||||||
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
||||||
tox_file_get_file_id(core->tox.get(), friendId, fileId, (uint8_t*)file.resumeFileId.data(), nullptr);
|
tox_file_get_file_id(core->tox.get(), friendId, fileId, (uint8_t*)file.resumeFileId.data(),
|
||||||
|
nullptr);
|
||||||
addFile(friendId, fileId, file);
|
addFile(friendId, fileId, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ class CoreFile
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void handleAvatarOffer(uint32_t friendId, uint32_t fileId, bool accept);
|
static void handleAvatarOffer(uint32_t friendId, uint32_t fileId, bool accept);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CoreFile() = delete;
|
CoreFile() = delete;
|
||||||
|
|
||||||
|
|
|
@ -20,22 +20,26 @@ ToxOptions::ToxOptions(Tox_Options *options, const QByteArray &proxyAddrData)
|
||||||
, proxyAddrData(proxyAddrData)
|
, proxyAddrData(proxyAddrData)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
ToxOptions::~ToxOptions() {
|
ToxOptions::~ToxOptions()
|
||||||
|
{
|
||||||
tox_options_free(options);
|
tox_options_free(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
ToxOptions::ToxOptions(ToxOptions &&from) {
|
ToxOptions::ToxOptions(ToxOptions&& from)
|
||||||
|
{
|
||||||
options = from.options;
|
options = from.options;
|
||||||
proxyAddrData.swap(from.proxyAddrData);
|
proxyAddrData.swap(from.proxyAddrData);
|
||||||
from.options = nullptr;
|
from.options = nullptr;
|
||||||
from.proxyAddrData.clear();
|
from.proxyAddrData.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *ToxOptions::getProxyAddrData() const {
|
const char* ToxOptions::getProxyAddrData() const
|
||||||
|
{
|
||||||
return proxyAddrData.constData();
|
return proxyAddrData.constData();
|
||||||
}
|
}
|
||||||
|
|
||||||
ToxOptions::operator Tox_Options *() {
|
ToxOptions::operator Tox_Options*()
|
||||||
|
{
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +48,8 @@ ToxOptions::operator Tox_Options *() {
|
||||||
* @param savedata Previously saved Tox data
|
* @param savedata Previously saved Tox data
|
||||||
* @return ToxOptions instance initialized to create Tox instance
|
* @return ToxOptions instance initialized to create Tox instance
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<ToxOptions> ToxOptions::makeToxOptions(const QByteArray& savedata, const ICoreSettings* s)
|
std::unique_ptr<ToxOptions> ToxOptions::makeToxOptions(const QByteArray& savedata,
|
||||||
|
const ICoreSettings* s)
|
||||||
{
|
{
|
||||||
// IPv6 needed for LAN discovery, but can crash some weird routers. On by default, can be
|
// IPv6 needed for LAN discovery, but can crash some weird routers. On by default, can be
|
||||||
// disabled in options.
|
// disabled in options.
|
||||||
|
@ -76,9 +81,10 @@ std::unique_ptr<ToxOptions> ToxOptions::makeToxOptions(const QByteArray& savedat
|
||||||
tox_options_set_log_callback(*toxOptions, ToxLogger::onLogMessage);
|
tox_options_set_log_callback(*toxOptions, ToxLogger::onLogMessage);
|
||||||
|
|
||||||
// savedata
|
// savedata
|
||||||
tox_options_set_savedata_type(*toxOptions, !savedata.isNull() ? TOX_SAVEDATA_TYPE_TOX_SAVE : TOX_SAVEDATA_TYPE_NONE);
|
tox_options_set_savedata_type(*toxOptions, !savedata.isNull() ? TOX_SAVEDATA_TYPE_TOX_SAVE
|
||||||
tox_options_set_savedata_data(*toxOptions, reinterpret_cast<const uint8_t*>(savedata.data()), savedata.size());
|
: TOX_SAVEDATA_TYPE_NONE);
|
||||||
|
tox_options_set_savedata_data(*toxOptions, reinterpret_cast<const uint8_t*>(savedata.data()),
|
||||||
|
savedata.size());
|
||||||
// No proxy by default
|
// No proxy by default
|
||||||
tox_options_set_proxy_type(*toxOptions, TOX_PROXY_TYPE_NONE);
|
tox_options_set_proxy_type(*toxOptions, TOX_PROXY_TYPE_NONE);
|
||||||
tox_options_set_proxy_host(*toxOptions, nullptr);
|
tox_options_set_proxy_host(*toxOptions, nullptr);
|
||||||
|
@ -125,4 +131,3 @@ void ToxOptions::setIPv6Enabled(bool enabled)
|
||||||
{
|
{
|
||||||
tox_options_set_ipv6_enabled(options, enabled);
|
tox_options_set_ipv6_enabled(options, enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,8 @@ public:
|
||||||
ToxOptions(ToxOptions&& from);
|
ToxOptions(ToxOptions&& from);
|
||||||
operator Tox_Options*();
|
operator Tox_Options*();
|
||||||
const char* getProxyAddrData() const;
|
const char* getProxyAddrData() const;
|
||||||
static std::unique_ptr<ToxOptions> makeToxOptions(const QByteArray &savedata, const ICoreSettings *s);
|
static std::unique_ptr<ToxOptions> makeToxOptions(const QByteArray& savedata,
|
||||||
|
const ICoreSettings* s);
|
||||||
bool getIPv6Enabled() const;
|
bool getIPv6Enabled() const;
|
||||||
void setIPv6Enabled(bool enabled);
|
void setIPv6Enabled(bool enabled);
|
||||||
|
|
||||||
|
|
23
src/main.cpp
23
src/main.cpp
|
@ -155,10 +155,8 @@ int main(int argc, char* argv[])
|
||||||
#if defined(Q_OS_UNIX)
|
#if defined(Q_OS_UNIX)
|
||||||
// PosixSignalNotifier is used only for terminating signals,
|
// PosixSignalNotifier is used only for terminating signals,
|
||||||
// so it's connected directly to quit() without any filtering.
|
// so it's connected directly to quit() without any filtering.
|
||||||
QObject::connect(&PosixSignalNotifier::globalInstance(),
|
QObject::connect(&PosixSignalNotifier::globalInstance(), &PosixSignalNotifier::activated,
|
||||||
&PosixSignalNotifier::activated,
|
a.get(), &QApplication::quit);
|
||||||
a.get(),
|
|
||||||
&QApplication::quit);
|
|
||||||
PosixSignalNotifier::watchCommonTerminatingSignals();
|
PosixSignalNotifier::watchCommonTerminatingSignals();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -195,10 +193,14 @@ int main(int argc, char* argv[])
|
||||||
parser.addVersionOption();
|
parser.addVersionOption();
|
||||||
parser.addPositionalArgument("uri", QObject::tr("Tox URI to parse"));
|
parser.addPositionalArgument("uri", QObject::tr("Tox URI to parse"));
|
||||||
parser.addOption(
|
parser.addOption(
|
||||||
QCommandLineOption(QStringList() << "p" << "profile", QObject::tr("Starts new instance and loads specified profile."),
|
QCommandLineOption(QStringList() << "p"
|
||||||
|
<< "profile",
|
||||||
|
QObject::tr("Starts new instance and loads specified profile."),
|
||||||
QObject::tr("profile")));
|
QObject::tr("profile")));
|
||||||
parser.addOption(
|
parser.addOption(
|
||||||
QCommandLineOption(QStringList() << "l" << "login", QObject::tr("Starts new instance and opens the login screen.")));
|
QCommandLineOption(QStringList() << "l"
|
||||||
|
<< "login",
|
||||||
|
QObject::tr("Starts new instance and opens the login screen.")));
|
||||||
parser.process(*a);
|
parser.process(*a);
|
||||||
|
|
||||||
uint32_t profileId = Settings::getInstance().getCurrentProfileId();
|
uint32_t profileId = Settings::getInstance().getCurrentProfileId();
|
||||||
|
@ -317,8 +319,10 @@ int main(int argc, char* argv[])
|
||||||
// If someone else processed it, we're done here, no need to actually start qTox
|
// If someone else processed it, we're done here, no need to actually start qTox
|
||||||
if (ipc.waitUntilAccepted(event, 2)) {
|
if (ipc.waitUntilAccepted(event, 2)) {
|
||||||
if (eventType == "activate") {
|
if (eventType == "activate") {
|
||||||
qDebug() << "Another qTox instance is already running. If you want to start a second "
|
qDebug()
|
||||||
"instance, please open login screen (qtox -l) or start with a profile (qtox -p <profile name>).";
|
<< "Another qTox instance is already running. If you want to start a second "
|
||||||
|
"instance, please open login screen (qtox -l) or start with a profile (qtox "
|
||||||
|
"-p <profile name>).";
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Event" << eventType << "was handled by other client.";
|
qDebug() << "Event" << eventType << "was handled by other client.";
|
||||||
}
|
}
|
||||||
|
@ -329,8 +333,7 @@ int main(int argc, char* argv[])
|
||||||
Profile* profile = nullptr;
|
Profile* profile = nullptr;
|
||||||
|
|
||||||
// Autologin
|
// Autologin
|
||||||
if (autoLogin && Profile::exists(profileName) &&
|
if (autoLogin && Profile::exists(profileName) && !Profile::isEncrypted(profileName)) {
|
||||||
!Profile::isEncrypted(profileName)) {
|
|
||||||
profile = Profile::loadProfile(profileName);
|
profile = Profile::loadProfile(profileName);
|
||||||
} else {
|
} else {
|
||||||
LoginScreen loginScreen{profileName};
|
LoginScreen loginScreen{profileName};
|
||||||
|
|
|
@ -19,14 +19,14 @@
|
||||||
|
|
||||||
#include "profileinfo.h"
|
#include "profileinfo.h"
|
||||||
#include "src/core/core.h"
|
#include "src/core/core.h"
|
||||||
|
#include "src/nexus.h"
|
||||||
#include "src/persistence/profile.h"
|
#include "src/persistence/profile.h"
|
||||||
#include "src/persistence/settings.h"
|
#include "src/persistence/settings.h"
|
||||||
#include "src/nexus.h"
|
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QBuffer>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QBuffer>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class ProfileInfo
|
* @class ProfileInfo
|
||||||
|
|
|
@ -61,8 +61,7 @@ Nexus::Nexus(QObject* parent)
|
||||||
, profile{nullptr}
|
, profile{nullptr}
|
||||||
, widget{nullptr}
|
, widget{nullptr}
|
||||||
, running{true}
|
, running{true}
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
Nexus::~Nexus()
|
Nexus::~Nexus()
|
||||||
{
|
{
|
||||||
|
@ -209,7 +208,8 @@ void Nexus::showMainGUI()
|
||||||
connect(core, &Core::friendMessageReceived, widget, &Widget::onFriendMessageReceived);
|
connect(core, &Core::friendMessageReceived, widget, &Widget::onFriendMessageReceived);
|
||||||
connect(core, &Core::groupInviteReceived, widget, &Widget::onGroupInviteReceived);
|
connect(core, &Core::groupInviteReceived, widget, &Widget::onGroupInviteReceived);
|
||||||
connect(core, &Core::groupMessageReceived, widget, &Widget::onGroupMessageReceived);
|
connect(core, &Core::groupMessageReceived, widget, &Widget::onGroupMessageReceived);
|
||||||
connect(core, &Core::groupNamelistChanged, widget, &Widget::onGroupNamelistChangedOld); // TODO(sudden6): toxcore < 0.2.0, remove
|
connect(core, &Core::groupNamelistChanged, widget,
|
||||||
|
&Widget::onGroupNamelistChangedOld); // TODO(sudden6): toxcore < 0.2.0, remove
|
||||||
connect(core, &Core::groupPeerlistChanged, widget, &Widget::onGroupPeerlistChanged);
|
connect(core, &Core::groupPeerlistChanged, widget, &Widget::onGroupPeerlistChanged);
|
||||||
connect(core, &Core::groupPeerNameChanged, widget, &Widget::onGroupPeerNameChanged);
|
connect(core, &Core::groupPeerNameChanged, widget, &Widget::onGroupPeerNameChanged);
|
||||||
connect(core, &Core::groupTitleChanged, widget, &Widget::onGroupTitleChanged);
|
connect(core, &Core::groupTitleChanged, widget, &Widget::onGroupTitleChanged);
|
||||||
|
|
|
@ -94,7 +94,6 @@ Profile::Profile(QString name, const QString& password, bool isNewProfile, const
|
||||||
|
|
||||||
const ToxId& selfId = core->getSelfId();
|
const ToxId& selfId = core->getSelfId();
|
||||||
loadDatabase(selfId, password);
|
loadDatabase(selfId, password);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,8 +107,7 @@ Profile::Profile(QString name, const QString& password, bool isNewProfile, const
|
||||||
Profile* Profile::loadProfile(QString name, const QString& password)
|
Profile* Profile::loadProfile(QString name, const QString& password)
|
||||||
{
|
{
|
||||||
if (ProfileLocker::hasLock()) {
|
if (ProfileLocker::hasLock()) {
|
||||||
qCritical() << "Tried to load profile " << name
|
qCritical() << "Tried to load profile " << name << ", but another profile is already locked!";
|
||||||
<< ", but another profile is already locked!";
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,8 +201,7 @@ Profile* Profile::createProfile(QString name, QString password)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ProfileLocker::hasLock()) {
|
if (ProfileLocker::hasLock()) {
|
||||||
qCritical() << "Tried to create profile " << name
|
qCritical() << "Tried to create profile " << name << ", but another profile is already locked!";
|
||||||
<< ", but another profile is already locked!";
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,8 +406,7 @@ QString Profile::avatarPath(const ToxPk& owner, bool forceUnencrypted)
|
||||||
QByteArray hash(hashSize, 0);
|
QByteArray hash(hashSize, 0);
|
||||||
crypto_generichash((uint8_t*)hash.data(), hashSize, (uint8_t*)idData.data(), idData.size(),
|
crypto_generichash((uint8_t*)hash.data(), hashSize, (uint8_t*)idData.data(), idData.size(),
|
||||||
(uint8_t*)pubkeyData.data(), pubkeyData.size());
|
(uint8_t*)pubkeyData.data(), pubkeyData.size());
|
||||||
return Settings::getInstance().getSettingsDirPath() + "avatars/" + hash.toHex().toUpper()
|
return Settings::getInstance().getSettingsDirPath() + "avatars/" + hash.toHex().toUpper() + ".png";
|
||||||
+ ".png";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
#include "groupnetcamview.h"
|
#include "groupnetcamview.h"
|
||||||
#include "src/audio/audio.h"
|
#include "src/audio/audio.h"
|
||||||
#include "src/core/core.h"
|
#include "src/core/core.h"
|
||||||
#include "src/model/friend.h"
|
|
||||||
#include "src/friendlist.h"
|
#include "src/friendlist.h"
|
||||||
|
#include "src/model/friend.h"
|
||||||
#include "src/nexus.h"
|
#include "src/nexus.h"
|
||||||
#include "src/persistence/profile.h"
|
#include "src/persistence/profile.h"
|
||||||
#include "src/video/videosurface.h"
|
#include "src/video/videosurface.h"
|
||||||
|
@ -56,9 +56,7 @@ public:
|
||||||
layout->addWidget(label);
|
layout->addWidget(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
~LabeledVideo()
|
~LabeledVideo() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
VideoSurface* getVideoSurface() const
|
VideoSurface* getVideoSurface() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
#include "netcamview.h"
|
#include "netcamview.h"
|
||||||
#include "camerasource.h"
|
#include "camerasource.h"
|
||||||
#include "src/core/core.h"
|
#include "src/core/core.h"
|
||||||
#include "src/model/friend.h"
|
|
||||||
#include "src/friendlist.h"
|
#include "src/friendlist.h"
|
||||||
|
#include "src/model/friend.h"
|
||||||
#include "src/nexus.h"
|
#include "src/nexus.h"
|
||||||
#include "src/persistence/profile.h"
|
#include "src/persistence/profile.h"
|
||||||
#include "src/persistence/settings.h"
|
#include "src/persistence/settings.h"
|
||||||
|
|
|
@ -27,21 +27,21 @@
|
||||||
#include "src/core/coreav.h"
|
#include "src/core/coreav.h"
|
||||||
#include "src/model/friend.h"
|
#include "src/model/friend.h"
|
||||||
#include "src/nexus.h"
|
#include "src/nexus.h"
|
||||||
|
#include "src/persistence/history.h"
|
||||||
#include "src/persistence/offlinemsgengine.h"
|
#include "src/persistence/offlinemsgengine.h"
|
||||||
#include "src/persistence/profile.h"
|
#include "src/persistence/profile.h"
|
||||||
#include "src/persistence/settings.h"
|
#include "src/persistence/settings.h"
|
||||||
#include "src/persistence/history.h"
|
|
||||||
#include "src/video/netcamview.h"
|
#include "src/video/netcamview.h"
|
||||||
#include "src/widget/chatformheader.h"
|
#include "src/widget/chatformheader.h"
|
||||||
#include "src/widget/form/loadhistorydialog.h"
|
#include "src/widget/form/loadhistorydialog.h"
|
||||||
#include "src/widget/maskablepixmapwidget.h"
|
#include "src/widget/maskablepixmapwidget.h"
|
||||||
|
#include "src/widget/searchform.h"
|
||||||
#include "src/widget/style.h"
|
#include "src/widget/style.h"
|
||||||
#include "src/widget/tool/callconfirmwidget.h"
|
#include "src/widget/tool/callconfirmwidget.h"
|
||||||
#include "src/widget/tool/chattextedit.h"
|
#include "src/widget/tool/chattextedit.h"
|
||||||
#include "src/widget/tool/screenshotgrabber.h"
|
#include "src/widget/tool/screenshotgrabber.h"
|
||||||
#include "src/widget/translator.h"
|
#include "src/widget/translator.h"
|
||||||
#include "src/widget/widget.h"
|
#include "src/widget/widget.h"
|
||||||
#include "src/widget/searchform.h"
|
|
||||||
|
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
@ -197,12 +197,10 @@ ChatForm::ChatForm(Friend* chatFriend, History* history)
|
||||||
});
|
});
|
||||||
|
|
||||||
// reflect name changes in the header
|
// reflect name changes in the header
|
||||||
connect(headWidget, &ChatFormHeader::nameChanged, this, [=](const QString& newName) {
|
connect(headWidget, &ChatFormHeader::nameChanged, this,
|
||||||
f->setAlias(newName);
|
[=](const QString& newName) { f->setAlias(newName); });
|
||||||
});
|
connect(headWidget, &ChatFormHeader::callAccepted, this,
|
||||||
connect(headWidget, &ChatFormHeader::callAccepted, this, [this] {
|
[this] { onAnswerCallTriggered(lastCallIsVideo); });
|
||||||
onAnswerCallTriggered(lastCallIsVideo);
|
|
||||||
});
|
|
||||||
connect(headWidget, &ChatFormHeader::callRejected, this, &ChatForm::onRejectCallTriggered);
|
connect(headWidget, &ChatFormHeader::callRejected, this, &ChatForm::onRejectCallTriggered);
|
||||||
|
|
||||||
updateCallButtons();
|
updateCallButtons();
|
||||||
|
@ -265,7 +263,8 @@ void ChatForm::onTextEditChanged()
|
||||||
|
|
||||||
void ChatForm::onAttachClicked()
|
void ChatForm::onAttachClicked()
|
||||||
{
|
{
|
||||||
QStringList paths = QFileDialog::getOpenFileNames(Q_NULLPTR, tr("Send a file"), QDir::homePath(), 0, 0);
|
QStringList paths =
|
||||||
|
QFileDialog::getOpenFileNames(Q_NULLPTR, tr("Send a file"), QDir::homePath(), 0, 0);
|
||||||
|
|
||||||
if (paths.isEmpty()) {
|
if (paths.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
@ -680,7 +679,8 @@ void ChatForm::dropEvent(QDropEvent* ev)
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
if (file.isSequential()) {
|
if (file.isSequential()) {
|
||||||
QMessageBox::critical(0, tr("Bad idea"), tr("You're trying to send a sequential file, "
|
QMessageBox::critical(0, tr("Bad idea"),
|
||||||
|
tr("You're trying to send a sequential file, "
|
||||||
"which is not going to work!"));
|
"which is not going to work!"));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -789,7 +789,9 @@ void ChatForm::insertChatlines(QList<ChatLine::Ptr> chatLines)
|
||||||
verticalBar->setValue(savedSliderPos);
|
verticalBar->setValue(savedSliderPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDate ChatForm::addDateLineIfNeeded(QList<ChatLine::Ptr> msgs, QDate const& lastDate, History::HistMessage const& newMessage, MessageMetadata const& metadata)
|
QDate ChatForm::addDateLineIfNeeded(QList<ChatLine::Ptr> msgs, QDate const& lastDate,
|
||||||
|
History::HistMessage const& newMessage,
|
||||||
|
MessageMetadata const& metadata)
|
||||||
{
|
{
|
||||||
// Show the date every new day
|
// Show the date every new day
|
||||||
QDate newDate = metadata.msgDateTime.date();
|
QDate newDate = metadata.msgDateTime.date();
|
||||||
|
@ -813,11 +815,13 @@ ChatForm::MessageMetadata ChatForm::getMessageMetadata(History::HistMessage cons
|
||||||
return {isSelf, needSending, isAction, id, authorPk, msgDateTime};
|
return {isSelf, needSending, isAction, id, authorPk, msgDateTime};
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatMessage::Ptr ChatForm::chatMessageFromHistMessage(History::HistMessage const& histMessage, MessageMetadata const& metadata)
|
ChatMessage::Ptr ChatForm::chatMessageFromHistMessage(History::HistMessage const& histMessage,
|
||||||
|
MessageMetadata const& metadata)
|
||||||
{
|
{
|
||||||
ToxPk authorPk(ToxId(histMessage.sender).getPublicKey());
|
ToxPk authorPk(ToxId(histMessage.sender).getPublicKey());
|
||||||
QString authorStr = getMsgAuthorDispName(authorPk, histMessage.dispName);
|
QString authorStr = getMsgAuthorDispName(authorPk, histMessage.dispName);
|
||||||
QString messageText = metadata.isAction ? histMessage.message.mid(ACTION_PREFIX.length()) : histMessage.message;
|
QString messageText =
|
||||||
|
metadata.isAction ? histMessage.message.mid(ACTION_PREFIX.length()) : histMessage.message;
|
||||||
ChatMessage::MessageType type = metadata.isAction ? ChatMessage::ACTION : ChatMessage::NORMAL;
|
ChatMessage::MessageType type = metadata.isAction ? ChatMessage::ACTION : ChatMessage::NORMAL;
|
||||||
QDateTime dateTime = metadata.needSending ? QDateTime() : metadata.msgDateTime;
|
QDateTime dateTime = metadata.needSending ? QDateTime() : metadata.msgDateTime;
|
||||||
auto msg = ChatMessage::createChatMessage(authorStr, messageText, type, metadata.isSelf, dateTime);
|
auto msg = ChatMessage::createChatMessage(authorStr, messageText, type, metadata.isSelf, dateTime);
|
||||||
|
@ -957,8 +961,7 @@ void ChatForm::stopCounter(bool error)
|
||||||
QString mess = error ? tr("Call with %1 ended unexpectedly. %2") : tr("Call with %1 ended. %2");
|
QString mess = error ? tr("Call with %1 ended unexpectedly. %2") : tr("Call with %1 ended. %2");
|
||||||
// TODO: add notification once notifications are implemented
|
// TODO: add notification once notifications are implemented
|
||||||
|
|
||||||
addSystemInfoMessage(mess.arg(name, dhms), ChatMessage::INFO,
|
addSystemInfoMessage(mess.arg(name, dhms), ChatMessage::INFO, QDateTime::currentDateTime());
|
||||||
QDateTime::currentDateTime());
|
|
||||||
callDurationTimer->stop();
|
callDurationTimer->stop();
|
||||||
callDuration->setText("");
|
callDuration->setText("");
|
||||||
callDuration->hide();
|
callDuration->hide();
|
||||||
|
|
|
@ -109,25 +109,30 @@ private slots:
|
||||||
void onExportChat();
|
void onExportChat();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct MessageMetadata {
|
struct MessageMetadata
|
||||||
|
{
|
||||||
const bool isSelf;
|
const bool isSelf;
|
||||||
const bool needSending;
|
const bool needSending;
|
||||||
const bool isAction;
|
const bool isAction;
|
||||||
const qint64 id;
|
const qint64 id;
|
||||||
const ToxPk authorPk;
|
const ToxPk authorPk;
|
||||||
const QDateTime msgDateTime;
|
const QDateTime msgDateTime;
|
||||||
MessageMetadata(bool isSelf, bool needSending, bool isAction, qint64 id, ToxPk authorPk, QDateTime msgDateTime) :
|
MessageMetadata(bool isSelf, bool needSending, bool isAction, qint64 id, ToxPk authorPk,
|
||||||
isSelf{isSelf},
|
QDateTime msgDateTime)
|
||||||
needSending{needSending},
|
: isSelf{isSelf}
|
||||||
isAction{isAction},
|
, needSending{needSending}
|
||||||
id{id},
|
, isAction{isAction}
|
||||||
authorPk{authorPk},
|
, id{id}
|
||||||
msgDateTime{msgDateTime} {}
|
, authorPk{authorPk}
|
||||||
|
, msgDateTime{msgDateTime}
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
void handleLoadedMessages(QList<History::HistMessage> newHistMsgs, bool processUndelivered);
|
void handleLoadedMessages(QList<History::HistMessage> newHistMsgs, bool processUndelivered);
|
||||||
QDate addDateLineIfNeeded(QList<ChatLine::Ptr> msgs, QDate const& lastDate, History::HistMessage const& newMessage, MessageMetadata const& metadata);
|
QDate addDateLineIfNeeded(QList<ChatLine::Ptr> msgs, QDate const& lastDate,
|
||||||
|
History::HistMessage const& newMessage, MessageMetadata const& metadata);
|
||||||
MessageMetadata getMessageMetadata(History::HistMessage const& histMessage);
|
MessageMetadata getMessageMetadata(History::HistMessage const& histMessage);
|
||||||
ChatMessage::Ptr chatMessageFromHistMessage(History::HistMessage const& histMessage, MessageMetadata const& metadata);
|
ChatMessage::Ptr chatMessageFromHistMessage(History::HistMessage const& histMessage,
|
||||||
|
MessageMetadata const& metadata);
|
||||||
void sendLoadedMessage(ChatMessage::Ptr chatMsg, MessageMetadata const& metadata);
|
void sendLoadedMessage(ChatMessage::Ptr chatMsg, MessageMetadata const& metadata);
|
||||||
void insertChatlines(QList<ChatLine::Ptr> chatLines);
|
void insertChatlines(QList<ChatLine::Ptr> chatLines);
|
||||||
void updateMuteMicButton();
|
void updateMuteMicButton();
|
||||||
|
|
|
@ -24,11 +24,11 @@
|
||||||
#include "maskablepixmapwidget.h"
|
#include "maskablepixmapwidget.h"
|
||||||
|
|
||||||
#include "src/core/core.h"
|
#include "src/core/core.h"
|
||||||
#include "src/model/friend.h"
|
|
||||||
#include "src/model/about/aboutfriend.h"
|
|
||||||
#include "src/friendlist.h"
|
#include "src/friendlist.h"
|
||||||
#include "src/model/group.h"
|
|
||||||
#include "src/grouplist.h"
|
#include "src/grouplist.h"
|
||||||
|
#include "src/model/about/aboutfriend.h"
|
||||||
|
#include "src/model/friend.h"
|
||||||
|
#include "src/model/group.h"
|
||||||
#include "src/persistence/settings.h"
|
#include "src/persistence/settings.h"
|
||||||
#include "src/widget/about/aboutfriendform.h"
|
#include "src/widget/about/aboutfriendform.h"
|
||||||
#include "src/widget/form/chatform.h"
|
#include "src/widget/form/chatform.h"
|
||||||
|
@ -49,8 +49,7 @@
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
constexpr auto MAX_NAME_LENGTH = 30;
|
constexpr auto MAX_NAME_LENGTH = 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,8 +120,8 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
QMenu* inviteMenu = menu.addMenu(tr("Invite to group",
|
QMenu* inviteMenu =
|
||||||
"Menu to invite a friend to a groupchat"));
|
menu.addMenu(tr("Invite to group", "Menu to invite a friend to a groupchat"));
|
||||||
inviteMenu->setEnabled(frnd->getStatus() != Status::Offline);
|
inviteMenu->setEnabled(frnd->getStatus() != Status::Offline);
|
||||||
const auto newGroupAction = inviteMenu->addAction(tr("To new group"));
|
const auto newGroupAction = inviteMenu->addAction(tr("To new group"));
|
||||||
connect(newGroupAction, &QAction::triggered, this, &FriendWidget::moveToNewGroup);
|
connect(newGroupAction, &QAction::triggered, this, &FriendWidget::moveToNewGroup);
|
||||||
|
@ -139,8 +138,8 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
||||||
|
|
||||||
const auto& s = Settings::getInstance();
|
const auto& s = Settings::getInstance();
|
||||||
const auto circleId = s.getFriendCircleID(frnd->getPublicKey());
|
const auto circleId = s.getFriendCircleID(frnd->getPublicKey());
|
||||||
auto circleMenu = menu.addMenu(tr("Move to circle...",
|
auto circleMenu =
|
||||||
"Menu to move a friend into a different circle"));
|
menu.addMenu(tr("Move to circle...", "Menu to move a friend into a different circle"));
|
||||||
|
|
||||||
const auto pk = frnd->getPublicKey();
|
const auto pk = frnd->getPublicKey();
|
||||||
const auto newCircleAction = circleMenu->addAction(tr("To new circle"));
|
const auto newCircleAction = circleMenu->addAction(tr("To new circle"));
|
||||||
|
@ -148,8 +147,8 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
||||||
|
|
||||||
if (circleId != -1) {
|
if (circleId != -1) {
|
||||||
const QString circleName = s.getCircleName(circleId);
|
const QString circleName = s.getCircleName(circleId);
|
||||||
const auto removeCircleAction = circleMenu->addAction(
|
const auto removeCircleAction =
|
||||||
tr("Remove from circle '%1'").arg(circleName));
|
circleMenu->addAction(tr("Remove from circle '%1'").arg(circleName));
|
||||||
connect(removeCircleAction, &QAction::triggered, this, &FriendWidget::removeFromCircle);
|
connect(removeCircleAction, &QAction::triggered, this, &FriendWidget::removeFromCircle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,8 +179,8 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
||||||
connect(setAlias, &QAction::triggered, [this]() { nameLabel->editBegin(); });
|
connect(setAlias, &QAction::triggered, [this]() { nameLabel->editBegin(); });
|
||||||
|
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
auto autoAccept = menu.addAction(tr("Auto accept files from this friend",
|
auto autoAccept =
|
||||||
"context menu entry"));
|
menu.addAction(tr("Auto accept files from this friend", "context menu entry"));
|
||||||
const auto dir = s.getAutoAcceptDir(pk);
|
const auto dir = s.getAutoAcceptDir(pk);
|
||||||
autoAccept->setCheckable(true);
|
autoAccept->setCheckable(true);
|
||||||
autoAccept->setChecked(!dir.isEmpty());
|
autoAccept->setChecked(!dir.isEmpty());
|
||||||
|
@ -189,8 +188,8 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
|
||||||
if (!contentDialog || !contentDialog->hasFriendWidget(friendId, this)) {
|
if (!contentDialog || !contentDialog->hasFriendWidget(friendId, this)) {
|
||||||
const auto removeAction = menu.addAction(
|
const auto removeAction =
|
||||||
tr("Remove friend", "Menu to remove the friend from our friendlist"));
|
menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist"));
|
||||||
connect(removeAction, &QAction::triggered, this, [=]() { emit removeFriend(friendId); },
|
connect(removeAction, &QAction::triggered, this, [=]() { emit removeFriend(friendId); },
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
@ -228,11 +227,9 @@ void FriendWidget::inviteFriend(uint32_t friendId, const Group* group)
|
||||||
Core::getInstance()->groupInviteFriend(friendId, group->getId());
|
Core::getInstance()->groupInviteFriend(friendId, group->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
|
|
||||||
std::tuple<CircleWidget*, FriendListWidget*> getCircleAndFriendList(
|
std::tuple<CircleWidget*, FriendListWidget*> getCircleAndFriendList(const Friend* frnd, FriendWidget* fw)
|
||||||
const Friend* frnd, FriendWidget* fw)
|
|
||||||
{
|
{
|
||||||
const auto pk = frnd->getPublicKey();
|
const auto pk = frnd->getPublicKey();
|
||||||
const auto circleId = Settings::getInstance().getFriendCircleID(pk);
|
const auto circleId = Settings::getInstance().getFriendCircleID(pk);
|
||||||
|
@ -242,7 +239,7 @@ std::tuple<CircleWidget*, FriendListWidget*> getCircleAndFriendList(
|
||||||
return std::make_tuple(circleWidget, friendList);
|
return std::make_tuple(circleWidget, friendList);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
void FriendWidget::moveToNewCircle()
|
void FriendWidget::moveToNewCircle()
|
||||||
{
|
{
|
||||||
|
@ -313,8 +310,10 @@ void FriendWidget::changeAutoAccept(bool enable)
|
||||||
auto& s = Settings::getInstance();
|
auto& s = Settings::getInstance();
|
||||||
if (enable) {
|
if (enable) {
|
||||||
const auto oldDir = s.getAutoAcceptDir(pk);
|
const auto oldDir = s.getAutoAcceptDir(pk);
|
||||||
const auto newDir = QFileDialog::getExistingDirectory(
|
const auto newDir =
|
||||||
Q_NULLPTR, tr("Choose an auto accept directory", "popup title"), oldDir);
|
QFileDialog::getExistingDirectory(Q_NULLPTR,
|
||||||
|
tr("Choose an auto accept directory", "popup title"),
|
||||||
|
oldDir);
|
||||||
|
|
||||||
const auto friendId = frnd->getId();
|
const auto friendId = frnd->getId();
|
||||||
qDebug() << "Setting auto accept dir for" << friendId << "to" << newDir;
|
qDebug() << "Setting auto accept dir for" << friendId << "to" << newDir;
|
||||||
|
@ -351,6 +350,7 @@ void FriendWidget::setAsInactiveChatroom()
|
||||||
|
|
||||||
void FriendWidget::updateStatusLight()
|
void FriendWidget::updateStatusLight()
|
||||||
{
|
{
|
||||||
|
// clang-format off
|
||||||
static const QString statuses[] = {
|
static const QString statuses[] = {
|
||||||
":img/status/online.svg",
|
":img/status/online.svg",
|
||||||
":img/status/online_notification.svg",
|
":img/status/online_notification.svg",
|
||||||
|
@ -361,6 +361,7 @@ void FriendWidget::updateStatusLight()
|
||||||
":img/status/offline.svg",
|
":img/status/offline.svg",
|
||||||
":img/status/offline_notification.svg",
|
":img/status/offline_notification.svg",
|
||||||
};
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
const bool event = frnd->getEventFlag();
|
const bool event = frnd->getEventFlag();
|
||||||
const int index = static_cast<int>(frnd->getStatus()) * 2 + event;
|
const int index = static_cast<int>(frnd->getStatus()) * 2 + event;
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
#include "friendlistwidget.h"
|
#include "friendlistwidget.h"
|
||||||
#include "friendwidget.h"
|
#include "friendwidget.h"
|
||||||
#include "groupwidget.h"
|
#include "groupwidget.h"
|
||||||
#include "src/model/groupinvite.h"
|
|
||||||
#include "maskablepixmapwidget.h"
|
#include "maskablepixmapwidget.h"
|
||||||
#include "splitterrestorer.h"
|
#include "splitterrestorer.h"
|
||||||
#include "systemtrayicon.h"
|
#include "systemtrayicon.h"
|
||||||
|
@ -52,11 +51,12 @@
|
||||||
#include "src/audio/audio.h"
|
#include "src/audio/audio.h"
|
||||||
#include "src/core/core.h"
|
#include "src/core/core.h"
|
||||||
#include "src/core/coreav.h"
|
#include "src/core/coreav.h"
|
||||||
#include "src/model/friend.h"
|
|
||||||
#include "src/friendlist.h"
|
#include "src/friendlist.h"
|
||||||
#include "src/model/group.h"
|
|
||||||
#include "src/model/profile/profileinfo.h"
|
|
||||||
#include "src/grouplist.h"
|
#include "src/grouplist.h"
|
||||||
|
#include "src/model/friend.h"
|
||||||
|
#include "src/model/group.h"
|
||||||
|
#include "src/model/groupinvite.h"
|
||||||
|
#include "src/model/profile/profileinfo.h"
|
||||||
#include "src/net/autoupdate.h"
|
#include "src/net/autoupdate.h"
|
||||||
#include "src/nexus.h"
|
#include "src/nexus.h"
|
||||||
#include "src/persistence/offlinemsgengine.h"
|
#include "src/persistence/offlinemsgengine.h"
|
||||||
|
@ -1253,9 +1253,8 @@ void Widget::addFriendDialog(const Friend* frnd, ContentDialog* dialog)
|
||||||
auto widgetRemoveFriend = static_cast<void (Widget::*)(int)>(&Widget::removeFriend);
|
auto widgetRemoveFriend = static_cast<void (Widget::*)(int)>(&Widget::removeFriend);
|
||||||
#endif
|
#endif
|
||||||
connect(friendWidget, &FriendWidget::removeFriend, this, widgetRemoveFriend);
|
connect(friendWidget, &FriendWidget::removeFriend, this, widgetRemoveFriend);
|
||||||
connect(friendWidget, &FriendWidget::middleMouseClicked, dialog, [=]() {
|
connect(friendWidget, &FriendWidget::middleMouseClicked, dialog,
|
||||||
dialog->removeFriend(friendId);
|
[=]() { dialog->removeFriend(friendId); });
|
||||||
});
|
|
||||||
connect(friendWidget, &FriendWidget::copyFriendIdToClipboard, this,
|
connect(friendWidget, &FriendWidget::copyFriendIdToClipboard, this,
|
||||||
&Widget::copyFriendIdToClipboard);
|
&Widget::copyFriendIdToClipboard);
|
||||||
|
|
||||||
|
@ -1265,13 +1264,11 @@ void Widget::addFriendDialog(const Friend* frnd, ContentDialog* dialog)
|
||||||
connect(friendWidget, &FriendWidget::contextMenuCalled, widget,
|
connect(friendWidget, &FriendWidget::contextMenuCalled, widget,
|
||||||
[=](QContextMenuEvent* event) { emit widget->contextMenuCalled(event); });
|
[=](QContextMenuEvent* event) { emit widget->contextMenuCalled(event); });
|
||||||
|
|
||||||
connect(friendWidget, &FriendWidget::chatroomWidgetClicked,
|
connect(friendWidget, &FriendWidget::chatroomWidgetClicked, [=](GenericChatroomWidget* w) {
|
||||||
[=](GenericChatroomWidget* w) {
|
|
||||||
Q_UNUSED(w);
|
Q_UNUSED(w);
|
||||||
emit widget->chatroomWidgetClicked(widget);
|
emit widget->chatroomWidgetClicked(widget);
|
||||||
});
|
});
|
||||||
connect(friendWidget, &FriendWidget::newWindowOpened,
|
connect(friendWidget, &FriendWidget::newWindowOpened, [=](GenericChatroomWidget* w) {
|
||||||
[=](GenericChatroomWidget* w) {
|
|
||||||
Q_UNUSED(w);
|
Q_UNUSED(w);
|
||||||
emit widget->newWindowOpened(widget);
|
emit widget->newWindowOpened(widget);
|
||||||
});
|
});
|
||||||
|
@ -1308,22 +1305,19 @@ void Widget::addGroupDialog(Group* group, ContentDialog* dialog)
|
||||||
#endif
|
#endif
|
||||||
connect(groupWidget, &GroupWidget::removeGroup, this, removeGroup);
|
connect(groupWidget, &GroupWidget::removeGroup, this, removeGroup);
|
||||||
connect(groupWidget, &GroupWidget::chatroomWidgetClicked, chatForm, &GroupChatForm::focusInput);
|
connect(groupWidget, &GroupWidget::chatroomWidgetClicked, chatForm, &GroupChatForm::focusInput);
|
||||||
connect(groupWidget, &GroupWidget::middleMouseClicked, dialog, [=]() {
|
connect(groupWidget, &GroupWidget::middleMouseClicked, dialog,
|
||||||
dialog->removeGroup(groupId);
|
[=]() { dialog->removeGroup(groupId); });
|
||||||
});
|
|
||||||
connect(groupWidget, &GroupWidget::chatroomWidgetClicked, chatForm, &ChatForm::focusInput);
|
connect(groupWidget, &GroupWidget::chatroomWidgetClicked, chatForm, &ChatForm::focusInput);
|
||||||
|
|
||||||
// Signal transmission from the created `groupWidget` (which shown in
|
// Signal transmission from the created `groupWidget` (which shown in
|
||||||
// ContentDialog) to the `widget` (which shown in main widget)
|
// ContentDialog) to the `widget` (which shown in main widget)
|
||||||
// FIXME: emit should be removed
|
// FIXME: emit should be removed
|
||||||
connect(groupWidget, &GroupWidget::chatroomWidgetClicked,
|
connect(groupWidget, &GroupWidget::chatroomWidgetClicked, [=](GenericChatroomWidget* w) {
|
||||||
[=](GenericChatroomWidget* w) {
|
|
||||||
Q_UNUSED(w);
|
Q_UNUSED(w);
|
||||||
emit widget->chatroomWidgetClicked(widget);
|
emit widget->chatroomWidgetClicked(widget);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(groupWidget, &GroupWidget::newWindowOpened,
|
connect(groupWidget, &GroupWidget::newWindowOpened, [=](GenericChatroomWidget* w) {
|
||||||
[=](GenericChatroomWidget* w) {
|
|
||||||
Q_UNUSED(w);
|
Q_UNUSED(w);
|
||||||
emit widget->newWindowOpened(widget);
|
emit widget->newWindowOpened(widget);
|
||||||
});
|
});
|
||||||
|
@ -1936,9 +1930,7 @@ Group* Widget::createGroup(int groupId)
|
||||||
auto widgetRemoveGroup = static_cast<void (Widget::*)(int)>(&Widget::removeGroup);
|
auto widgetRemoveGroup = static_cast<void (Widget::*)(int)>(&Widget::removeGroup);
|
||||||
#endif
|
#endif
|
||||||
connect(widget, &GroupWidget::removeGroup, this, widgetRemoveGroup);
|
connect(widget, &GroupWidget::removeGroup, this, widgetRemoveGroup);
|
||||||
connect(widget, &GroupWidget::middleMouseClicked, this, [=]() {
|
connect(widget, &GroupWidget::middleMouseClicked, this, [=]() { removeGroup(groupId); });
|
||||||
removeGroup(groupId);
|
|
||||||
});
|
|
||||||
connect(widget, &GroupWidget::chatroomWidgetClicked, form, &ChatForm::focusInput);
|
connect(widget, &GroupWidget::chatroomWidgetClicked, form, &ChatForm::focusInput);
|
||||||
connect(form, &GroupChatForm::sendMessage, core, &Core::sendGroupMessage);
|
connect(form, &GroupChatForm::sendMessage, core, &Core::sendGroupMessage);
|
||||||
connect(form, &GroupChatForm::sendAction, core, &Core::sendGroupAction);
|
connect(form, &GroupChatForm::sendAction, core, &Core::sendGroupAction);
|
||||||
|
@ -2277,8 +2269,7 @@ inline QIcon Widget::prepareIcon(QString path, int w, int h)
|
||||||
}
|
}
|
||||||
|
|
||||||
desktop = desktop.toLower();
|
desktop = desktop.toLower();
|
||||||
if (desktop == "xfce" || desktop.contains("gnome") || desktop == "mate"
|
if (desktop == "xfce" || desktop.contains("gnome") || desktop == "mate" || desktop == "x-cinnamon") {
|
||||||
|| desktop == "x-cinnamon") {
|
|
||||||
if (w > 0 && h > 0) {
|
if (w > 0 && h > 0) {
|
||||||
QSvgRenderer renderer(path);
|
QSvgRenderer renderer(path);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user