From 68de3667385e44c864a857a48155a831dae5141e Mon Sep 17 00:00:00 2001 From: dubslow Date: Mon, 13 Oct 2014 16:17:42 -0500 Subject: [PATCH 1/6] fix #431, fix export cancels, and more debug prints --- src/core.cpp | 9 +++++++++ src/widget/form/settings/identityform.cpp | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/core.cpp b/src/core.cpp index efaa68e7f..824085de6 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -46,6 +46,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; @@ -1184,6 +1186,13 @@ void Core::saveConfiguration(const QString& path) void Core::switchConfiguration(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(); diff --git a/src/widget/form/settings/identityform.cpp b/src/widget/form/settings/identityform.cpp index c0853f958..1c16e6b8b 100644 --- a/src/widget/form/settings/identityform.cpp +++ b/src/widget/form/settings/identityform.cpp @@ -132,7 +132,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 +158,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); From cbf8d610c84aa2d963860dcaafab3b2f77c03348 Mon Sep 17 00:00:00 2001 From: krepa098 Date: Sat, 11 Oct 2014 20:23:31 +0200 Subject: [PATCH 2/6] fixed #425 --- src/widget/camera.cpp | 1 - 1 file changed, 1 deletion(-) 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); From 3b32727d9e91124d14d3e9a783294da294e82a79 Mon Sep 17 00:00:00 2001 From: dubslow Date: Mon, 13 Oct 2014 17:45:52 -0500 Subject: [PATCH 3/6] We handle .tox files (still need actual command line support) --- qTox.desktop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From 48faffaa3e2c546eb4803f3701e3979991c82ec0 Mon Sep 17 00:00:00 2001 From: dubslow Date: Mon, 13 Oct 2014 19:27:24 -0500 Subject: [PATCH 4/6] fix compile warning, they are fatal to Qt Creator --- src/core.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core.cpp b/src/core.cpp index 824085de6..614184242 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -585,7 +585,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 From a0ca379c1bdd035111d5f5c3c4317e77a857adab Mon Sep 17 00:00:00 2001 From: dubslow Date: Tue, 14 Oct 2014 20:04:53 -0500 Subject: [PATCH 5/6] fix #436 --- src/core.h | 2 ++ src/coreav.cpp | 8 ++++++++ src/widget/form/settings/identityform.cpp | 9 ++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core.h b/src/core.h index f57a97342..2b6a7d8ca 100644 --- a/src/core.h +++ b/src/core.h @@ -64,6 +64,8 @@ public: void increaseVideoBusyness(); void decreaseVideoBusyness(); + bool anyActiveCalls(); + public slots: void start(); void process(); 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/form/settings/identityform.cpp b/src/widget/form/settings/identityform.cpp index 1c16e6b8b..7e85c2d05 100644 --- a/src/widget/form/settings/identityform.cpp +++ b/src/widget/form/settings/identityform.cpp @@ -108,7 +108,14 @@ 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 + Core::getInstance()->switchConfiguration(bodyUI->profiles->currentText()); + } } void IdentityForm::onRenameClicked() From 63671ae3ffee3c09537ac7cb2703e72f683df24d Mon Sep 17 00:00:00 2001 From: dubslow Date: Tue, 14 Oct 2014 21:06:44 -0500 Subject: [PATCH 6/6] I learned some things: improve thread safety --- src/core.cpp | 4 ++-- src/core.h | 3 ++- src/widget/form/settings/identityform.cpp | 3 ++- src/widget/widget.cpp | 2 ++ src/widget/widget.h | 1 + 5 files changed, 9 insertions(+), 4 deletions(-) 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();