diff --git a/qTox.desktop b/qTox.desktop index afd74b440..298a11771 100644 --- a/qTox.desktop +++ b/qTox.desktop @@ -9,4 +9,4 @@ Exec=qtox Icon=qtox Categories=InstantMessaging;;AudioVideo;Network; Terminal=false -MimeType=x-scheme-handler/tox; +MimeType=x-scheme-handler/tox;application/x-tox; diff --git a/src/core.cpp b/src/core.cpp index 27d0afc61..436c9d5c4 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -47,6 +47,8 @@ QList Core::fileRecvQueue; Core::Core(Camera* cam, QThread *coreThread, QString loadPath) : tox(nullptr), camera(cam), loadPath(loadPath) { + qDebug() << "Core: loading Tox from" << loadPath; + videobuf = new uint8_t[videobufsize]; videoBusyness=0; @@ -590,7 +592,7 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive uint64_t resumePos = *reinterpret_cast(data); - if (resumePos >= file->filesize) + if (resumePos >= (unsigned)file->filesize) { qWarning() << "Core::onFileControlCallback: invalid resume position"; tox_file_send_control(tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0); // don't sure about it @@ -1218,8 +1220,15 @@ void Core::saveConfiguration(const QString& path) } } -void Core::switchConfiguration(QString profile) +void Core::switchConfiguration(const QString& profile) { + if (profile.isEmpty()) + { + qWarning() << "Core: got null profile to switch to, not switching"; + return; + } + else + qDebug() << "Core: switching from" << Settings::getInstance().getCurrentProfile() << "to" << profile; saveConfiguration(); toxTimer->stop(); @@ -1231,7 +1240,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 2e928c9a4..7e8dc632e 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(); @@ -64,10 +63,13 @@ public: void increaseVideoBusyness(); void decreaseVideoBusyness(); + bool anyActiveCalls(); + 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); @@ -112,6 +114,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/coreav.cpp b/src/coreav.cpp index b7aae0103..516d08833 100644 --- a/src/coreav.cpp +++ b/src/coreav.cpp @@ -28,6 +28,14 @@ ALCdevice* Core::alOutDev, *Core::alInDev; ALCcontext* Core::alContext; ALuint Core::alMainSource; +bool Core::anyActiveCalls() +{ + for (auto& call : calls) + if (call.active) + return true; + return false; +} + void Core::prepareCall(int friendId, int callId, ToxAv* toxav, bool videoEnabled) { qDebug() << QString("Core: preparing call %1").arg(callId); diff --git a/src/widget/camera.cpp b/src/widget/camera.cpp index 5bf07e6df..b652d7033 100644 --- a/src/widget/camera.cpp +++ b/src/widget/camera.cpp @@ -34,7 +34,6 @@ Camera::Camera() connect(workerThread, &QThread::started, worker, &CameraWorker::onStart); connect(workerThread, &QThread::finished, worker, &CameraWorker::deleteLater); - connect(workerThread, &QThread::deleteLater, worker, &CameraWorker::deleteLater); connect(worker, &CameraWorker::started, this, &Camera::onWorkerStarted); connect(worker, &CameraWorker::newFrameAvailable, this, &Camera::onNewFrameAvailable); connect(worker, &CameraWorker::resProbingFinished, this, &Camera::onResProbingFinished); diff --git a/src/widget/form/settings/identityform.cpp b/src/widget/form/settings/identityform.cpp index c0853f958..d61a9fb18 100644 --- a/src/widget/form/settings/identityform.cpp +++ b/src/widget/form/settings/identityform.cpp @@ -108,7 +108,15 @@ void IdentityForm::setStatusMessage(const QString &msg) void IdentityForm::onLoadClicked() { - Core::getInstance()->switchConfiguration(bodyUI->profiles->currentText()); + if (bodyUI->profiles->currentText() != Settings::getInstance().getCurrentProfile()) + { + if (Core::getInstance()->anyActiveCalls()) + QMessageBox::warning(this, tr("Call active", "popup title"), + tr("You can't switch profiles while a call is active!", "popup text")); + else + emit Widget::getInstance()->changeProfile(bodyUI->profiles->currentText()); + // I think by directly calling the function, I may have been causing thread issues + } } void IdentityForm::onRenameClicked() @@ -132,7 +140,8 @@ void IdentityForm::onExportClicked() QString path = QFileDialog::getSaveFileName(this, tr("Export profile", "save dialog title"), QDir::home().filePath(current), tr("Tox save file (*.tox)", "save dialog filter")); - QFile::copy(QDir(Settings::getSettingsDirPath()).filePath(current), path); + if (!path.isEmpty()) + QFile::copy(QDir(Settings::getSettingsDirPath()).filePath(current), path); } void IdentityForm::onDeleteClicked() @@ -157,6 +166,8 @@ void IdentityForm::onDeleteClicked() void IdentityForm::onImportClicked() { QString path = QFileDialog::getOpenFileName(this, tr("Import profile", "import dialog title"), QDir::homePath(), tr("Tox save file (*.tox)", "import dialog filter")); + if (path.isEmpty()) + return; QFileInfo info(path); QString profile = info.completeBaseName(); QString profilePath = QDir(Settings::getSettingsDirPath()).filePath(profile + Core::TOX_EXT); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index b310627c0..18231d2ac 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();