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

refactor: cleanup notifications and core

This commit is contained in:
sudden6 2018-01-08 18:04:35 +01:00
parent d01999814e
commit 09ad16bc44
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
6 changed files with 35 additions and 48 deletions

View File

@ -234,26 +234,6 @@ void Core::makeTox(QByteArray savedata)
}
}
/**
* @brief Creates CoreAv instance. Should be called after makeTox method
*/
void Core::makeAv()
{
if (!tox) {
qCritical() << "No Tox instance, can't create ToxAV";
return;
}
av = new CoreAV(tox);
if (!av->getToxAv()) {
qCritical() << "Toxav core failed to start";
emit failedToStart();
}
for (const auto& callback : toCallWhenAvReady) {
callback(av);
}
toCallWhenAvReady.clear();
}
/**
* @brief Initializes the core, must be called before anything else
*/
@ -263,7 +243,6 @@ void Core::start(const QByteArray& savedata)
if (isNewProfile) {
qDebug() << "Creating a new profile";
makeTox(QByteArray());
makeAv();
setStatusMessage(tr("Toxing on qTox"));
setUsername(profile.getName());
} else {
@ -274,7 +253,6 @@ void Core::start(const QByteArray& savedata)
}
makeTox(savedata);
makeAv();
}
qsrand(time(nullptr));
@ -284,6 +262,15 @@ void Core::start(const QByteArray& savedata)
return;
}
// toxcore is successfully created, create toxav
av = new CoreAV(tox);
if (!av->getToxAv()) {
qCritical() << "Toxav failed to start";
emit failedToStart();
deadifyTox();
return;
}
// set GUI with user and statusmsg
QString name = getUsername();
if (!name.isEmpty()) {
@ -332,6 +319,7 @@ void Core::start(const QByteArray& savedata)
process(); // starts its own timer
av->start();
emit avReady();
}
/* Using the now commented out statements in checkConnection(), I watched how
@ -1385,11 +1373,6 @@ bool Core::isReady() const
return av && av->getToxAv() && tox && ready;
}
void Core::callWhenAvReady(std::function<void(CoreAV* av)>&& toCall)
{
toCallWhenAvReady.emplace_back(std::move(toCall));
}
/**
* @brief Sets the NoSpam value to prevent friend request spam
* @param nospam an arbitrary which becomes part of the Tox ID

View File

@ -81,7 +81,6 @@ public:
QPair<QByteArray, QByteArray> getKeypair() const;
bool isReady() const;
void callWhenAvReady(std::function<void(CoreAV* av)>&& toCall);
void sendFile(uint32_t friendId, QString filename, QString filePath, long long filesize);
@ -170,6 +169,7 @@ signals:
void failedToStart();
void badProxy();
void avReady();
void fileSendStarted(ToxFile file);
void fileReceiveRequested(ToxFile file);
@ -235,7 +235,6 @@ private:
QMutex messageSendMutex;
bool ready;
const ICoreSettings* const s;
std::vector<std::function<void(CoreAV* av)>> toCallWhenAvReady;
static QThread* coreThread;

View File

@ -18,8 +18,6 @@
*/
#include "chatform.h"
#include "src/audio/audio.h"
#include "src/chatlog/chatlinecontentproxy.h"
#include "src/chatlog/chatlog.h"
#include "src/chatlog/chatmessage.h"
@ -53,6 +51,15 @@
#include <cassert>
/**
* @brief ChatForm::incomingNotification Notify that we are called by someone.
* @param friendId Friend that is calling us.
*
* @brief ChatForm::outgoingNotification Notify that we are calling someone.
*
* @brief stopNotification Tell others to stop notification of a call.
*/
static const int CHAT_WIDGET_MIN_HEIGHT = 50;
static const int DELIVER_OFFLINE_MESSAGES_DELAY = 250;
static const int SCREENSHOT_GRABBER_OPENING_DELAY = 500;
@ -368,7 +375,7 @@ void ChatForm::onAvStart(uint32_t friendId, bool video)
hideNetcam();
}
Audio::getInstance().stopLoop();
emit stopNotification();
updateCallButtons();
startCounter();
}
@ -385,6 +392,7 @@ void ChatForm::onAvEnd(uint32_t friendId, bool error)
netcam->showNormal();
}
emit stopNotification();
updateCallButtons();
stopCounter(error);
hideNetcam();
@ -403,6 +411,7 @@ void ChatForm::onAnswerCallTriggered(bool video)
{
headWidget->removeCallConfirm();
uint32_t friendId = f->getId();
emit stopNotification();
emit acceptCall(friendId);
updateCallButtons();

View File

@ -30,7 +30,6 @@
#include "src/widget/tool/screenshotgrabber.h"
class CallConfirmWidget;
class CoreAV;
class FileTransferInstance;
class Friend;
class History;
@ -57,8 +56,10 @@ public:
static const QString ACTION_PREFIX;
signals:
void incomingNotification(uint32_t friendId);
void outgoingNotification();
void stopNotification();
void rejectCall(uint32_t friendId);
void acceptCall(uint32_t friendId);

View File

@ -244,7 +244,6 @@ void Widget::init()
const Settings& s = Settings::getInstance();
core->callWhenAvReady([this](CoreAV* av){connect(av, &CoreAV::avEnd, this, &Widget::onCallEnd);});
connect(core, &Core::fileDownloadFinished, filesForm, &FilesForm::onFileDownloadComplete);
connect(core, &Core::fileUploadFinished, filesForm, &FilesForm::onFileUploadComplete);
connect(ui->addButton, &QPushButton::clicked, this, &Widget::onAddClicked);
@ -954,23 +953,20 @@ void Widget::outgoingNotification()
audio.playMono16Sound(Audio::getSound(Audio::Sound::OutgoingCall));
}
/**
* @brief Widget::onStopNotification Stop the notification sound.
*/
void Widget::onStopNotification()
{
Audio::getInstance().stopLoop();
}
void Widget::onRejectCall(uint32_t friendId)
{
Audio::getInstance().stopLoop();
CoreAV* av = Core::getInstance()->getAv();
av->cancelCall(friendId);
}
void Widget::onAcceptCall(uint32_t friendId)
{
Audio::getInstance().stopLoop();
}
void Widget::onCallEnd(uint32_t friendId)
{
Audio::getInstance().stopLoop();
}
void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
{
Settings& s = Settings::getInstance();
@ -1000,8 +996,8 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
connect(friendForm, &ChatForm::incomingNotification, this, &Widget::incomingNotification);
connect(friendForm, &ChatForm::outgoingNotification, this, &Widget::outgoingNotification);
connect(friendForm, &ChatForm::stopNotification, this, &Widget::onStopNotification);
connect(friendForm, &ChatForm::rejectCall, this, &Widget::onRejectCall);
connect(friendForm, &ChatForm::acceptCall, this, &Widget::onAcceptCall);
connect(widget, &FriendWidget::newWindowOpened, this, &Widget::openNewDialog);
connect(widget, &FriendWidget::chatroomWidgetClicked, this, &Widget::onChatroomWidgetClicked);

View File

@ -217,8 +217,7 @@ private slots:
void outgoingNotification();
void incomingNotification(uint32_t friendId);
void onRejectCall(uint32_t friendId);
void onAcceptCall(uint32_t friendId);
void onCallEnd(uint32_t friendId);
void onStopNotification();
private:
// QMainWindow overrides