mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #4316
noavarice (3): refactor: Core refactoring refactor: next part of Core refactoring refactor: returned correct code format
This commit is contained in:
commit
8028281069
File diff suppressed because it is too large
Load Diff
|
@ -21,24 +21,17 @@
|
||||||
#ifndef CORE_HPP
|
#ifndef CORE_HPP
|
||||||
#define CORE_HPP
|
#define CORE_HPP
|
||||||
|
|
||||||
#include <QMutex>
|
|
||||||
#include <QObject>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
#include <tox/tox.h>
|
|
||||||
#include <tox/toxencryptsave.h>
|
|
||||||
|
|
||||||
#include "corestructs.h"
|
#include "corestructs.h"
|
||||||
#include "toxid.h"
|
#include "toxid.h"
|
||||||
|
|
||||||
class Profile;
|
#include <tox/tox.h>
|
||||||
template <typename T>
|
|
||||||
class QList;
|
#include <QMutex>
|
||||||
class QTimer;
|
#include <QObject>
|
||||||
class QString;
|
|
||||||
struct ToxAV;
|
|
||||||
class CoreAV;
|
class CoreAV;
|
||||||
struct vpx_image;
|
class Profile;
|
||||||
|
class QTimer;
|
||||||
|
|
||||||
class Core : public QObject
|
class Core : public QObject
|
||||||
{
|
{
|
||||||
|
@ -53,7 +46,7 @@ public:
|
||||||
static const QString TOX_EXT;
|
static const QString TOX_EXT;
|
||||||
static const QString CONFIG_FILE_NAME;
|
static const QString CONFIG_FILE_NAME;
|
||||||
static QString sanitize(QString name);
|
static QString sanitize(QString name);
|
||||||
static QList<QString> splitMessage(const QString& message, int maxLen);
|
static QStringList splitMessage(const QString& message, int maxLen);
|
||||||
|
|
||||||
static QByteArray getSaltFromFile(QString filename);
|
static QByteArray getSaltFromFile(QString filename);
|
||||||
|
|
||||||
|
@ -63,7 +56,7 @@ public:
|
||||||
uint32_t getGroupNumberPeers(int groupId) const;
|
uint32_t getGroupNumberPeers(int groupId) const;
|
||||||
QString getGroupPeerName(int groupId, int peerId) const;
|
QString getGroupPeerName(int groupId, int peerId) const;
|
||||||
ToxPk getGroupPeerPk(int groupId, int peerId) const;
|
ToxPk getGroupPeerPk(int groupId, int peerId) const;
|
||||||
QList<QString> getGroupPeerNames(int groupId) const;
|
QStringList getGroupPeerNames(int groupId) const;
|
||||||
ToxPk getFriendPublicKey(uint32_t friendNumber) const;
|
ToxPk getFriendPublicKey(uint32_t friendNumber) const;
|
||||||
QString getFriendUsername(uint32_t friendNumber) const;
|
QString getFriendUsername(uint32_t friendNumber) const;
|
||||||
|
|
||||||
|
@ -76,6 +69,7 @@ public:
|
||||||
Status getStatus() const;
|
Status getStatus() const;
|
||||||
QString getStatusMessage() const;
|
QString getStatusMessage() const;
|
||||||
ToxId getSelfId() const;
|
ToxId getSelfId() const;
|
||||||
|
ToxPk getSelfPublicKey() const;
|
||||||
QPair<QByteArray, QByteArray> getKeypair() const;
|
QPair<QByteArray, QByteArray> getKeypair() const;
|
||||||
|
|
||||||
bool isReady() const;
|
bool isReady() const;
|
||||||
|
@ -215,11 +209,13 @@ private:
|
||||||
|
|
||||||
void checkEncryptedHistory();
|
void checkEncryptedHistory();
|
||||||
void makeTox(QByteArray savedata);
|
void makeTox(QByteArray savedata);
|
||||||
|
void makeAv();
|
||||||
void loadFriends();
|
void loadFriends();
|
||||||
|
|
||||||
void checkLastOnline(uint32_t friendId);
|
void checkLastOnline(uint32_t friendId);
|
||||||
|
|
||||||
void deadifyTox();
|
void deadifyTox();
|
||||||
|
QString getFriendRequestErrorMessage(const ToxId& friendId, const QString& message) const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void killTimers(bool onlyStop);
|
void killTimers(bool onlyStop);
|
||||||
|
|
|
@ -68,13 +68,17 @@ QString statusToString(const Status status)
|
||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case Status::Online: result = ChatForm::tr("online", "contact status");
|
case Status::Online:
|
||||||
|
result = ChatForm::tr("online", "contact status");
|
||||||
break;
|
break;
|
||||||
case Status::Away: result = ChatForm::tr("away", "contact status");
|
case Status::Away:
|
||||||
|
result = ChatForm::tr("away", "contact status");
|
||||||
break;
|
break;
|
||||||
case Status::Busy: result = ChatForm::tr("busy", "contact status");
|
case Status::Busy:
|
||||||
|
result = ChatForm::tr("busy", "contact status");
|
||||||
break;
|
break;
|
||||||
case Status::Offline: result = ChatForm::tr("offline", "contact status");
|
case Status::Offline:
|
||||||
|
result = ChatForm::tr("offline", "contact status");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -171,12 +175,12 @@ ChatForm::ChatForm(Friend* chatFriend)
|
||||||
connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered);
|
connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered);
|
||||||
connect(msgEdit, &ChatTextEdit::textChanged, this, &ChatForm::onTextEditChanged);
|
connect(msgEdit, &ChatTextEdit::textChanged, this, &ChatForm::onTextEditChanged);
|
||||||
connect(statusMessageLabel, &CroppingLabel::customContextMenuRequested, this,
|
connect(statusMessageLabel, &CroppingLabel::customContextMenuRequested, this,
|
||||||
[&](const QPoint& pos) {
|
[&](const QPoint& pos) {
|
||||||
if (!statusMessageLabel->text().isEmpty()) {
|
if (!statusMessageLabel->text().isEmpty()) {
|
||||||
QWidget* sender = static_cast<QWidget*>(this->sender());
|
QWidget* sender = static_cast<QWidget*>(this->sender());
|
||||||
statusMessageMenu.exec(sender->mapToGlobal(pos));
|
statusMessageMenu.exec(sender->mapToGlobal(pos));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(&typingTimer, &QTimer::timeout, this, [=] {
|
connect(&typingTimer, &QTimer::timeout, this, [=] {
|
||||||
Core::getInstance()->sendTyping(f->getFriendId(), false);
|
Core::getInstance()->sendTyping(f->getFriendId(), false);
|
||||||
|
@ -237,12 +241,8 @@ void ChatForm::onTextEditChanged()
|
||||||
|
|
||||||
void ChatForm::onAttachClicked()
|
void ChatForm::onAttachClicked()
|
||||||
{
|
{
|
||||||
QStringList paths = QFileDialog::getOpenFileNames(this,
|
QStringList paths = QFileDialog::getOpenFileNames(this, tr("Send a file"), QDir::homePath(), 0,
|
||||||
tr("Send a file"),
|
0, QFileDialog::DontUseNativeDialog);
|
||||||
QDir::homePath(),
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
QFileDialog::DontUseNativeDialog);
|
|
||||||
if (paths.isEmpty()) {
|
if (paths.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -252,16 +252,14 @@ void ChatForm::onAttachClicked()
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
QString fileName = QFileInfo(path).fileName();
|
QString fileName = QFileInfo(path).fileName();
|
||||||
if (!file.exists() || !file.open(QIODevice::ReadOnly)) {
|
if (!file.exists() || !file.open(QIODevice::ReadOnly)) {
|
||||||
QMessageBox::warning(this,
|
QMessageBox::warning(this, tr("Unable to open"),
|
||||||
tr("Unable to open"),
|
|
||||||
tr("qTox wasn't able to open %1").arg(fileName));
|
tr("qTox wasn't able to open %1").arg(fileName));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
if (file.isSequential()) {
|
if (file.isSequential()) {
|
||||||
QMessageBox::critical(this,
|
QMessageBox::critical(this, tr("Bad idea"),
|
||||||
tr("Bad idea"),
|
|
||||||
tr("You're trying to send a sequential file, "
|
tr("You're trying to send a sequential file, "
|
||||||
"which is not going to work!"));
|
"which is not going to work!"));
|
||||||
continue;
|
continue;
|
||||||
|
@ -286,10 +284,8 @@ void ChatForm::startFileSend(ToxFile file)
|
||||||
previousId = self;
|
previousId = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
insertChatMessage(ChatMessage::createFileTransferMessage(name,
|
insertChatMessage(
|
||||||
file,
|
ChatMessage::createFileTransferMessage(name, file, true, QDateTime::currentDateTime()));
|
||||||
true,
|
|
||||||
QDateTime::currentDateTime()));
|
|
||||||
Widget::getInstance()->updateFriendActivity(f);
|
Widget::getInstance()->updateFriendActivity(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,10 +303,8 @@ void ChatForm::onFileRecvRequest(ToxFile file)
|
||||||
previousId = friendId;
|
previousId = friendId;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatMessage::Ptr msg = ChatMessage::createFileTransferMessage(name,
|
ChatMessage::Ptr msg =
|
||||||
file,
|
ChatMessage::createFileTransferMessage(name, file, false, QDateTime::currentDateTime());
|
||||||
false,
|
|
||||||
QDateTime::currentDateTime());
|
|
||||||
insertChatMessage(msg);
|
insertChatMessage(msg);
|
||||||
|
|
||||||
ChatLineContentProxy* proxy = static_cast<ChatLineContentProxy*>(msg->getContent(1));
|
ChatLineContentProxy* proxy = static_cast<ChatLineContentProxy*>(msg->getContent(1));
|
||||||
|
@ -322,7 +316,7 @@ void ChatForm::onFileRecvRequest(ToxFile file)
|
||||||
// there is auto-accept for that contact
|
// there is auto-accept for that contact
|
||||||
if (!autoAcceptDir.isEmpty()) {
|
if (!autoAcceptDir.isEmpty()) {
|
||||||
tfWidget->autoAcceptTransfer(autoAcceptDir);
|
tfWidget->autoAcceptTransfer(autoAcceptDir);
|
||||||
// global autosave to global directory
|
// global autosave to global directory
|
||||||
} else if (settings.getAutoSaveEnabled()) {
|
} else if (settings.getAutoSaveEnabled()) {
|
||||||
tfWidget->autoAcceptTransfer(settings.getGlobalAutoAcceptDir());
|
tfWidget->autoAcceptTransfer(settings.getGlobalAutoAcceptDir());
|
||||||
}
|
}
|
||||||
|
@ -348,9 +342,7 @@ void ChatForm::onAvInvite(uint32_t friendId, bool video)
|
||||||
uint32_t friendId = f->getFriendId();
|
uint32_t friendId = f->getFriendId();
|
||||||
qDebug() << "automatic call answer";
|
qDebug() << "automatic call answer";
|
||||||
CoreAV* coreav = Core::getInstance()->getAv();
|
CoreAV* coreav = Core::getInstance()->getAv();
|
||||||
QMetaObject::invokeMethod(coreav,
|
QMetaObject::invokeMethod(coreav, "answerCall", Qt::QueuedConnection,
|
||||||
"answerCall",
|
|
||||||
Qt::QueuedConnection,
|
|
||||||
Q_ARG(uint32_t, friendId));
|
Q_ARG(uint32_t, friendId));
|
||||||
onAvStart(friendId, video);
|
onAvStart(friendId, video);
|
||||||
} else {
|
} else {
|
||||||
|
@ -359,8 +351,7 @@ void ChatForm::onAvInvite(uint32_t friendId, bool video)
|
||||||
connect(confirmData, &CallConfirmWidget::accepted, this, &ChatForm::onAnswerCallTriggered);
|
connect(confirmData, &CallConfirmWidget::accepted, this, &ChatForm::onAnswerCallTriggered);
|
||||||
connect(confirmData, &CallConfirmWidget::rejected, this, &ChatForm::onRejectCallTriggered);
|
connect(confirmData, &CallConfirmWidget::rejected, this, &ChatForm::onRejectCallTriggered);
|
||||||
auto msg = ChatMessage::createChatInfoMessage(tr("%1 calling").arg(displayedName),
|
auto msg = ChatMessage::createChatInfoMessage(tr("%1 calling").arg(displayedName),
|
||||||
ChatMessage::INFO,
|
ChatMessage::INFO, QDateTime::currentDateTime());
|
||||||
QDateTime::currentDateTime());
|
|
||||||
insertChatMessage(msg);
|
insertChatMessage(msg);
|
||||||
Widget::getInstance()->newFriendMessageAlert(friendId, false);
|
Widget::getInstance()->newFriendMessageAlert(friendId, false);
|
||||||
Audio& audio = Audio::getInstance();
|
Audio& audio = Audio::getInstance();
|
||||||
|
@ -410,8 +401,7 @@ void ChatForm::showOutgoingCall(bool video)
|
||||||
btn->setObjectName("yellow");
|
btn->setObjectName("yellow");
|
||||||
btn->setStyleSheet(Style::getStylesheet(video ? VIDEO_BTN_STYLESHEET : CALL_BTN_STYLESHEET));
|
btn->setStyleSheet(Style::getStylesheet(video ? VIDEO_BTN_STYLESHEET : CALL_BTN_STYLESHEET));
|
||||||
btn->setToolTip(video ? tr("Cancel video call") : tr("Cancel audio call"));
|
btn->setToolTip(video ? tr("Cancel video call") : tr("Cancel audio call"));
|
||||||
addSystemInfoMessage(tr("Calling %1").arg(f->getDisplayedName()),
|
addSystemInfoMessage(tr("Calling %1").arg(f->getDisplayedName()), ChatMessage::INFO,
|
||||||
ChatMessage::INFO,
|
|
||||||
QDateTime::currentDateTime());
|
QDateTime::currentDateTime());
|
||||||
Widget::getInstance()->updateFriendActivity(f);
|
Widget::getInstance()->updateFriendActivity(f);
|
||||||
}
|
}
|
||||||
|
@ -519,8 +509,7 @@ void ChatForm::onFileSendFailed(uint32_t friendId, const QString& fname)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addSystemInfoMessage(tr("Failed to send file \"%1\"").arg(fname),
|
addSystemInfoMessage(tr("Failed to send file \"%1\"").arg(fname), ChatMessage::ERROR,
|
||||||
ChatMessage::ERROR,
|
|
||||||
QDateTime::currentDateTime());
|
QDateTime::currentDateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,8 +534,7 @@ void ChatForm::onFriendStatusChanged(uint32_t friendId, Status status)
|
||||||
addSystemInfoMessage(tr("%1 is now %2", "e.g. \"Dubslow is now online\"")
|
addSystemInfoMessage(tr("%1 is now %2", "e.g. \"Dubslow is now online\"")
|
||||||
.arg(f->getDisplayedName())
|
.arg(f->getDisplayedName())
|
||||||
.arg(fStatus),
|
.arg(fStatus),
|
||||||
ChatMessage::INFO,
|
ChatMessage::INFO, QDateTime::currentDateTime());
|
||||||
QDateTime::currentDateTime());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -637,8 +625,7 @@ void ChatForm::dropEvent(QDropEvent* ev)
|
||||||
info.setFile(url.toLocalFile());
|
info.setFile(url.toLocalFile());
|
||||||
file.setFileName(info.absoluteFilePath());
|
file.setFileName(info.absoluteFilePath());
|
||||||
if (!file.exists() || !file.open(QIODevice::ReadOnly)) {
|
if (!file.exists() || !file.open(QIODevice::ReadOnly)) {
|
||||||
QMessageBox::warning(this,
|
QMessageBox::warning(this, tr("Unable to open"),
|
||||||
tr("Unable to open"),
|
|
||||||
tr("qTox wasn't able to open %1").arg(fileName));
|
tr("qTox wasn't able to open %1").arg(fileName));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -646,10 +633,8 @@ void ChatForm::dropEvent(QDropEvent* ev)
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
if (file.isSequential()) {
|
if (file.isSequential()) {
|
||||||
QMessageBox::critical(0,
|
QMessageBox::critical(0, tr("Bad idea"), tr("You're trying to send a sequential file, "
|
||||||
tr("Bad idea"),
|
"which is not going to work!"));
|
||||||
tr("You're trying to send a sequential file, "
|
|
||||||
"which is not going to work!"));
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -905,8 +890,7 @@ void ChatForm::stopCounter()
|
||||||
}
|
}
|
||||||
QString dhms = secondsToDHMS(timeElapsed.elapsed() / 1000);
|
QString dhms = secondsToDHMS(timeElapsed.elapsed() / 1000);
|
||||||
QString name = f->getDisplayedName();
|
QString name = f->getDisplayedName();
|
||||||
addSystemInfoMessage(tr("Call with %1 ended. %2").arg(name, dhms),
|
addSystemInfoMessage(tr("Call with %1 ended. %2").arg(name, dhms), ChatMessage::INFO,
|
||||||
ChatMessage::INFO,
|
|
||||||
QDateTime::currentDateTime());
|
QDateTime::currentDateTime());
|
||||||
callDurationTimer->stop();
|
callDurationTimer->stop();
|
||||||
callDuration->setText("");
|
callDuration->setText("");
|
||||||
|
@ -972,7 +956,7 @@ void ChatForm::SendMessageStr(QString msg)
|
||||||
msg.remove(0, ACTION_PREFIX.length());
|
msg.remove(0, ACTION_PREFIX.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QString> splittedMsg = Core::splitMessage(msg, TOX_MAX_MESSAGE_LENGTH);
|
QStringList splittedMsg = Core::splitMessage(msg, TOX_MAX_MESSAGE_LENGTH);
|
||||||
QDateTime timestamp = QDateTime::currentDateTime();
|
QDateTime timestamp = QDateTime::currentDateTime();
|
||||||
|
|
||||||
for (const QString& part : splittedMsg) {
|
for (const QString& part : splittedMsg) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user