diff --git a/src/core.cpp b/src/core.cpp index 614184242..325028b03 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -1184,7 +1184,7 @@ void Core::saveConfiguration(const QString& path) } } -void Core::switchConfiguration(QString profile) +void Core::switchConfiguration(const QString& profile) { if (profile.isEmpty()) { @@ -1204,7 +1204,7 @@ void Core::switchConfiguration(QString profile) tox = nullptr; } emit selfAvatarChanged(QPixmap(":/img/contact_dark.png")); - Widget::getInstance()->clearContactsList(); // we need this to block, so no signals for us + emit blockingClearContacts(); // we need this to block, but signals are required for thread safety loadPath = QDir(Settings::getSettingsDirPath()).filePath(profile + TOX_EXT); Settings::getInstance().setCurrentProfile(profile); diff --git a/src/core.h b/src/core.h index 2b6a7d8ca..189f4060a 100644 --- a/src/core.h +++ b/src/core.h @@ -53,7 +53,6 @@ public: void saveConfiguration(); void saveConfiguration(const QString& path); - void switchConfiguration(QString profile); QString getIDString(); @@ -70,6 +69,7 @@ public slots: void start(); void process(); void bootstrapDht(); + void switchConfiguration(const QString& profile); void acceptFriendRequest(const QString& userId); void requestFriendship(const QString& friendAddress, const QString& message); @@ -107,6 +107,7 @@ public slots: signals: void connected(); void disconnected(); + void blockingClearContacts(); void friendRequestReceived(const QString& userId, const QString& message); void friendMessageReceived(int friendId, const QString& message, bool isAction); diff --git a/src/widget/form/settings/identityform.cpp b/src/widget/form/settings/identityform.cpp index 7e85c2d05..d61a9fb18 100644 --- a/src/widget/form/settings/identityform.cpp +++ b/src/widget/form/settings/identityform.cpp @@ -114,7 +114,8 @@ void IdentityForm::onLoadClicked() QMessageBox::warning(this, tr("Call active", "popup title"), tr("You can't switch profiles while a call is active!", "popup text")); else - Core::getInstance()->switchConfiguration(bodyUI->profiles->currentText()); + emit Widget::getInstance()->changeProfile(bodyUI->profiles->currentText()); + // I think by directly calling the function, I may have been causing thread issues } } diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 156aad12e..7a9146e47 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -146,6 +146,7 @@ Widget::Widget(QWidget *parent) connect(core, &Core::groupNamelistChanged, this, &Widget::onGroupNamelistChanged); connect(core, &Core::emptyGroupCreated, this, &Widget::onEmptyGroupCreated); connect(core, &Core::avInvite, this, &Widget::playRingtone); + connect(core, &Core::blockingClearContacts, this, &Widget::clearContactsList, Qt::BlockingQueuedConnection); connect(core, SIGNAL(messageSentResult(int,QString,int)), this, SLOT(onMessageSendResult(int,QString,int))); connect(core, SIGNAL(groupSentResult(int,QString,int)), this, SLOT(onGroupSendResult(int,QString,int))); @@ -153,6 +154,7 @@ Widget::Widget(QWidget *parent) connect(this, &Widget::statusSet, core, &Core::setStatus); connect(this, &Widget::friendRequested, core, &Core::requestFriendship); connect(this, &Widget::friendRequestAccepted, core, &Core::acceptFriendRequest); + connect(this, &Widget::changeProfile, core, &Core::switchConfiguration); connect(ui->addButton, SIGNAL(clicked()), this, SLOT(onAddClicked())); connect(ui->groupButton, SIGNAL(clicked()), this, SLOT(onGroupClicked())); diff --git a/src/widget/widget.h b/src/widget/widget.h index 923d077df..572ba1922 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -69,6 +69,7 @@ signals: void statusSelected(Status status); void usernameChanged(const QString& username); void statusMessageChanged(const QString& statusMessage); + void changeProfile(const QString& profile); private slots: void onConnected();