Skip to content

Commit

Permalink
Fixed various crashes and freezes
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilInTheGaps committed Nov 3, 2023
1 parent fb552b9 commit bfd1b35
Show file tree
Hide file tree
Showing 57 changed files with 704 additions and 648 deletions.
6 changes: 3 additions & 3 deletions app/ui/FileDialog/filedialogbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void FileDialogBackend::createFolder(const QString &folderName)
{
const auto path = FileUtils::fileInDir(folderName, currentDir());

File::createDirAsync(path).then(this, [this](FileResult &&result) {
File::createDirAsync(path).then([this](FileResult &&result) {
if (!result.success())
{
qCWarning(gmFileDialog()) << result.errorMessage();
Expand All @@ -125,8 +125,8 @@ void FileDialogBackend::updateFileList()
isLoading(true);

m_currentFuture = File::listAsync(currentDir(), !folderMode(), true);
m_currentFuture.then(this, [this](FileListResult &&result) { onFileListReceived(std::move(result)); })
.onCanceled(this, [this]() {
m_currentFuture.then([this](FileListResult &&result) { onFileListReceived(std::move(result)); })
.onCanceled([this]() {
qCDebug(gmFileDialog()) << "file list update was cancelled.";
isLoading(false);
});
Expand Down
42 changes: 21 additions & 21 deletions app/ui/tools/audio/editor/dialogs/AddonElementDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,17 @@ Dialog {
}

onAccepted: {
let project = AudioTool.editor.addons.projects[addon_project_combo_box.currentIndex]
let subscenario = asSubscenario ? subscenarioIndex : -1

switch (mode) {
case AddonElementDialog.Mode.Project:
AudioTool.editor.createProjectFromTemplate(project)
AudioTool.editor.createProjectFromTemplate(AudioTool.editor.addons.currentProject)
break
case AddonElementDialog.Mode.Category:
AudioTool.editor.createCategoryFromTemplate(project.currentCategory)
AudioTool.editor.createCategoryFromTemplate(AudioTool.editor.addons.currentProject.currentCategory)
break
case AddonElementDialog.Mode.Scenario:
AudioTool.editor.createScenarioFromTemplate(project.currentScenario,
asSubscenario)
AudioTool.editor.createScenarioFromTemplate(AudioTool.editor.addons.currentProject.currentScenario, asSubscenario)
break
case AddonElementDialog.Mode.Music:
case AddonElementDialog.Mode.Sound:
Expand Down Expand Up @@ -92,7 +90,7 @@ Dialog {
textRole: "shortName"

onCurrentTextChanged: {
AudioTool.editor.addons.currentIndex = currentIndex
AudioTool.editor.addons.currentAddonIndex = currentIndex
}
}

Expand All @@ -103,8 +101,12 @@ Dialog {
anchors.right: parent.right
emptyString: qsTr("No Projects")

model: AudioTool.editor.addons.projects
model: AudioTool.editor.addons.availableProjects
textRole: "name"

onCurrentTextChanged: {
AudioTool.editor.addons.currentProjectIndex = currentIndex
}
}

Flickable {
Expand All @@ -129,19 +131,18 @@ Dialog {
anchors.right: parent.right

Repeater {
model: addon_project_combo_box.currentIndex >= 0
? AudioTool.editor.addons.projects[addon_project_combo_box.currentIndex].categories : []
model: AudioTool.editor.addons.currentProject ?
AudioTool.editor.addons.currentProject.categories : []

CustomButton {
required property AudioProject modelData
required property AudioCategory modelData

anchors.left: parent.left
anchors.right: parent.right
anchors.left: parent ? parent.left : undefined
anchors.right: parent ? parent.right : undefined
buttonText: modelData.name // qmllint disable missing-property

onClicked: {
let project = AudioTool.editor.addons.projects[addon_project_combo_box.currentIndex]
project.currentCategory = modelData
AudioTool.editor.addons.currentProject.currentCategory = modelData
}
}
}
Expand All @@ -166,8 +167,8 @@ Dialog {
Repeater {
id: scenario_repeater

model: addon_project_combo_box.currentIndex >= 0
? AudioTool.editor.addons.projects[addon_project_combo_box.currentIndex].currentCategory.scenarios : []
model: AudioTool.editor.addons.currentProject && AudioTool.editor.addons.currentProject.currentCategory ?
AudioTool.editor.addons.currentProject.currentCategory.scenarios : []

CustomButton {
required property AudioScenario modelData
Expand All @@ -177,8 +178,7 @@ Dialog {
backgroundColor: "transparent"
usesFixedWidth: false
onClicked: {
let project = AudioTool.editor.addons.projects[addon_project_combo_box.currentIndex]
let category = project.currentCategory
let category = AudioTool.editor.addons.currentProject.currentCategory
category.currentScenario = modelData
}
}
Expand All @@ -205,9 +205,9 @@ Dialog {

clip: true

model: addon_project_combo_box.currentIndex >= 0
&& AudioTool.editor.addons.projects[addon_project_combo_box.currentIndex].currentCategory.currentScenario
? AudioTool.editor.addons.projects[addon_project_combo_box.currentIndex].currentCategory.currentScenario.model : []
model: AudioTool.editor.addons.currentProject
&& AudioTool.editor.addons.currentProject.currentCategory.currentScenario
? AudioTool.editor.addons.currentProject.currentCategory.currentScenario.model : []

ScrollBar.vertical: ScrollBar {
id: verticalScrollBar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ Item {
required property AudioScenario modelData
required property int index

anchors.right: parent.right
anchors.left: parent.left
anchors.right: parent ? parent.right : undefined
anchors.left: parent ? parent.left : undefined

text: modelData.name // qmllint disable missing-property

Expand Down
2 changes: 1 addition & 1 deletion src/addons/addonmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ auto AddonManager::installRemoteAsync(Addon &addon) -> QFuture<void>
qCDebug(gmAddonManager()) << "Installed remote addon" << addon.id();
};

return QtFuture::connect(reply, &QNetworkReply::finished).then(this, callback);
return QtFuture::connect(reply, &QNetworkReply::finished).then(callback);
}

/// Update addon by removing the old version and installing the new one
Expand Down
17 changes: 8 additions & 9 deletions src/addons/addonrepositorymanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,14 @@ void AddonRepositoryManager::fetchAllRepositoryData()

foreach (const auto *repo, repositories())
{
auto future =
fetchRepositoryDataAsync(repo->url()).then([this, repo](const std::vector<AddonReleaseInfo> &info) {
if (!info.empty())
{
qCDebug(gmAddonRepoManager()) << "Successfully read addon repository" << repo->url();
}

m_releaseInfos.insert(m_releaseInfos.end(), info.begin(), info.end());
});
auto future = fetchRepositoryDataAsync(repo->url()).then([this, repo](std::vector<AddonReleaseInfo> &&info) {
if (!info.empty())
{
qCDebug(gmAddonRepoManager()) << "Successfully read addon repository" << repo->url();
}

m_releaseInfos.insert(m_releaseInfos.end(), info.begin(), info.end());
});

combinator << future;
}
Expand Down
87 changes: 41 additions & 46 deletions src/common/settings/settingsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,52 +117,47 @@ void SettingsManager::setServerUrl(const QString &url, const QString &service)
instance()->set(u"server"_s, url, service);
}

auto SettingsManager::getPassword(const QString &username, const QString &service) -> QFuture<QString>
{
return QtConcurrent::run([username, service]() {
auto job = std::make_unique<QKeychain::ReadPasswordJob>(u"gm-companion.%1"_s.arg(service));
job->setAutoDelete(false);
job->setKey(username);

QEventLoop loop;
job->connect(job.get(), &QKeychain::ReadPasswordJob::finished, &loop, &QEventLoop::quit);
job->start();
loop.exec();

if (job->error())
{
qCCritical(gmSettings) << "Could not read password:" << job->error() << job->errorString();
return u""_s;
}

qCDebug(gmSettings) << "Successfully read password for service" << service;
return job->textData();
});
}

auto SettingsManager::setPassword(const QString &username, const QString &password, const QString &service)
-> QFuture<bool>
{
return QtConcurrent::run([username, password, service]() {
auto job = std::make_unique<QKeychain::WritePasswordJob>(u"gm-companion.%1"_s.arg(service));
job->setAutoDelete(false);
job->setKey(username);
job->setTextData(password);

QEventLoop loop;
job->connect(job.get(), &QKeychain::WritePasswordJob::finished, &loop, &QEventLoop::quit);
job->start();
loop.exec();

if (job->error())
{
qCCritical(gmSettings) << "Unable to save password:" << job->error() << job->errorString();
return false;
}

qCDebug(gmSettings) << "Successfully saved password.";
return true;
});
auto SettingsManager::getPassword(const QString &username, const QString &service) -> QString
{
// job is deleted automatically when finished
auto *job = new QKeychain::ReadPasswordJob(u"gm-companion.%1"_s.arg(service));
job->setKey(username);

QEventLoop loop;
job->connect(job, &QKeychain::ReadPasswordJob::finished, &loop, &QEventLoop::quit);
job->start();
loop.exec();

if (job->error())
{
qCCritical(gmSettings) << "Could not read password:" << job->error() << job->errorString();
return u""_s;
}

qCDebug(gmSettings) << "Successfully read password for service" << service;
return job->textData();
}

auto SettingsManager::setPassword(const QString &username, const QString &password, const QString &service) -> bool
{
// job is deleted automatically when finished
auto *job = new QKeychain::WritePasswordJob(u"gm-companion.%1"_s.arg(service));
job->setKey(username);
job->setTextData(password);

QEventLoop loop;
job->connect(job, &QKeychain::WritePasswordJob::finished, &loop, &QEventLoop::quit);
job->start();
loop.exec();

if (job->error())
{
qCCritical(gmSettings) << "Unable to save password:" << job->error() << job->errorString();
return false;
}

qCDebug(gmSettings) << "Successfully saved password.";
return true;
}

auto SettingsManager::getDefaultPath(const QString &setting, const QString &group) -> QString
Expand Down
4 changes: 2 additions & 2 deletions src/common/settings/settingsmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class SettingsManager : public AbstractSettingsManager
static auto getServerUrl(const QString &service, bool hasDefault = true) -> QString;
static void setServerUrl(const QString &url, const QString &service);

static auto getPassword(const QString &username, const QString &service) -> QFuture<QString>;
static auto setPassword(const QString &username, const QString &password, const QString &service) -> QFuture<bool>;
static auto getPassword(const QString &username, const QString &service) -> QString;
static auto setPassword(const QString &username, const QString &password, const QString &service) -> bool;

void setAddonEnabled(const QString &addon, bool enabled);
auto getIsAddonEnabled(const QString &addon) -> bool;
Expand Down
6 changes: 3 additions & 3 deletions src/common/updates/updatemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ void UpdateManager::checkForUpdates()
qCDebug(gmUpdateManager) << "Current version:" << CURRENT_VERSION;
qCDebug(gmUpdateManager) << "Releases feed URL:" << m_feedURL;

fetchNewestVersion().then([this](const QString &version) {
m_newestVersion = version;
qCDebug(gmUpdateManager()) << "Newest available version:" << version;
fetchNewestVersion().then([this](QString &&version) {
m_newestVersion = std::move(version);
qCDebug(gmUpdateManager()) << "Newest available version:" << m_newestVersion;

if (compareVersions(CURRENT_VERSION, m_newestVersion))
{
Expand Down
Loading

0 comments on commit bfd1b35

Please sign in to comment.