mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #5721
jenli669 (1): fix(core): correctly relink ui/core when core is changed
This commit is contained in:
commit
17083b50ba
|
@ -237,40 +237,12 @@ void Nexus::showMainGUI()
|
|||
// Connections
|
||||
connect(profile, &Profile::selfAvatarChanged, widget, &Widget::onSelfAvatarLoaded);
|
||||
|
||||
Core* core = profile->getCore();
|
||||
connect(core, &Core::requestSent, profile, &Profile::onRequestSent);
|
||||
connect(profile, &Profile::coreChanged, widget, &Widget::onCoreChanged);
|
||||
|
||||
connect(core, &Core::connected, widget, &Widget::onConnected);
|
||||
connect(core, &Core::disconnected, widget, &Widget::onDisconnected);
|
||||
connect(profile, &Profile::failedToStart, widget, &Widget::onFailedToStartCore,
|
||||
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(widget, &Widget::friendRequested, core, &Core::requestFriendship);
|
||||
connect(widget, &Widget::friendRequestAccepted, core, &Core::acceptFriendRequest);
|
||||
connect(profile, &Profile::badProxy, widget, &Widget::onBadProxyCore, Qt::BlockingQueuedConnection);
|
||||
|
||||
profile->startCore();
|
||||
|
||||
|
|
|
@ -299,6 +299,10 @@ QString Profile::getName() const
|
|||
*/
|
||||
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();
|
||||
|
||||
const ToxId& selfId = core->getSelfId();
|
||||
|
@ -799,6 +803,11 @@ void Profile::restartCore()
|
|||
assert(audioBak != nullptr);
|
||||
initCore(savedata, Settings::getInstance(), isNewProfile);
|
||||
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();
|
||||
} else {
|
||||
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
|
||||
void failedToStart();
|
||||
void badProxy();
|
||||
void coreChanged(Core& core);
|
||||
|
||||
public slots:
|
||||
void onRequestSent(const ToxPk& friendPk, const QString& message);
|
||||
|
|
|
@ -219,9 +219,9 @@ void Widget::init()
|
|||
filterDisplayActivity->setCheckable(true);
|
||||
filterDisplayGroup->addAction(filterDisplayActivity);
|
||||
filterMenu->addAction(filterDisplayActivity);
|
||||
settings.getFriendSortingMode() == FriendListWidget::SortingMode::Name ?
|
||||
filterDisplayName->setChecked(true) :
|
||||
filterDisplayActivity->setChecked(true);
|
||||
settings.getFriendSortingMode() == FriendListWidget::SortingMode::Name
|
||||
? filterDisplayName->setChecked(true)
|
||||
: filterDisplayActivity->setChecked(true);
|
||||
filterMenu->addSeparator();
|
||||
|
||||
filterAllAction = new QAction(this);
|
||||
|
@ -502,9 +502,9 @@ void Widget::updateIcons()
|
|||
return;
|
||||
}
|
||||
|
||||
const QString assetSuffix =
|
||||
Status::getAssetSuffix(static_cast<Status::Status>(ui->statusButton->property("status").toInt()))
|
||||
+ (eventIcon ? "_event" : "");
|
||||
const QString assetSuffix = Status::getAssetSuffix(static_cast<Status::Status>(
|
||||
ui->statusButton->property("status").toInt()))
|
||||
+ (eventIcon ? "_event" : "");
|
||||
|
||||
// Some builds of Qt appear to have a bug in icon loading:
|
||||
// QIcon::hasThemeIcon is sometimes unaware that the icon returned
|
||||
|
@ -675,6 +675,38 @@ void Widget::onSelfAvatarLoaded(const QPixmap& 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()
|
||||
{
|
||||
ui->statusButton->setEnabled(true);
|
||||
|
@ -1513,13 +1545,15 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString& text, b
|
|||
ui->friendList->trackWidget(widget);
|
||||
#if DESKTOP_NOTIFICATIONS
|
||||
if (settings.getNotifyHide()) {
|
||||
notifier.notifyMessageSimple(file ? DesktopNotify::MessageType::FRIEND_FILE : DesktopNotify::MessageType::FRIEND);
|
||||
notifier.notifyMessageSimple(file ? DesktopNotify::MessageType::FRIEND_FILE
|
||||
: DesktopNotify::MessageType::FRIEND);
|
||||
} else {
|
||||
QString title = f->getDisplayedName();
|
||||
if (file) {
|
||||
title += " - " + tr("File sent");
|
||||
}
|
||||
notifier.notifyMessagePixmap(title, text, Nexus::getProfile()->loadAvatar(f->getPublicKey()));
|
||||
notifier.notifyMessagePixmap(title, text,
|
||||
Nexus::getProfile()->loadAvatar(f->getPublicKey()));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1537,7 +1571,8 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString& text, b
|
|||
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;
|
||||
QWidget* currentWindow;
|
||||
|
@ -1563,12 +1598,13 @@ bool Widget::newGroupMessageAlert(const GroupId& groupId, const ToxPk& authorPk,
|
|||
if (settings.getNotifyHide()) {
|
||||
notifier.notifyMessageSimple(DesktopNotify::MessageType::GROUP);
|
||||
} else {
|
||||
Friend *f = FriendList::findFriend(authorPk);
|
||||
Friend* f = FriendList::findFriend(authorPk);
|
||||
QString title = g->getPeerList().value(authorPk) + " (" + g->getDisplayedName() + ")";
|
||||
if (!f) {
|
||||
notifier.notifyMessage(title, message);
|
||||
} else {
|
||||
notifier.notifyMessagePixmap(title, message, Nexus::getProfile()->loadAvatar(f->getPublicKey()));
|
||||
notifier.notifyMessagePixmap(title, message,
|
||||
Nexus::getProfile()->loadAvatar(f->getPublicKey()));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -1903,7 +1939,8 @@ void Widget::onGroupInviteReceived(const GroupInvite& inviteInfo)
|
|||
if (settings.getNotifyHide()) {
|
||||
notifier.notifyMessageSimple(DesktopNotify::MessageType::GROUP_INVITE);
|
||||
} 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
|
||||
}
|
||||
|
|
|
@ -127,8 +127,10 @@ public:
|
|||
void showUpdateDownloadProgress();
|
||||
void addFriendDialog(const Friend* frnd, ContentDialog* dialog);
|
||||
void addGroupDialog(Group* group, ContentDialog* dialog);
|
||||
bool newFriendMessageAlert(const ToxPk& friendId, const QString& text, bool sound = true, bool file = false);
|
||||
bool newGroupMessageAlert(const GroupId& groupId, const ToxPk& authorPk, const QString& message, bool notify);
|
||||
bool newFriendMessageAlert(const ToxPk& friendId, const QString& text, bool sound = true,
|
||||
bool file = false);
|
||||
bool newGroupMessageAlert(const GroupId& groupId, const ToxPk& authorPk, const QString& message,
|
||||
bool notify);
|
||||
bool getIsWindowMinimized();
|
||||
void updateIcons();
|
||||
|
||||
|
@ -193,6 +195,7 @@ public slots:
|
|||
void toggleFullscreen();
|
||||
void refreshPeerListsLocal(const QString& username);
|
||||
void onUpdateAvailable(QString latestVersion, QUrl link);
|
||||
void onCoreChanged(Core& core);
|
||||
|
||||
signals:
|
||||
void friendRequestAccepted(const ToxPk& friendPk);
|
||||
|
|
Loading…
Reference in New Issue
Block a user