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
|
||||
* @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_message(tox, onFriendMessage);
|
||||
tox_callback_friend_name(tox, onFriendNameChange);
|
||||
|
@ -104,8 +105,8 @@ void Core::registerCallbacks(Tox * tox) {
|
|||
* @param settings Settings specific to Core
|
||||
* @return nullptr or a Core object ready to start
|
||||
*/
|
||||
ToxCorePtr Core::makeToxCore(const QByteArray &savedata, const ICoreSettings * const settings,
|
||||
ToxCoreErrors *err)
|
||||
ToxCorePtr Core::makeToxCore(const QByteArray& savedata, const ICoreSettings* const settings,
|
||||
ToxCoreErrors* err)
|
||||
{
|
||||
QThread* thread = new QThread();
|
||||
if (thread == nullptr) {
|
||||
|
@ -117,15 +118,15 @@ ToxCorePtr Core::makeToxCore(const QByteArray &savedata, const ICoreSettings * c
|
|||
auto toxOptions = ToxOptions::makeToxOptions(savedata, settings);
|
||||
if (toxOptions == nullptr) {
|
||||
qCritical() << "could not allocate Tox Options data structure";
|
||||
if(err) {
|
||||
if (err) {
|
||||
*err = ToxCoreErrors::ERROR_ALLOC;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ToxCorePtr core(new Core(thread));
|
||||
if(core == nullptr) {
|
||||
if(err) {
|
||||
if (core == nullptr) {
|
||||
if (err) {
|
||||
*err = ToxCoreErrors::ERROR_ALLOC;
|
||||
}
|
||||
return {};
|
||||
|
@ -140,7 +141,7 @@ ToxCorePtr Core::makeToxCore(const QByteArray &savedata, const ICoreSettings * c
|
|||
|
||||
case TOX_ERR_NEW_LOAD_BAD_FORMAT:
|
||||
qCritical() << "failed to parse Tox save data";
|
||||
if(err) {
|
||||
if (err) {
|
||||
*err = ToxCoreErrors::BAD_PROXY;
|
||||
}
|
||||
return {};
|
||||
|
@ -157,7 +158,7 @@ ToxCorePtr Core::makeToxCore(const QByteArray &savedata, const ICoreSettings * c
|
|||
}
|
||||
|
||||
qCritical() << "can't to bind the port";
|
||||
if(err) {
|
||||
if (err) {
|
||||
*err = ToxCoreErrors::FAILED_TO_START;
|
||||
}
|
||||
return {};
|
||||
|
@ -166,42 +167,42 @@ ToxCorePtr Core::makeToxCore(const QByteArray &savedata, const ICoreSettings * c
|
|||
case TOX_ERR_NEW_PROXY_BAD_PORT:
|
||||
case TOX_ERR_NEW_PROXY_BAD_TYPE:
|
||||
qCritical() << "bad proxy, error code:" << tox_err;
|
||||
if(err) {
|
||||
if (err) {
|
||||
*err = ToxCoreErrors::BAD_PROXY;
|
||||
}
|
||||
return {};
|
||||
|
||||
case TOX_ERR_NEW_PROXY_NOT_FOUND:
|
||||
qCritical() << "proxy not found";
|
||||
if(err) {
|
||||
if (err) {
|
||||
*err = ToxCoreErrors::BAD_PROXY;
|
||||
}
|
||||
return {};
|
||||
|
||||
case TOX_ERR_NEW_LOAD_ENCRYPTED:
|
||||
qCritical() << "attempted to load encrypted Tox save data";
|
||||
if(err) {
|
||||
if (err) {
|
||||
*err = ToxCoreErrors::INVALID_SAVE;
|
||||
}
|
||||
return {};
|
||||
|
||||
case TOX_ERR_NEW_MALLOC:
|
||||
qCritical() << "memory allocation failed";
|
||||
if(err) {
|
||||
if (err) {
|
||||
*err = ToxCoreErrors::ERROR_ALLOC;
|
||||
}
|
||||
return {};
|
||||
|
||||
case TOX_ERR_NEW_NULL:
|
||||
qCritical() << "a parameter was null";
|
||||
if(err) {
|
||||
if (err) {
|
||||
*err = ToxCoreErrors::FAILED_TO_START;
|
||||
}
|
||||
return {};
|
||||
|
||||
default:
|
||||
qCritical() << "Tox core failed to start, unknown error code:" << tox_err;
|
||||
if(err) {
|
||||
if (err) {
|
||||
*err = ToxCoreErrors::FAILED_TO_START;
|
||||
}
|
||||
return {};
|
||||
|
@ -217,7 +218,7 @@ ToxCorePtr Core::makeToxCore(const QByteArray &savedata, const ICoreSettings * c
|
|||
core->av = std::unique_ptr<CoreAV>(new CoreAV(core->tox.get()));
|
||||
if (!core->av || !core->av->getToxAv()) {
|
||||
qCritical() << "Toxav failed to start";
|
||||
if(err) {
|
||||
if (err) {
|
||||
*err = ToxCoreErrors::FAILED_TO_START;
|
||||
}
|
||||
return {};
|
||||
|
@ -328,7 +329,8 @@ void Core::process()
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
size_t length, void* vCore)
|
||||
void Core::onGroupInvite(Tox* tox, uint32_t friendId, TOX_CONFERENCE_TYPE type,
|
||||
const uint8_t* cookie, size_t length, void* vCore)
|
||||
{
|
||||
Core* core = static_cast<Core*>(vCore);
|
||||
// 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);
|
||||
if (friendId == UINT32_MAX) {
|
||||
// Rejoining existing (persistent) AV conference after disconnect and reconnect.
|
||||
toxav_join_av_groupchat(tox, friendId, cookie, length,
|
||||
CoreAV::groupCallCallback, core);
|
||||
toxav_join_av_groupchat(tox, friendId, cookie, length, CoreAV::groupCallCallback, core);
|
||||
return;
|
||||
}
|
||||
emit core->groupInviteReceived(inviteInfo);
|
||||
|
@ -511,8 +512,8 @@ void Core::onGroupPeerListChange(Tox*, uint32_t groupId, void* core)
|
|||
emit static_cast<Core*>(core)->groupPeerlistChanged(groupId);
|
||||
}
|
||||
|
||||
void Core::onGroupPeerNameChange(Tox*, uint32_t groupId, uint32_t peerId,
|
||||
const uint8_t* name, size_t length, void* core)
|
||||
void Core::onGroupPeerNameChange(Tox*, uint32_t groupId, uint32_t peerId, const uint8_t* name,
|
||||
size_t length, void* core)
|
||||
{
|
||||
const auto newName = ToxString(name, length).getQString();
|
||||
qDebug() << QString("Group %1, Peer %2, name changed to %3").arg(groupId).arg(peerId).arg(newName);
|
||||
|
@ -525,7 +526,7 @@ void Core::onGroupNamelistChange(Tox*, uint32_t groupId, uint32_t peerId,
|
|||
TOX_CONFERENCE_STATE_CHANGE change, void* core)
|
||||
{
|
||||
CoreAV* coreAv = static_cast<Core*>(core)->getAv();
|
||||
const auto changed = change == TOX_CONFERENCE_STATE_CHANGE_PEER_EXIT;
|
||||
const auto changed = change == TOX_CONFERENCE_STATE_CHANGE_PEER_EXIT;
|
||||
if (changed && coreAv->isGroupAvEnabled(groupId)) {
|
||||
CoreAV::invalidateGroupCallPeerSource(groupId, peerId);
|
||||
}
|
||||
|
@ -622,8 +623,8 @@ int Core::sendMessage(uint32_t friendId, const QString& message)
|
|||
{
|
||||
QMutexLocker ml(coreLoopLock.get());
|
||||
ToxString cMessage(message);
|
||||
int receipt = tox_friend_send_message(tox.get(), friendId, TOX_MESSAGE_TYPE_NORMAL, cMessage.data(),
|
||||
cMessage.size(), nullptr);
|
||||
int receipt = tox_friend_send_message(tox.get(), friendId, TOX_MESSAGE_TYPE_NORMAL,
|
||||
cMessage.data(), cMessage.size(), nullptr);
|
||||
emit messageSentResult(friendId, message, receipt);
|
||||
return receipt;
|
||||
}
|
||||
|
@ -632,8 +633,8 @@ int Core::sendAction(uint32_t friendId, const QString& action)
|
|||
{
|
||||
QMutexLocker ml(coreLoopLock.get());
|
||||
ToxString cMessage(action);
|
||||
int receipt = tox_friend_send_message(tox.get(), friendId, TOX_MESSAGE_TYPE_ACTION, cMessage.data(),
|
||||
cMessage.size(), nullptr);
|
||||
int receipt = tox_friend_send_message(tox.get(), friendId, TOX_MESSAGE_TYPE_ACTION,
|
||||
cMessage.data(), cMessage.size(), nullptr);
|
||||
emit messageSentResult(friendId, action, receipt);
|
||||
return receipt;
|
||||
}
|
||||
|
@ -684,7 +685,8 @@ void Core::sendGroupMessageWithType(int groupId, const QString& message, TOX_MES
|
|||
for (auto& part : cMessages) {
|
||||
ToxString cMsg(part);
|
||||
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)) {
|
||||
emit groupSentFailed(groupId);
|
||||
return;
|
||||
|
@ -1011,16 +1013,16 @@ QByteArray Core::getToxSaveData()
|
|||
}
|
||||
|
||||
// Declared to avoid code duplication
|
||||
#define GET_FRIEND_PROPERTY(property, function, checkSize) \
|
||||
const size_t property##Size = function##_size(tox.get(), ids[i], nullptr); \
|
||||
if ((!checkSize || property##Size) && property##Size != SIZE_MAX) { \
|
||||
uint8_t* prop = new uint8_t[property##Size]; \
|
||||
if (function(tox.get(), ids[i], prop, nullptr)) { \
|
||||
QString propStr = ToxString(prop, property##Size).getQString(); \
|
||||
emit friend##property##Changed(ids[i], propStr); \
|
||||
} \
|
||||
\
|
||||
delete[] prop; \
|
||||
#define GET_FRIEND_PROPERTY(property, function, checkSize) \
|
||||
const size_t property##Size = function##_size(tox.get(), ids[i], nullptr); \
|
||||
if ((!checkSize || property##Size) && property##Size != SIZE_MAX) { \
|
||||
uint8_t* prop = new uint8_t[property##Size]; \
|
||||
if (function(tox.get(), ids[i], prop, nullptr)) { \
|
||||
QString propStr = ToxString(prop, property##Size).getQString(); \
|
||||
emit friend##property##Changed(ids[i], propStr); \
|
||||
} \
|
||||
\
|
||||
delete[] prop; \
|
||||
}
|
||||
|
||||
void Core::loadFriends()
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
#include "toxfile.h"
|
||||
#include "toxid.h"
|
||||
|
||||
#include <tox/tox.h>
|
||||
#include "src/core/dhtserver.h"
|
||||
#include <tox/tox.h>
|
||||
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
|
@ -56,8 +56,8 @@ class Core : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
enum class ToxCoreErrors {
|
||||
enum class ToxCoreErrors
|
||||
{
|
||||
BAD_PROXY,
|
||||
INVALID_SAVE,
|
||||
FAILED_TO_START,
|
||||
|
@ -232,8 +232,8 @@ private:
|
|||
const uint8_t* cMessage, size_t length, void* vCore);
|
||||
#if TOX_VERSION_IS_API_COMPATIBLE(0, 2, 0)
|
||||
static void onGroupPeerListChange(Tox*, uint32_t groupId, void* core);
|
||||
static void onGroupPeerNameChange(Tox*, uint32_t groupId, uint32_t peerId,
|
||||
const uint8_t* name, size_t length, void* core);
|
||||
static void onGroupPeerNameChange(Tox*, uint32_t groupId, uint32_t peerId, const uint8_t* name,
|
||||
size_t length, void* core);
|
||||
#else
|
||||
static void onGroupNamelistChange(Tox* tox, uint32_t groupId, uint32_t peerId,
|
||||
TOX_CONFERENCE_STATE_CHANGE change, void* core);
|
||||
|
@ -248,7 +248,7 @@ private:
|
|||
bool checkConnection();
|
||||
|
||||
void checkEncryptedHistory();
|
||||
void makeTox(QByteArray savedata, ICoreSettings *s);
|
||||
void makeTox(QByteArray savedata, ICoreSettings* s);
|
||||
void makeAv();
|
||||
void loadFriends();
|
||||
void bootstrapDht();
|
||||
|
@ -256,7 +256,7 @@ private:
|
|||
void checkLastOnline(uint32_t friendId);
|
||||
|
||||
QString getFriendRequestErrorMessage(const ToxId& friendId, const QString& message) const;
|
||||
static void registerCallbacks(Tox * tox);
|
||||
static void registerCallbacks(Tox* tox);
|
||||
|
||||
private slots:
|
||||
void killTimers();
|
||||
|
@ -264,9 +264,12 @@ private slots:
|
|||
void onStarted();
|
||||
|
||||
private:
|
||||
|
||||
struct ToxDeleter {
|
||||
void operator()(Tox* tox) { tox_kill(tox); }
|
||||
struct ToxDeleter
|
||||
{
|
||||
void operator()(Tox* tox)
|
||||
{
|
||||
tox_kill(tox);
|
||||
}
|
||||
};
|
||||
|
||||
using ToxPtr = std::unique_ptr<Tox, ToxDeleter>;
|
||||
|
|
|
@ -487,7 +487,7 @@ void CoreAV::groupCallCallback(void* tox, uint32_t group, uint32_t peer, const i
|
|||
const Settings& s = Settings::getInstance();
|
||||
// don't play the audio if it comes from a muted peer
|
||||
if (s.getBlackList().contains(peerPk.toString())) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
CoreAV* cav = c->getAv();
|
||||
|
@ -797,7 +797,8 @@ void CoreAV::callCallback(ToxAV* toxav, uint32_t friendNum, bool audio, bool vid
|
|||
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) {
|
||||
/// Hanging up from a callback is supposed to be UB,
|
||||
/// 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));
|
||||
}
|
||||
|
||||
qDebug() << "Recommended audio bitrate with" << friendNum << " is now " << rate
|
||||
<< ", ignoring it";
|
||||
qDebug() << "Recommended audio bitrate with" << friendNum << " is now " << rate << ", ignoring it";
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
qDebug() << "Recommended video bitrate with" << friendNum << " is now " << rate
|
||||
<< ", ignoring it";
|
||||
qDebug() << "Recommended video bitrate with" << friendNum << " is now " << rate << ", ignoring it";
|
||||
}
|
||||
|
||||
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 toggleMuteCallOutput(const Friend* f);
|
||||
#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,
|
||||
uint8_t channels, uint32_t sample_rate, void* core);
|
||||
static void groupCallCallback(void* tox, uint32_t group, uint32_t peer, const int16_t* data,
|
||||
unsigned samples, uint8_t channels, uint32_t sample_rate,
|
||||
void* core);
|
||||
#else
|
||||
static void groupCallCallback(void* tox, int group, int peer, const int16_t* data, unsigned samples,
|
||||
uint8_t channels, unsigned sample_rate, void* core);
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "core.h"
|
||||
#include "corefile.h"
|
||||
#include "core.h"
|
||||
#include "toxfile.h"
|
||||
#include "toxstring.h"
|
||||
#include "src/persistence/profile.h"
|
||||
|
@ -27,8 +27,8 @@
|
|||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QThread>
|
||||
#include <QRegularExpression>
|
||||
#include <QThread>
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
|
@ -112,7 +112,8 @@ void CoreFile::sendAvatarFile(Core* core, uint32_t friendId, const QByteArray& d
|
|||
file.fileKind = TOX_FILE_KIND_AVATAR;
|
||||
file.avatarData = data;
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -122,8 +123,8 @@ void CoreFile::sendFile(Core* core, uint32_t friendId, QString filename, QString
|
|||
QMutexLocker mlocker(&fileSendMutex);
|
||||
|
||||
QByteArray fileName = filename.toUtf8();
|
||||
uint32_t fileNum = tox_file_send(core->tox.get(), friendId, TOX_FILE_KIND_DATA, filesize, nullptr,
|
||||
(uint8_t*)fileName.data(), fileName.size(), nullptr);
|
||||
uint32_t fileNum = tox_file_send(core->tox.get(), friendId, TOX_FILE_KIND_DATA, filesize,
|
||||
nullptr, (uint8_t*)fileName.data(), fileName.size(), nullptr);
|
||||
if (fileNum == std::numeric_limits<uint32_t>::max()) {
|
||||
qWarning() << "sendFile: Can't create the Tox file sender";
|
||||
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};
|
||||
file.filesize = filesize;
|
||||
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)) {
|
||||
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) {
|
||||
file->status = ToxFile::PAUSED;
|
||||
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) {
|
||||
file->status = ToxFile::TRANSMITTING;
|
||||
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 {
|
||||
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) {
|
||||
file->status = ToxFile::PAUSED;
|
||||
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) {
|
||||
file->status = ToxFile::TRANSMITTING;
|
||||
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 {
|
||||
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.fileKind = kind;
|
||||
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);
|
||||
if (kind != TOX_FILE_KIND_AVATAR)
|
||||
emit core->fileReceiveRequested(file);
|
||||
|
@ -336,8 +343,7 @@ void CoreFile::handleAvatarOffer(uint32_t friendId, uint32_t fileId, bool accept
|
|||
auto core = Core::getInstance();
|
||||
if (!accept) {
|
||||
// If it's an avatar but we already have it cached, cancel
|
||||
qDebug() << QString(
|
||||
"Received avatar request %1:%2, reject, since we have it in cache.")
|
||||
qDebug() << QString("Received avatar request %1:%2, reject, since we have it in cache.")
|
||||
.arg(friendId)
|
||||
.arg(fileId);
|
||||
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.fileKind = TOX_FILE_KIND_AVATAR;
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ class CoreFile
|
|||
|
||||
public:
|
||||
static void handleAvatarOffer(uint32_t friendId, uint32_t fileId, bool accept);
|
||||
|
||||
private:
|
||||
CoreFile() = delete;
|
||||
|
||||
|
|
|
@ -15,27 +15,31 @@ static const int MAX_PROXY_ADDRESS_LENGTH = 255;
|
|||
* are correctly deleted.
|
||||
*/
|
||||
|
||||
ToxOptions::ToxOptions(Tox_Options *options, const QByteArray &proxyAddrData)
|
||||
ToxOptions::ToxOptions(Tox_Options* options, const QByteArray& proxyAddrData)
|
||||
: options(options)
|
||||
, proxyAddrData(proxyAddrData)
|
||||
{}
|
||||
|
||||
ToxOptions::~ToxOptions() {
|
||||
ToxOptions::~ToxOptions()
|
||||
{
|
||||
tox_options_free(options);
|
||||
}
|
||||
|
||||
ToxOptions::ToxOptions(ToxOptions &&from) {
|
||||
ToxOptions::ToxOptions(ToxOptions&& from)
|
||||
{
|
||||
options = from.options;
|
||||
proxyAddrData.swap(from.proxyAddrData);
|
||||
from.options = nullptr;
|
||||
from.proxyAddrData.clear();
|
||||
}
|
||||
|
||||
const char *ToxOptions::getProxyAddrData() const {
|
||||
const char* ToxOptions::getProxyAddrData() const
|
||||
{
|
||||
return proxyAddrData.constData();
|
||||
}
|
||||
|
||||
ToxOptions::operator Tox_Options *() {
|
||||
ToxOptions::operator Tox_Options*()
|
||||
{
|
||||
return options;
|
||||
}
|
||||
|
||||
|
@ -44,7 +48,8 @@ ToxOptions::operator Tox_Options *() {
|
|||
* @param savedata Previously saved Tox data
|
||||
* @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
|
||||
// disabled in options.
|
||||
|
@ -61,13 +66,13 @@ std::unique_ptr<ToxOptions> ToxOptions::makeToxOptions(const QByteArray& savedat
|
|||
}
|
||||
if (enableIPv6) {
|
||||
qDebug() << "Core starting with IPv6 enabled";
|
||||
} else if(enableLanDiscovery) {
|
||||
} else if (enableLanDiscovery) {
|
||||
qWarning() << "Core starting with IPv6 disabled. LAN discovery may not work properly.";
|
||||
}
|
||||
|
||||
Tox_Options* tox_opts = tox_options_new(nullptr);
|
||||
|
||||
if(!tox_opts) {
|
||||
if (!tox_opts) {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -76,9 +81,10 @@ std::unique_ptr<ToxOptions> ToxOptions::makeToxOptions(const QByteArray& savedat
|
|||
tox_options_set_log_callback(*toxOptions, ToxLogger::onLogMessage);
|
||||
|
||||
// savedata
|
||||
tox_options_set_savedata_type(*toxOptions, !savedata.isNull() ? TOX_SAVEDATA_TYPE_TOX_SAVE : TOX_SAVEDATA_TYPE_NONE);
|
||||
tox_options_set_savedata_data(*toxOptions, reinterpret_cast<const uint8_t*>(savedata.data()), savedata.size());
|
||||
|
||||
tox_options_set_savedata_type(*toxOptions, !savedata.isNull() ? TOX_SAVEDATA_TYPE_TOX_SAVE
|
||||
: TOX_SAVEDATA_TYPE_NONE);
|
||||
tox_options_set_savedata_data(*toxOptions, reinterpret_cast<const uint8_t*>(savedata.data()),
|
||||
savedata.size());
|
||||
// No proxy by default
|
||||
tox_options_set_proxy_type(*toxOptions, TOX_PROXY_TYPE_NONE);
|
||||
tox_options_set_proxy_host(*toxOptions, nullptr);
|
||||
|
@ -125,4 +131,3 @@ void ToxOptions::setIPv6Enabled(bool enabled)
|
|||
{
|
||||
tox_options_set_ipv6_enabled(options, enabled);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,18 +12,19 @@ class ToxOptions
|
|||
{
|
||||
public:
|
||||
~ToxOptions();
|
||||
ToxOptions (ToxOptions && from);
|
||||
operator Tox_Options* ();
|
||||
ToxOptions(ToxOptions&& from);
|
||||
operator Tox_Options*();
|
||||
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;
|
||||
void setIPv6Enabled(bool enabled);
|
||||
|
||||
private:
|
||||
ToxOptions(Tox_Options *options, const QByteArray& proxyAddrData);
|
||||
ToxOptions(Tox_Options* options, const QByteArray& proxyAddrData);
|
||||
|
||||
private:
|
||||
Tox_Options *options = nullptr;
|
||||
Tox_Options* options = nullptr;
|
||||
QByteArray proxyAddrData;
|
||||
};
|
||||
|
||||
|
|
25
src/main.cpp
25
src/main.cpp
|
@ -155,10 +155,8 @@ int main(int argc, char* argv[])
|
|||
#if defined(Q_OS_UNIX)
|
||||
// PosixSignalNotifier is used only for terminating signals,
|
||||
// so it's connected directly to quit() without any filtering.
|
||||
QObject::connect(&PosixSignalNotifier::globalInstance(),
|
||||
&PosixSignalNotifier::activated,
|
||||
a.get(),
|
||||
&QApplication::quit);
|
||||
QObject::connect(&PosixSignalNotifier::globalInstance(), &PosixSignalNotifier::activated,
|
||||
a.get(), &QApplication::quit);
|
||||
PosixSignalNotifier::watchCommonTerminatingSignals();
|
||||
#endif
|
||||
|
||||
|
@ -195,10 +193,14 @@ int main(int argc, char* argv[])
|
|||
parser.addVersionOption();
|
||||
parser.addPositionalArgument("uri", QObject::tr("Tox URI to parse"));
|
||||
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")));
|
||||
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);
|
||||
|
||||
uint32_t profileId = Settings::getInstance().getCurrentProfileId();
|
||||
|
@ -281,7 +283,7 @@ int main(int argc, char* argv[])
|
|||
profileName = parser.value("p");
|
||||
if (!Profile::exists(profileName)) {
|
||||
qWarning() << "-p profile" << profileName + ".tox"
|
||||
<< "doesn't exist, opening login screen";
|
||||
<< "doesn't exist, opening login screen";
|
||||
doIpc = false;
|
||||
autoLogin = false;
|
||||
} else {
|
||||
|
@ -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 (ipc.waitUntilAccepted(event, 2)) {
|
||||
if (eventType == "activate") {
|
||||
qDebug() << "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>).";
|
||||
qDebug()
|
||||
<< "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 {
|
||||
qDebug() << "Event" << eventType << "was handled by other client.";
|
||||
}
|
||||
|
@ -329,8 +333,7 @@ int main(int argc, char* argv[])
|
|||
Profile* profile = nullptr;
|
||||
|
||||
// Autologin
|
||||
if (autoLogin && Profile::exists(profileName) &&
|
||||
!Profile::isEncrypted(profileName)) {
|
||||
if (autoLogin && Profile::exists(profileName) && !Profile::isEncrypted(profileName)) {
|
||||
profile = Profile::loadProfile(profileName);
|
||||
} else {
|
||||
LoginScreen loginScreen{profileName};
|
||||
|
|
|
@ -19,14 +19,14 @@
|
|||
|
||||
#include "profileinfo.h"
|
||||
#include "src/core/core.h"
|
||||
#include "src/nexus.h"
|
||||
#include "src/persistence/profile.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include "src/nexus.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QBuffer>
|
||||
#include <QClipboard>
|
||||
#include <QFile>
|
||||
#include <QBuffer>
|
||||
|
||||
/**
|
||||
* @class ProfileInfo
|
||||
|
@ -41,7 +41,7 @@
|
|||
* @param profile Pointer to Profile.
|
||||
* @note All pointers parameters shouldn't be null.
|
||||
*/
|
||||
ProfileInfo::ProfileInfo(Core* core, Profile *profile)
|
||||
ProfileInfo::ProfileInfo(Core* core, Profile* profile)
|
||||
: profile{profile}
|
||||
, core{core}
|
||||
{
|
||||
|
@ -55,7 +55,7 @@ ProfileInfo::ProfileInfo(Core* core, Profile *profile)
|
|||
* @param password New password.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
bool ProfileInfo::setPassword(const QString &password)
|
||||
bool ProfileInfo::setPassword(const QString& password)
|
||||
{
|
||||
QString errorMsg = profile->setPassword(password);
|
||||
return errorMsg.isEmpty();
|
||||
|
@ -98,7 +98,7 @@ void ProfileInfo::copyId() const
|
|||
* @brief Set self user name.
|
||||
* @param name New name.
|
||||
*/
|
||||
void ProfileInfo::setUsername(const QString &name)
|
||||
void ProfileInfo::setUsername(const QString& name)
|
||||
{
|
||||
core->setUsername(name);
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ void ProfileInfo::setUsername(const QString &name)
|
|||
* @brief Set self status message.
|
||||
* @param status New status message.
|
||||
*/
|
||||
void ProfileInfo::setStatusMessage(const QString &status)
|
||||
void ProfileInfo::setStatusMessage(const QString& status)
|
||||
{
|
||||
core->setStatusMessage(status);
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ static QString sanitize(const QString& src)
|
|||
* @param name New profile name.
|
||||
* @return Result code of rename operation.
|
||||
*/
|
||||
IProfileInfo::RenameResult ProfileInfo::renameProfile(const QString &name)
|
||||
IProfileInfo::RenameResult ProfileInfo::renameProfile(const QString& name)
|
||||
{
|
||||
QString cur = profile->getName();
|
||||
if (name.isEmpty()) {
|
||||
|
@ -191,7 +191,7 @@ static bool tryRemoveFile(const QString& filepath)
|
|||
* @param path Path to save profile.
|
||||
* @return Result code of save operation.
|
||||
*/
|
||||
IProfileInfo::SaveResult ProfileInfo::exportProfile(const QString &path) const
|
||||
IProfileInfo::SaveResult ProfileInfo::exportProfile(const QString& path) const
|
||||
{
|
||||
QString current = profile->getName() + Core::TOX_EXT;
|
||||
if (path.isEmpty()) {
|
||||
|
@ -284,7 +284,7 @@ QByteArray picToPng(const QPixmap& pic)
|
|||
* @param path Path to image, which should be the new avatar.
|
||||
* @return Code of set avatar operation.
|
||||
*/
|
||||
IProfileInfo::SetAvatarResult ProfileInfo::setAvatar(const QString &path)
|
||||
IProfileInfo::SetAvatarResult ProfileInfo::setAvatar(const QString& path)
|
||||
{
|
||||
if (path.isEmpty()) {
|
||||
return SetAvatarResult::EmptyPath;
|
||||
|
|
|
@ -61,8 +61,7 @@ Nexus::Nexus(QObject* parent)
|
|||
, profile{nullptr}
|
||||
, widget{nullptr}
|
||||
, running{true}
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
Nexus::~Nexus()
|
||||
{
|
||||
|
@ -209,7 +208,8 @@ void Nexus::showMainGUI()
|
|||
connect(core, &Core::friendMessageReceived, widget, &Widget::onFriendMessageReceived);
|
||||
connect(core, &Core::groupInviteReceived, widget, &Widget::onGroupInviteReceived);
|
||||
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::groupPeerNameChanged, widget, &Widget::onGroupPeerNameChanged);
|
||||
connect(core, &Core::groupTitleChanged, widget, &Widget::onGroupTitleChanged);
|
||||
|
|
|
@ -56,7 +56,7 @@ void Profile::initCore(const QByteArray& toxsave, ICoreSettings& s)
|
|||
{
|
||||
Core::ToxCoreErrors err;
|
||||
core = Core::makeToxCore(toxsave, &s, &err);
|
||||
if(!core) {
|
||||
if (!core) {
|
||||
switch (err) {
|
||||
case Core::ToxCoreErrors::BAD_PROXY:
|
||||
emit badProxy();
|
||||
|
@ -94,7 +94,6 @@ Profile::Profile(QString name, const QString& password, bool isNewProfile, const
|
|||
|
||||
const ToxId& selfId = core->getSelfId();
|
||||
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)
|
||||
{
|
||||
if (ProfileLocker::hasLock()) {
|
||||
qCritical() << "Tried to load profile " << name
|
||||
<< ", but another profile is already locked!";
|
||||
qCritical() << "Tried to load profile " << name << ", but another profile is already locked!";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -203,8 +201,7 @@ Profile* Profile::createProfile(QString name, QString password)
|
|||
}
|
||||
|
||||
if (ProfileLocker::hasLock()) {
|
||||
qCritical() << "Tried to create profile " << name
|
||||
<< ", but another profile is already locked!";
|
||||
qCritical() << "Tried to create profile " << name << ", but another profile is already locked!";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -333,7 +330,7 @@ void Profile::onSaveToxSave()
|
|||
}
|
||||
|
||||
// TODO(sudden6): handle this better maybe?
|
||||
void Profile::onAvatarOfferReceived(uint32_t friendId, uint32_t fileId, const QByteArray &avatarHash)
|
||||
void Profile::onAvatarOfferReceived(uint32_t friendId, uint32_t fileId, const QByteArray& avatarHash)
|
||||
{
|
||||
// accept if we don't have it already
|
||||
const bool accept = getAvatarHash(core->getFriendPublicKey(friendId)) != avatarHash;
|
||||
|
@ -409,8 +406,7 @@ QString Profile::avatarPath(const ToxPk& owner, bool forceUnencrypted)
|
|||
QByteArray hash(hashSize, 0);
|
||||
crypto_generichash((uint8_t*)hash.data(), hashSize, (uint8_t*)idData.data(), idData.size(),
|
||||
(uint8_t*)pubkeyData.data(), pubkeyData.size());
|
||||
return Settings::getInstance().getSettingsDirPath() + "avatars/" + hash.toHex().toUpper()
|
||||
+ ".png";
|
||||
return Settings::getInstance().getSettingsDirPath() + "avatars/" + hash.toHex().toUpper() + ".png";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -557,7 +553,7 @@ void Profile::onRequestSent(const ToxPk& friendPk, const QString& message)
|
|||
void Profile::saveAvatar(const ToxPk& owner, const QByteArray& avatar)
|
||||
{
|
||||
bool needEncrypt = encrypted && !avatar.isEmpty();
|
||||
const QByteArray& pic = needEncrypt ? passkey->encrypt(avatar): avatar;
|
||||
const QByteArray& pic = needEncrypt ? passkey->encrypt(avatar) : avatar;
|
||||
|
||||
QString path = avatarPath(owner);
|
||||
QDir(Settings::getInstance().getSettingsDirPath()).mkdir("avatars");
|
||||
|
@ -756,14 +752,14 @@ void Profile::restartCore()
|
|||
{
|
||||
GUI::setEnabled(false); // Core::reset re-enables it
|
||||
|
||||
if(core && !isRemoved) {
|
||||
if (core && !isRemoved) {
|
||||
// TODO(sudden6): there's a potential race condition between unlocking the core loop
|
||||
// and killing the core
|
||||
const QByteArray& savedata = core->getToxSaveData();
|
||||
// save to disk just in case
|
||||
bool saved = saveToxSave(savedata);
|
||||
|
||||
if(saved) {
|
||||
if (saved) {
|
||||
qDebug() << "Restarting Core";
|
||||
initCore(savedata, Settings::getInstance());
|
||||
core->start();
|
||||
|
|
|
@ -86,7 +86,7 @@ public slots:
|
|||
|
||||
private slots:
|
||||
void loadDatabase(const ToxId& id, QString password);
|
||||
void saveAvatar(const ToxPk& owner, const QByteArray &avatar);
|
||||
void saveAvatar(const ToxPk& owner, const QByteArray& avatar);
|
||||
void removeAvatar(const ToxPk& owner);
|
||||
void onSaveToxSave();
|
||||
// TODO(sudden6): use ToxPk instead of friendId
|
||||
|
@ -97,7 +97,7 @@ private:
|
|||
static QStringList getFilesByExt(QString extension);
|
||||
QString avatarPath(const ToxPk& owner, bool forceUnencrypted = false);
|
||||
bool saveToxSave(QByteArray data);
|
||||
void initCore(const QByteArray &toxsave, ICoreSettings &s);
|
||||
void initCore(const QByteArray& toxsave, ICoreSettings& s);
|
||||
|
||||
private:
|
||||
std::unique_ptr<Core> core = nullptr;
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
#include "groupnetcamview.h"
|
||||
#include "src/audio/audio.h"
|
||||
#include "src/core/core.h"
|
||||
#include "src/model/friend.h"
|
||||
#include "src/friendlist.h"
|
||||
#include "src/model/friend.h"
|
||||
#include "src/nexus.h"
|
||||
#include "src/persistence/profile.h"
|
||||
#include "src/video/videosurface.h"
|
||||
|
@ -56,9 +56,7 @@ public:
|
|||
layout->addWidget(label);
|
||||
}
|
||||
|
||||
~LabeledVideo()
|
||||
{
|
||||
}
|
||||
~LabeledVideo() {}
|
||||
|
||||
VideoSurface* getVideoSurface() const
|
||||
{
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
#include "netcamview.h"
|
||||
#include "camerasource.h"
|
||||
#include "src/core/core.h"
|
||||
#include "src/model/friend.h"
|
||||
#include "src/friendlist.h"
|
||||
#include "src/model/friend.h"
|
||||
#include "src/nexus.h"
|
||||
#include "src/persistence/profile.h"
|
||||
#include "src/persistence/settings.h"
|
||||
|
|
|
@ -27,21 +27,21 @@
|
|||
#include "src/core/coreav.h"
|
||||
#include "src/model/friend.h"
|
||||
#include "src/nexus.h"
|
||||
#include "src/persistence/history.h"
|
||||
#include "src/persistence/offlinemsgengine.h"
|
||||
#include "src/persistence/profile.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include "src/persistence/history.h"
|
||||
#include "src/video/netcamview.h"
|
||||
#include "src/widget/chatformheader.h"
|
||||
#include "src/widget/form/loadhistorydialog.h"
|
||||
#include "src/widget/maskablepixmapwidget.h"
|
||||
#include "src/widget/searchform.h"
|
||||
#include "src/widget/style.h"
|
||||
#include "src/widget/tool/callconfirmwidget.h"
|
||||
#include "src/widget/tool/chattextedit.h"
|
||||
#include "src/widget/tool/screenshotgrabber.h"
|
||||
#include "src/widget/translator.h"
|
||||
#include "src/widget/widget.h"
|
||||
#include "src/widget/searchform.h"
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QFileDialog>
|
||||
|
@ -197,12 +197,10 @@ ChatForm::ChatForm(Friend* chatFriend, History* history)
|
|||
});
|
||||
|
||||
// reflect name changes in the header
|
||||
connect(headWidget, &ChatFormHeader::nameChanged, this, [=](const QString& newName) {
|
||||
f->setAlias(newName);
|
||||
});
|
||||
connect(headWidget, &ChatFormHeader::callAccepted, this, [this] {
|
||||
onAnswerCallTriggered(lastCallIsVideo);
|
||||
});
|
||||
connect(headWidget, &ChatFormHeader::nameChanged, this,
|
||||
[=](const QString& newName) { f->setAlias(newName); });
|
||||
connect(headWidget, &ChatFormHeader::callAccepted, this,
|
||||
[this] { onAnswerCallTriggered(lastCallIsVideo); });
|
||||
connect(headWidget, &ChatFormHeader::callRejected, this, &ChatForm::onRejectCallTriggered);
|
||||
|
||||
updateCallButtons();
|
||||
|
@ -265,7 +263,8 @@ void ChatForm::onTextEditChanged()
|
|||
|
||||
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()) {
|
||||
return;
|
||||
|
@ -680,8 +679,9 @@ void ChatForm::dropEvent(QDropEvent* ev)
|
|||
|
||||
file.close();
|
||||
if (file.isSequential()) {
|
||||
QMessageBox::critical(0, tr("Bad idea"), tr("You're trying to send a sequential file, "
|
||||
"which is not going to work!"));
|
||||
QMessageBox::critical(0, tr("Bad idea"),
|
||||
tr("You're trying to send a sequential file, "
|
||||
"which is not going to work!"));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -789,7 +789,9 @@ void ChatForm::insertChatlines(QList<ChatLine::Ptr> chatLines)
|
|||
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
|
||||
QDate newDate = metadata.msgDateTime.date();
|
||||
|
@ -813,11 +815,13 @@ ChatForm::MessageMetadata ChatForm::getMessageMetadata(History::HistMessage cons
|
|||
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());
|
||||
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;
|
||||
QDateTime dateTime = metadata.needSending ? QDateTime() : metadata.msgDateTime;
|
||||
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");
|
||||
// TODO: add notification once notifications are implemented
|
||||
|
||||
addSystemInfoMessage(mess.arg(name, dhms), ChatMessage::INFO,
|
||||
QDateTime::currentDateTime());
|
||||
addSystemInfoMessage(mess.arg(name, dhms), ChatMessage::INFO, QDateTime::currentDateTime());
|
||||
callDurationTimer->stop();
|
||||
callDuration->setText("");
|
||||
callDuration->hide();
|
||||
|
@ -1033,9 +1036,9 @@ void ChatForm::SendMessageStr(QString msg)
|
|||
QString pk = f->getPublicKey().toString();
|
||||
QString name = Core::getInstance()->getUsername();
|
||||
history->addNewMessage(pk, historyPart, selfPk, timestamp, status, name,
|
||||
[offMsgEngine, rec, ma](int64_t id) {
|
||||
offMsgEngine->registerReceipt(rec, id, ma);
|
||||
});
|
||||
[offMsgEngine, rec, ma](int64_t id) {
|
||||
offMsgEngine->registerReceipt(rec, id, ma);
|
||||
});
|
||||
} else {
|
||||
// TODO: Make faux-offline messaging work partially with the history disabled
|
||||
ma->markAsSent(QDateTime::currentDateTime());
|
||||
|
|
|
@ -73,7 +73,7 @@ public slots:
|
|||
void onAvStart(uint32_t friendId, bool video);
|
||||
void onAvEnd(uint32_t friendId, bool error);
|
||||
void onAvatarChange(uint32_t friendId, const QPixmap& pic);
|
||||
void onAvatarRemoved(const ToxPk &friendPk);
|
||||
void onAvatarRemoved(const ToxPk& friendPk);
|
||||
void onFileNameChanged();
|
||||
|
||||
protected slots:
|
||||
|
@ -109,25 +109,30 @@ private slots:
|
|||
void onExportChat();
|
||||
|
||||
private:
|
||||
struct MessageMetadata {
|
||||
struct MessageMetadata
|
||||
{
|
||||
const bool isSelf;
|
||||
const bool needSending;
|
||||
const bool isAction;
|
||||
const qint64 id;
|
||||
const ToxPk authorPk;
|
||||
const QDateTime msgDateTime;
|
||||
MessageMetadata(bool isSelf, bool needSending, bool isAction, qint64 id, ToxPk authorPk, QDateTime msgDateTime) :
|
||||
isSelf{isSelf},
|
||||
needSending{needSending},
|
||||
isAction{isAction},
|
||||
id{id},
|
||||
authorPk{authorPk},
|
||||
msgDateTime{msgDateTime} {}
|
||||
MessageMetadata(bool isSelf, bool needSending, bool isAction, qint64 id, ToxPk authorPk,
|
||||
QDateTime msgDateTime)
|
||||
: isSelf{isSelf}
|
||||
, needSending{needSending}
|
||||
, isAction{isAction}
|
||||
, id{id}
|
||||
, authorPk{authorPk}
|
||||
, msgDateTime{msgDateTime}
|
||||
{}
|
||||
};
|
||||
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);
|
||||
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 insertChatlines(QList<ChatLine::Ptr> chatLines);
|
||||
void updateMuteMicButton();
|
||||
|
|
|
@ -24,11 +24,11 @@
|
|||
#include "maskablepixmapwidget.h"
|
||||
|
||||
#include "src/core/core.h"
|
||||
#include "src/model/friend.h"
|
||||
#include "src/model/about/aboutfriend.h"
|
||||
#include "src/friendlist.h"
|
||||
#include "src/model/group.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/widget/about/aboutfriendform.h"
|
||||
#include "src/widget/form/chatform.h"
|
||||
|
@ -49,8 +49,7 @@
|
|||
|
||||
#include <cassert>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
constexpr auto MAX_NAME_LENGTH = 30;
|
||||
}
|
||||
|
||||
|
@ -121,8 +120,8 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
|||
}
|
||||
|
||||
menu.addSeparator();
|
||||
QMenu* inviteMenu = menu.addMenu(tr("Invite to group",
|
||||
"Menu to invite a friend to a groupchat"));
|
||||
QMenu* inviteMenu =
|
||||
menu.addMenu(tr("Invite to group", "Menu to invite a friend to a groupchat"));
|
||||
inviteMenu->setEnabled(frnd->getStatus() != Status::Offline);
|
||||
const auto newGroupAction = inviteMenu->addAction(tr("To new group"));
|
||||
connect(newGroupAction, &QAction::triggered, this, &FriendWidget::moveToNewGroup);
|
||||
|
@ -139,8 +138,8 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
|||
|
||||
const auto& s = Settings::getInstance();
|
||||
const auto circleId = s.getFriendCircleID(frnd->getPublicKey());
|
||||
auto circleMenu = menu.addMenu(tr("Move to circle...",
|
||||
"Menu to move a friend into a different circle"));
|
||||
auto circleMenu =
|
||||
menu.addMenu(tr("Move to circle...", "Menu to move a friend into a different circle"));
|
||||
|
||||
const auto pk = frnd->getPublicKey();
|
||||
const auto newCircleAction = circleMenu->addAction(tr("To new circle"));
|
||||
|
@ -148,8 +147,8 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
|||
|
||||
if (circleId != -1) {
|
||||
const QString circleName = s.getCircleName(circleId);
|
||||
const auto removeCircleAction = circleMenu->addAction(
|
||||
tr("Remove from circle '%1'").arg(circleName));
|
||||
const auto removeCircleAction =
|
||||
circleMenu->addAction(tr("Remove from circle '%1'").arg(circleName));
|
||||
connect(removeCircleAction, &QAction::triggered, this, &FriendWidget::removeFromCircle);
|
||||
}
|
||||
|
||||
|
@ -180,8 +179,8 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
|||
connect(setAlias, &QAction::triggered, [this]() { nameLabel->editBegin(); });
|
||||
|
||||
menu.addSeparator();
|
||||
auto autoAccept = menu.addAction(tr("Auto accept files from this friend",
|
||||
"context menu entry"));
|
||||
auto autoAccept =
|
||||
menu.addAction(tr("Auto accept files from this friend", "context menu entry"));
|
||||
const auto dir = s.getAutoAcceptDir(pk);
|
||||
autoAccept->setCheckable(true);
|
||||
autoAccept->setChecked(!dir.isEmpty());
|
||||
|
@ -189,10 +188,10 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
|||
menu.addSeparator();
|
||||
|
||||
if (!contentDialog || !contentDialog->hasFriendWidget(friendId, this)) {
|
||||
const auto removeAction = menu.addAction(
|
||||
tr("Remove friend", "Menu to remove the friend from our friendlist"));
|
||||
const auto removeAction =
|
||||
menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist"));
|
||||
connect(removeAction, &QAction::triggered, this, [=]() { emit removeFriend(friendId); },
|
||||
Qt::QueuedConnection);
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
menu.addSeparator();
|
||||
|
@ -228,11 +227,9 @@ void FriendWidget::inviteFriend(uint32_t friendId, const Group* group)
|
|||
Core::getInstance()->groupInviteFriend(friendId, group->getId());
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
|
||||
std::tuple<CircleWidget*, FriendListWidget*> getCircleAndFriendList(
|
||||
const Friend* frnd, FriendWidget* fw)
|
||||
std::tuple<CircleWidget*, FriendListWidget*> getCircleAndFriendList(const Friend* frnd, FriendWidget* fw)
|
||||
{
|
||||
const auto pk = frnd->getPublicKey();
|
||||
const auto circleId = Settings::getInstance().getFriendCircleID(pk);
|
||||
|
@ -242,7 +239,7 @@ std::tuple<CircleWidget*, FriendListWidget*> getCircleAndFriendList(
|
|||
return std::make_tuple(circleWidget, friendList);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void FriendWidget::moveToNewCircle()
|
||||
{
|
||||
|
@ -258,7 +255,7 @@ void FriendWidget::moveToNewCircle()
|
|||
friendList->addCircleWidget(this);
|
||||
} else {
|
||||
const auto pk = frnd->getPublicKey();
|
||||
auto &s = Settings::getInstance();
|
||||
auto& s = Settings::getInstance();
|
||||
auto circleId = s.addCircle();
|
||||
s.setFriendCircleID(pk, circleId);
|
||||
}
|
||||
|
@ -310,11 +307,13 @@ void FriendWidget::moveToCircle(int newCircleId)
|
|||
void FriendWidget::changeAutoAccept(bool enable)
|
||||
{
|
||||
const auto pk = frnd->getPublicKey();
|
||||
auto &s = Settings::getInstance();
|
||||
auto& s = Settings::getInstance();
|
||||
if (enable) {
|
||||
const auto oldDir = s.getAutoAcceptDir(pk);
|
||||
const auto newDir = QFileDialog::getExistingDirectory(
|
||||
Q_NULLPTR, tr("Choose an auto accept directory", "popup title"), oldDir);
|
||||
const auto newDir =
|
||||
QFileDialog::getExistingDirectory(Q_NULLPTR,
|
||||
tr("Choose an auto accept directory", "popup title"),
|
||||
oldDir);
|
||||
|
||||
const auto friendId = frnd->getId();
|
||||
qDebug() << "Setting auto accept dir for" << friendId << "to" << newDir;
|
||||
|
@ -351,6 +350,7 @@ void FriendWidget::setAsInactiveChatroom()
|
|||
|
||||
void FriendWidget::updateStatusLight()
|
||||
{
|
||||
// clang-format off
|
||||
static const QString statuses[] = {
|
||||
":img/status/online.svg",
|
||||
":img/status/online_notification.svg",
|
||||
|
@ -361,6 +361,7 @@ void FriendWidget::updateStatusLight()
|
|||
":img/status/offline.svg",
|
||||
":img/status/offline_notification.svg",
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
const bool event = frnd->getEventFlag();
|
||||
const int index = static_cast<int>(frnd->getStatus()) * 2 + event;
|
||||
|
|
|
@ -46,8 +46,8 @@ signals:
|
|||
void contextMenuCalled(QContextMenuEvent* event);
|
||||
|
||||
public slots:
|
||||
void onAvatarChange(const ToxPk &friendPk, const QPixmap& pic);
|
||||
void onAvatarRemoved(const ToxPk &friendPk);
|
||||
void onAvatarChange(const ToxPk& friendPk, const QPixmap& pic);
|
||||
void onAvatarRemoved(const ToxPk& friendPk);
|
||||
void onContextMenuCalled(QContextMenuEvent* event);
|
||||
|
||||
protected:
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
#include "friendlistwidget.h"
|
||||
#include "friendwidget.h"
|
||||
#include "groupwidget.h"
|
||||
#include "src/model/groupinvite.h"
|
||||
#include "maskablepixmapwidget.h"
|
||||
#include "splitterrestorer.h"
|
||||
#include "systemtrayicon.h"
|
||||
|
@ -52,11 +51,12 @@
|
|||
#include "src/audio/audio.h"
|
||||
#include "src/core/core.h"
|
||||
#include "src/core/coreav.h"
|
||||
#include "src/model/friend.h"
|
||||
#include "src/friendlist.h"
|
||||
#include "src/model/group.h"
|
||||
#include "src/model/profile/profileinfo.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/nexus.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);
|
||||
#endif
|
||||
connect(friendWidget, &FriendWidget::removeFriend, this, widgetRemoveFriend);
|
||||
connect(friendWidget, &FriendWidget::middleMouseClicked, dialog, [=]() {
|
||||
dialog->removeFriend(friendId);
|
||||
});
|
||||
connect(friendWidget, &FriendWidget::middleMouseClicked, dialog,
|
||||
[=]() { dialog->removeFriend(friendId); });
|
||||
connect(friendWidget, &FriendWidget::copyFriendIdToClipboard, this,
|
||||
&Widget::copyFriendIdToClipboard);
|
||||
|
||||
|
@ -1265,16 +1264,14 @@ void Widget::addFriendDialog(const Friend* frnd, ContentDialog* dialog)
|
|||
connect(friendWidget, &FriendWidget::contextMenuCalled, widget,
|
||||
[=](QContextMenuEvent* event) { emit widget->contextMenuCalled(event); });
|
||||
|
||||
connect(friendWidget, &FriendWidget::chatroomWidgetClicked,
|
||||
[=](GenericChatroomWidget* w) {
|
||||
Q_UNUSED(w);
|
||||
emit widget->chatroomWidgetClicked(widget);
|
||||
});
|
||||
connect(friendWidget, &FriendWidget::newWindowOpened,
|
||||
[=](GenericChatroomWidget* w) {
|
||||
Q_UNUSED(w);
|
||||
emit widget->newWindowOpened(widget);
|
||||
});
|
||||
connect(friendWidget, &FriendWidget::chatroomWidgetClicked, [=](GenericChatroomWidget* w) {
|
||||
Q_UNUSED(w);
|
||||
emit widget->chatroomWidgetClicked(widget);
|
||||
});
|
||||
connect(friendWidget, &FriendWidget::newWindowOpened, [=](GenericChatroomWidget* w) {
|
||||
Q_UNUSED(w);
|
||||
emit widget->newWindowOpened(widget);
|
||||
});
|
||||
// FIXME: emit should be removed
|
||||
emit widget->chatroomWidgetClicked(widget);
|
||||
|
||||
|
@ -1308,25 +1305,22 @@ void Widget::addGroupDialog(Group* group, ContentDialog* dialog)
|
|||
#endif
|
||||
connect(groupWidget, &GroupWidget::removeGroup, this, removeGroup);
|
||||
connect(groupWidget, &GroupWidget::chatroomWidgetClicked, chatForm, &GroupChatForm::focusInput);
|
||||
connect(groupWidget, &GroupWidget::middleMouseClicked, dialog, [=]() {
|
||||
dialog->removeGroup(groupId);
|
||||
});
|
||||
connect(groupWidget, &GroupWidget::middleMouseClicked, dialog,
|
||||
[=]() { dialog->removeGroup(groupId); });
|
||||
connect(groupWidget, &GroupWidget::chatroomWidgetClicked, chatForm, &ChatForm::focusInput);
|
||||
|
||||
// Signal transmission from the created `groupWidget` (which shown in
|
||||
// ContentDialog) to the `widget` (which shown in main widget)
|
||||
// FIXME: emit should be removed
|
||||
connect(groupWidget, &GroupWidget::chatroomWidgetClicked,
|
||||
[=](GenericChatroomWidget* w) {
|
||||
Q_UNUSED(w);
|
||||
emit widget->chatroomWidgetClicked(widget);
|
||||
});
|
||||
connect(groupWidget, &GroupWidget::chatroomWidgetClicked, [=](GenericChatroomWidget* w) {
|
||||
Q_UNUSED(w);
|
||||
emit widget->chatroomWidgetClicked(widget);
|
||||
});
|
||||
|
||||
connect(groupWidget, &GroupWidget::newWindowOpened,
|
||||
[=](GenericChatroomWidget* w) {
|
||||
Q_UNUSED(w);
|
||||
emit widget->newWindowOpened(widget);
|
||||
});
|
||||
connect(groupWidget, &GroupWidget::newWindowOpened, [=](GenericChatroomWidget* w) {
|
||||
Q_UNUSED(w);
|
||||
emit widget->newWindowOpened(widget);
|
||||
});
|
||||
|
||||
// FIXME: emit should be removed
|
||||
emit widget->chatroomWidgetClicked(widget);
|
||||
|
@ -1936,9 +1930,7 @@ Group* Widget::createGroup(int groupId)
|
|||
auto widgetRemoveGroup = static_cast<void (Widget::*)(int)>(&Widget::removeGroup);
|
||||
#endif
|
||||
connect(widget, &GroupWidget::removeGroup, this, widgetRemoveGroup);
|
||||
connect(widget, &GroupWidget::middleMouseClicked, this, [=]() {
|
||||
removeGroup(groupId);
|
||||
});
|
||||
connect(widget, &GroupWidget::middleMouseClicked, this, [=]() { removeGroup(groupId); });
|
||||
connect(widget, &GroupWidget::chatroomWidgetClicked, form, &ChatForm::focusInput);
|
||||
connect(form, &GroupChatForm::sendMessage, core, &Core::sendGroupMessage);
|
||||
connect(form, &GroupChatForm::sendAction, core, &Core::sendGroupAction);
|
||||
|
@ -2277,8 +2269,7 @@ inline QIcon Widget::prepareIcon(QString path, int w, int h)
|
|||
}
|
||||
|
||||
desktop = desktop.toLower();
|
||||
if (desktop == "xfce" || desktop.contains("gnome") || desktop == "mate"
|
||||
|| desktop == "x-cinnamon") {
|
||||
if (desktop == "xfce" || desktop.contains("gnome") || desktop == "mate" || desktop == "x-cinnamon") {
|
||||
if (w > 0 && h > 0) {
|
||||
QSvgRenderer renderer(path);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user