mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix(core): correctly relink ui/core when core is changed
Widget was only connecting the Core to itself during initialization, but the Core instance could change during a restartCore call. This commit will make Widget link the Core to itself when it changes rather than only on initialization. Fixes #5710
This commit is contained in:
parent
a5754ab0bb
commit
17d5d55259
|
@ -237,40 +237,12 @@ void Nexus::showMainGUI()
|
||||||
// Connections
|
// Connections
|
||||||
connect(profile, &Profile::selfAvatarChanged, widget, &Widget::onSelfAvatarLoaded);
|
connect(profile, &Profile::selfAvatarChanged, widget, &Widget::onSelfAvatarLoaded);
|
||||||
|
|
||||||
Core* core = profile->getCore();
|
connect(profile, &Profile::coreChanged, widget, &Widget::onCoreChanged);
|
||||||
connect(core, &Core::requestSent, profile, &Profile::onRequestSent);
|
|
||||||
|
|
||||||
connect(core, &Core::connected, widget, &Widget::onConnected);
|
|
||||||
connect(core, &Core::disconnected, widget, &Widget::onDisconnected);
|
|
||||||
connect(profile, &Profile::failedToStart, widget, &Widget::onFailedToStartCore,
|
connect(profile, &Profile::failedToStart, widget, &Widget::onFailedToStartCore,
|
||||||
Qt::BlockingQueuedConnection);
|
Qt::BlockingQueuedConnection);
|
||||||
connect(profile, &Profile::badProxy, widget, &Widget::onBadProxyCore, Qt::BlockingQueuedConnection);
|
|
||||||
connect(core, &Core::statusSet, widget, &Widget::onStatusSet);
|
|
||||||
connect(core, &Core::usernameSet, widget, &Widget::setUsername);
|
|
||||||
connect(core, &Core::statusMessageSet, widget, &Widget::setStatusMessage);
|
|
||||||
connect(core, &Core::friendAdded, widget, &Widget::addFriend);
|
|
||||||
connect(core, &Core::failedToAddFriend, widget, &Widget::addFriendFailed);
|
|
||||||
connect(core, &Core::friendUsernameChanged, widget, &Widget::onFriendUsernameChanged);
|
|
||||||
connect(core, &Core::friendStatusChanged, widget, &Widget::onFriendStatusChanged);
|
|
||||||
connect(core, &Core::friendStatusMessageChanged, widget, &Widget::onFriendStatusMessageChanged);
|
|
||||||
connect(core, &Core::friendRequestReceived, widget, &Widget::onFriendRequestReceived);
|
|
||||||
connect(core, &Core::friendMessageReceived, widget, &Widget::onFriendMessageReceived);
|
|
||||||
connect(core, &Core::receiptRecieved, widget, &Widget::onReceiptReceived);
|
|
||||||
connect(core, &Core::groupInviteReceived, widget, &Widget::onGroupInviteReceived);
|
|
||||||
connect(core, &Core::groupMessageReceived, widget, &Widget::onGroupMessageReceived);
|
|
||||||
connect(core, &Core::groupPeerlistChanged, widget, &Widget::onGroupPeerlistChanged);
|
|
||||||
connect(core, &Core::groupPeerNameChanged, widget, &Widget::onGroupPeerNameChanged);
|
|
||||||
connect(core, &Core::groupTitleChanged, widget, &Widget::onGroupTitleChanged);
|
|
||||||
connect(core, &Core::groupPeerAudioPlaying, widget, &Widget::onGroupPeerAudioPlaying);
|
|
||||||
connect(core, &Core::emptyGroupCreated, widget, &Widget::onEmptyGroupCreated);
|
|
||||||
connect(core, &Core::groupJoined, widget, &Widget::onGroupJoined);
|
|
||||||
connect(core, &Core::friendTypingChanged, widget, &Widget::onFriendTypingChanged);
|
|
||||||
connect(core, &Core::groupSentFailed, widget, &Widget::onGroupSendFailed);
|
|
||||||
connect(core, &Core::usernameSet, widget, &Widget::refreshPeerListsLocal);
|
|
||||||
|
|
||||||
connect(widget, &Widget::statusSet, core, &Core::setStatus);
|
connect(profile, &Profile::badProxy, widget, &Widget::onBadProxyCore, Qt::BlockingQueuedConnection);
|
||||||
connect(widget, &Widget::friendRequested, core, &Core::requestFriendship);
|
|
||||||
connect(widget, &Widget::friendRequestAccepted, core, &Core::acceptFriendRequest);
|
|
||||||
|
|
||||||
profile->startCore();
|
profile->startCore();
|
||||||
|
|
||||||
|
|
|
@ -299,6 +299,10 @@ QString Profile::getName() const
|
||||||
*/
|
*/
|
||||||
void Profile::startCore()
|
void Profile::startCore()
|
||||||
{
|
{
|
||||||
|
// kriby: code duplication belongs in initCore, but cannot yet due to Core/Profile coupling
|
||||||
|
connect(core.get(), &Core::requestSent, this, &Profile::onRequestSent);
|
||||||
|
emit coreChanged(*core);
|
||||||
|
|
||||||
core->start();
|
core->start();
|
||||||
|
|
||||||
const ToxId& selfId = core->getSelfId();
|
const ToxId& selfId = core->getSelfId();
|
||||||
|
@ -799,6 +803,11 @@ void Profile::restartCore()
|
||||||
assert(audioBak != nullptr);
|
assert(audioBak != nullptr);
|
||||||
initCore(savedata, Settings::getInstance(), isNewProfile);
|
initCore(savedata, Settings::getInstance(), isNewProfile);
|
||||||
core->getAv()->setAudio(*audioBak);
|
core->getAv()->setAudio(*audioBak);
|
||||||
|
|
||||||
|
// kriby: code duplication belongs in initCore, but cannot yet due to Core/Profile coupling
|
||||||
|
connect(core.get(), &Core::requestSent, this, &Profile::onRequestSent);
|
||||||
|
emit coreChanged(*core);
|
||||||
|
|
||||||
core->start();
|
core->start();
|
||||||
} else {
|
} else {
|
||||||
qCritical() << "Failed to save, not restarting core";
|
qCritical() << "Failed to save, not restarting core";
|
||||||
|
|
|
@ -84,6 +84,7 @@ signals:
|
||||||
// TODO(sudden6): this doesn't seem to be the right place for Core errors
|
// TODO(sudden6): this doesn't seem to be the right place for Core errors
|
||||||
void failedToStart();
|
void failedToStart();
|
||||||
void badProxy();
|
void badProxy();
|
||||||
|
void coreChanged(Core& core);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onRequestSent(const ToxPk& friendPk, const QString& message);
|
void onRequestSent(const ToxPk& friendPk, const QString& message);
|
||||||
|
|
|
@ -219,9 +219,9 @@ void Widget::init()
|
||||||
filterDisplayActivity->setCheckable(true);
|
filterDisplayActivity->setCheckable(true);
|
||||||
filterDisplayGroup->addAction(filterDisplayActivity);
|
filterDisplayGroup->addAction(filterDisplayActivity);
|
||||||
filterMenu->addAction(filterDisplayActivity);
|
filterMenu->addAction(filterDisplayActivity);
|
||||||
settings.getFriendSortingMode() == FriendListWidget::SortingMode::Name ?
|
settings.getFriendSortingMode() == FriendListWidget::SortingMode::Name
|
||||||
filterDisplayName->setChecked(true) :
|
? filterDisplayName->setChecked(true)
|
||||||
filterDisplayActivity->setChecked(true);
|
: filterDisplayActivity->setChecked(true);
|
||||||
filterMenu->addSeparator();
|
filterMenu->addSeparator();
|
||||||
|
|
||||||
filterAllAction = new QAction(this);
|
filterAllAction = new QAction(this);
|
||||||
|
@ -502,9 +502,9 @@ void Widget::updateIcons()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString assetSuffix =
|
const QString assetSuffix = Status::getAssetSuffix(static_cast<Status::Status>(
|
||||||
Status::getAssetSuffix(static_cast<Status::Status>(ui->statusButton->property("status").toInt()))
|
ui->statusButton->property("status").toInt()))
|
||||||
+ (eventIcon ? "_event" : "");
|
+ (eventIcon ? "_event" : "");
|
||||||
|
|
||||||
// Some builds of Qt appear to have a bug in icon loading:
|
// Some builds of Qt appear to have a bug in icon loading:
|
||||||
// QIcon::hasThemeIcon is sometimes unaware that the icon returned
|
// QIcon::hasThemeIcon is sometimes unaware that the icon returned
|
||||||
|
@ -675,6 +675,38 @@ void Widget::onSelfAvatarLoaded(const QPixmap& pic)
|
||||||
profilePicture->setPixmap(pic);
|
profilePicture->setPixmap(pic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Widget::onCoreChanged(Core& core)
|
||||||
|
{
|
||||||
|
|
||||||
|
connect(&core, &Core::connected, this, &Widget::onConnected);
|
||||||
|
connect(&core, &Core::disconnected, this, &Widget::onDisconnected);
|
||||||
|
connect(&core, &Core::statusSet, this, &Widget::onStatusSet);
|
||||||
|
connect(&core, &Core::usernameSet, this, &Widget::setUsername);
|
||||||
|
connect(&core, &Core::statusMessageSet, this, &Widget::setStatusMessage);
|
||||||
|
connect(&core, &Core::friendAdded, this, &Widget::addFriend);
|
||||||
|
connect(&core, &Core::failedToAddFriend, this, &Widget::addFriendFailed);
|
||||||
|
connect(&core, &Core::friendUsernameChanged, this, &Widget::onFriendUsernameChanged);
|
||||||
|
connect(&core, &Core::friendStatusChanged, this, &Widget::onFriendStatusChanged);
|
||||||
|
connect(&core, &Core::friendStatusMessageChanged, this, &Widget::onFriendStatusMessageChanged);
|
||||||
|
connect(&core, &Core::friendRequestReceived, this, &Widget::onFriendRequestReceived);
|
||||||
|
connect(&core, &Core::friendMessageReceived, this, &Widget::onFriendMessageReceived);
|
||||||
|
connect(&core, &Core::receiptRecieved, this, &Widget::onReceiptReceived);
|
||||||
|
connect(&core, &Core::groupInviteReceived, this, &Widget::onGroupInviteReceived);
|
||||||
|
connect(&core, &Core::groupMessageReceived, this, &Widget::onGroupMessageReceived);
|
||||||
|
connect(&core, &Core::groupPeerlistChanged, this, &Widget::onGroupPeerlistChanged);
|
||||||
|
connect(&core, &Core::groupPeerNameChanged, this, &Widget::onGroupPeerNameChanged);
|
||||||
|
connect(&core, &Core::groupTitleChanged, this, &Widget::onGroupTitleChanged);
|
||||||
|
connect(&core, &Core::groupPeerAudioPlaying, this, &Widget::onGroupPeerAudioPlaying);
|
||||||
|
connect(&core, &Core::emptyGroupCreated, this, &Widget::onEmptyGroupCreated);
|
||||||
|
connect(&core, &Core::groupJoined, this, &Widget::onGroupJoined);
|
||||||
|
connect(&core, &Core::friendTypingChanged, this, &Widget::onFriendTypingChanged);
|
||||||
|
connect(&core, &Core::groupSentFailed, this, &Widget::onGroupSendFailed);
|
||||||
|
connect(&core, &Core::usernameSet, this, &Widget::refreshPeerListsLocal);
|
||||||
|
connect(this, &Widget::statusSet, &core, &Core::setStatus);
|
||||||
|
connect(this, &Widget::friendRequested, &core, &Core::requestFriendship);
|
||||||
|
connect(this, &Widget::friendRequestAccepted, &core, &Core::acceptFriendRequest);
|
||||||
|
}
|
||||||
|
|
||||||
void Widget::onConnected()
|
void Widget::onConnected()
|
||||||
{
|
{
|
||||||
ui->statusButton->setEnabled(true);
|
ui->statusButton->setEnabled(true);
|
||||||
|
@ -1513,13 +1545,15 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString& text, b
|
||||||
ui->friendList->trackWidget(widget);
|
ui->friendList->trackWidget(widget);
|
||||||
#if DESKTOP_NOTIFICATIONS
|
#if DESKTOP_NOTIFICATIONS
|
||||||
if (settings.getNotifyHide()) {
|
if (settings.getNotifyHide()) {
|
||||||
notifier.notifyMessageSimple(file ? DesktopNotify::MessageType::FRIEND_FILE : DesktopNotify::MessageType::FRIEND);
|
notifier.notifyMessageSimple(file ? DesktopNotify::MessageType::FRIEND_FILE
|
||||||
|
: DesktopNotify::MessageType::FRIEND);
|
||||||
} else {
|
} else {
|
||||||
QString title = f->getDisplayedName();
|
QString title = f->getDisplayedName();
|
||||||
if (file) {
|
if (file) {
|
||||||
title += " - " + tr("File sent");
|
title += " - " + tr("File sent");
|
||||||
}
|
}
|
||||||
notifier.notifyMessagePixmap(title, text, Nexus::getProfile()->loadAvatar(f->getPublicKey()));
|
notifier.notifyMessagePixmap(title, text,
|
||||||
|
Nexus::getProfile()->loadAvatar(f->getPublicKey()));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1537,7 +1571,8 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString& text, b
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Widget::newGroupMessageAlert(const GroupId& groupId, const ToxPk& authorPk, const QString& message, bool notify)
|
bool Widget::newGroupMessageAlert(const GroupId& groupId, const ToxPk& authorPk,
|
||||||
|
const QString& message, bool notify)
|
||||||
{
|
{
|
||||||
bool hasActive;
|
bool hasActive;
|
||||||
QWidget* currentWindow;
|
QWidget* currentWindow;
|
||||||
|
@ -1563,12 +1598,13 @@ bool Widget::newGroupMessageAlert(const GroupId& groupId, const ToxPk& authorPk,
|
||||||
if (settings.getNotifyHide()) {
|
if (settings.getNotifyHide()) {
|
||||||
notifier.notifyMessageSimple(DesktopNotify::MessageType::GROUP);
|
notifier.notifyMessageSimple(DesktopNotify::MessageType::GROUP);
|
||||||
} else {
|
} else {
|
||||||
Friend *f = FriendList::findFriend(authorPk);
|
Friend* f = FriendList::findFriend(authorPk);
|
||||||
QString title = g->getPeerList().value(authorPk) + " (" + g->getDisplayedName() + ")";
|
QString title = g->getPeerList().value(authorPk) + " (" + g->getDisplayedName() + ")";
|
||||||
if (!f) {
|
if (!f) {
|
||||||
notifier.notifyMessage(title, message);
|
notifier.notifyMessage(title, message);
|
||||||
} else {
|
} else {
|
||||||
notifier.notifyMessagePixmap(title, message, Nexus::getProfile()->loadAvatar(f->getPublicKey()));
|
notifier.notifyMessagePixmap(title, message,
|
||||||
|
Nexus::getProfile()->loadAvatar(f->getPublicKey()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1903,7 +1939,8 @@ void Widget::onGroupInviteReceived(const GroupInvite& inviteInfo)
|
||||||
if (settings.getNotifyHide()) {
|
if (settings.getNotifyHide()) {
|
||||||
notifier.notifyMessageSimple(DesktopNotify::MessageType::GROUP_INVITE);
|
notifier.notifyMessageSimple(DesktopNotify::MessageType::GROUP_INVITE);
|
||||||
} else {
|
} else {
|
||||||
notifier.notifyMessagePixmap(f->getDisplayedName() + tr(" invites you to join a group."), {}, Nexus::getProfile()->loadAvatar(f->getPublicKey()));
|
notifier.notifyMessagePixmap(f->getDisplayedName() + tr(" invites you to join a group."),
|
||||||
|
{}, Nexus::getProfile()->loadAvatar(f->getPublicKey()));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,8 +127,10 @@ public:
|
||||||
void showUpdateDownloadProgress();
|
void showUpdateDownloadProgress();
|
||||||
void addFriendDialog(const Friend* frnd, ContentDialog* dialog);
|
void addFriendDialog(const Friend* frnd, ContentDialog* dialog);
|
||||||
void addGroupDialog(Group* group, ContentDialog* dialog);
|
void addGroupDialog(Group* group, ContentDialog* dialog);
|
||||||
bool newFriendMessageAlert(const ToxPk& friendId, const QString& text, bool sound = true, bool file = false);
|
bool newFriendMessageAlert(const ToxPk& friendId, const QString& text, bool sound = true,
|
||||||
bool newGroupMessageAlert(const GroupId& groupId, const ToxPk& authorPk, const QString& message, bool notify);
|
bool file = false);
|
||||||
|
bool newGroupMessageAlert(const GroupId& groupId, const ToxPk& authorPk, const QString& message,
|
||||||
|
bool notify);
|
||||||
bool getIsWindowMinimized();
|
bool getIsWindowMinimized();
|
||||||
void updateIcons();
|
void updateIcons();
|
||||||
|
|
||||||
|
@ -193,6 +195,7 @@ public slots:
|
||||||
void toggleFullscreen();
|
void toggleFullscreen();
|
||||||
void refreshPeerListsLocal(const QString& username);
|
void refreshPeerListsLocal(const QString& username);
|
||||||
void onUpdateAvailable(QString latestVersion, QUrl link);
|
void onUpdateAvailable(QString latestVersion, QUrl link);
|
||||||
|
void onCoreChanged(Core& core);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void friendRequestAccepted(const ToxPk& friendPk);
|
void friendRequestAccepted(const ToxPk& friendPk);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user