Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11565 confirmation dialog for reset preferences and make sure all preferences reset correctly #25872

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9e2926f
11565: Added a confirmation dialog for when the "Reset preferences" b…
krasko78 Oct 25, 2024
b5e5454
11565: Made the General page update upon Reset Preferences
krasko78 Oct 26, 2024
0287080
11565: Made the Canvas page update upon Reset Preferences
krasko78 Oct 26, 2024
e668325
11565: Made the Save & Publish page update upon Reset Preferences
krasko78 Oct 26, 2024
8114650
11565: Made the Note Input page update on Reset Preferences
krasko78 Dec 13, 2024
f0f051a
11565: Made the Braille page update upon Reset Preferences
krasko78 Oct 26, 2024
2c66c0d
11565: Made the Advanced page update upon Reset Preferences
krasko78 Oct 27, 2024
4517d44
11565: Made the Update page update on Reset Preferences
krasko78 Oct 27, 2024
26eae94
11565: Made the Import page update upon Reset Preferences
krasko78 Oct 28, 2024
b809973
11565: Made the MIDI Mappings page update on Reset Preferences
krasko78 Oct 28, 2024
4801011
11565: Made the Audio & MIDI page update on Reset Preferences
krasko78 Oct 28, 2024
d28918c
11565: Made the Score page update on Reset Preferences
krasko78 Oct 31, 2024
62497d6
11565: Added "This action cannot be undone." to the confirmation dial…
krasko78 Oct 31, 2024
737841a
11565: Refined the resetting of the General page settings
krasko78 Oct 31, 2024
b19c06d
11565: Refined the resetting of the Canvas page settings
krasko78 Oct 31, 2024
dab52ac
11565: Refined the resetting of the Note input page settings
krasko78 Oct 31, 2024
7930ccc
11565: Refined the resetting of the Advanced page settings
krasko78 Nov 1, 2024
df4a6c1
11565: Refined the resetting of the Import page settings
krasko78 Nov 1, 2024
e2d39c0
11565: Refined the resetting of the Score page settings
krasko78 Nov 1, 2024
ffb5aeb
11565: Fixing the coding style rule violations
krasko78 Nov 1, 2024
28bc3a6
11565: Fixing a conflict with DEFAULT_DEVICE_ID (failing Linux build …
krasko78 Nov 1, 2024
02b89f5
11565: Fixing the tests
krasko78 Nov 1, 2024
7756e75
11565: Fixing the tests
krasko78 Nov 1, 2024
789c64f
11565: Minor improvements
krasko78 Nov 18, 2024
83f19fd
11565: Tweaks per code review and my own
krasko78 Dec 14, 2024
1543c0a
11565: Refine the message and button order and appearance on the conf…
krasko78 Dec 17, 2024
0bd07ee
11565: Do not reset the "Has Completed First-Time Launch" setting so …
krasko78 Dec 17, 2024
da9f340
11565: Use one DEFAULT_DEVICE_ID constant
krasko78 Dec 17, 2024
3a7b22e
11565: Suppress the first-time launch wizard only on Preferences Rese…
krasko78 Dec 19, 2024
ed4bce2
11565: Made the Cancel button the accent button on the confirm Reset …
krasko78 Jan 1, 2025
710c198
11565: Allow a dialog title to be passed to StandardDialog
krasko78 Jan 1, 2025
c816e89
11565: Change title of 'Reset Preferences' and 'Revert to Factory Set…
krasko78 Jan 1, 2025
f06bb09
11565: Fixing the code style violations
krasko78 Jan 1, 2025
7b51f75
11565: Skip onChanged notifications when resetting preferences for se…
krasko78 Jan 3, 2025
4e39b0f
11565: Bringing back an include file that was previously flagged as u…
krasko78 Jan 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/appshell/iappshellconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define MU_APPSHELL_IAPPSHELLCONFIGURATION_H

#include "modularity/imoduleinterface.h"
#include "types/retval.h"
#include "types/ret.h"

#include "io/path.h"
#include "appshelltypes.h"
Expand All @@ -42,9 +42,11 @@ class IAppShellConfiguration : MODULE_EXPORT_INTERFACE

virtual StartupModeType startupModeType() const = 0;
virtual void setStartupModeType(StartupModeType type) = 0;
virtual muse::async::Notification startupModeTypeChanged() const = 0;

virtual muse::io::path_t startupScorePath() const = 0;
virtual void setStartupScorePath(const muse::io::path_t& scorePath) = 0;
virtual muse::async::Notification startupScorePathChanged() const = 0;

virtual muse::io::path_t userDataPath() const = 0;

Expand Down Expand Up @@ -73,7 +75,7 @@ class IAppShellConfiguration : MODULE_EXPORT_INTERFACE
virtual void applySettings() = 0;
virtual void rollbackSettings() = 0;

virtual void revertToFactorySettings(bool keepDefaultSettings = false, bool notifyAboutChanges = true) const = 0;
virtual void revertToFactorySettings(bool keepDefaultSettings = false, bool notifyAboutChanges = true) = 0;

virtual muse::io::paths_t sessionProjectsPaths() const = 0;
virtual muse::Ret setSessionProjectsPaths(const muse::io::paths_t& paths) = 0;
Expand Down
10 changes: 7 additions & 3 deletions src/appshell/internal/applicationactioncontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,15 @@ void ApplicationActionController::revertToFactorySettings()
"The list of recent scores will also be cleared.\n\n"
"This action will not delete any of your scores.");

IInteractive::ButtonData cancelBtn = interactive()->buttonData(IInteractive::Button::Cancel);
cancelBtn.accent = true;

int revertBtn = int(IInteractive::Button::Apply);
IInteractive::Result result = interactive()->warning(title, question,
{ interactive()->buttonData(IInteractive::Button::Cancel),
IInteractive::ButtonData(revertBtn, muse::trc("appshell", "Revert"), true) },
revertBtn);
{ cancelBtn,
IInteractive::ButtonData(revertBtn, muse::trc("appshell", "Revert")) },
cancelBtn.btn, { muse::IInteractive::Option::WithIcon },
muse::trc("appshell", "Revert to factory settings"));

if (result.standardButton() == IInteractive::Button::Cancel) {
return;
Expand Down
19 changes: 18 additions & 1 deletion src/appshell/internal/appshellconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ void AppShellConfiguration::init()
settings()->setDefaultValue(HAS_COMPLETED_FIRST_LAUNCH_SETUP, Val(false));

settings()->setDefaultValue(STARTUP_MODE_TYPE, Val(StartupModeType::StartEmpty));
settings()->valueChanged(STARTUP_MODE_TYPE).onReceive(this, [this](const Val&) {
m_startupModeTypeChanged.notify();
});

settings()->setDefaultValue(STARTUP_SCORE_PATH, Val(projectConfiguration()->myFirstProjectPath().toStdString()));
settings()->valueChanged(STARTUP_SCORE_PATH).onReceive(this, [this](const Val&) {
m_startupScorePathChanged.notify();
});

fileSystem()->makePath(sessionDataPath());
}
Expand All @@ -88,6 +95,11 @@ void AppShellConfiguration::setStartupModeType(StartupModeType type)
settings()->setSharedValue(STARTUP_MODE_TYPE, Val(type));
}

async::Notification AppShellConfiguration::startupModeTypeChanged() const
{
return m_startupModeTypeChanged;
}

muse::io::path_t AppShellConfiguration::startupScorePath() const
{
return settings()->value(STARTUP_SCORE_PATH).toString();
Expand All @@ -98,6 +110,11 @@ void AppShellConfiguration::setStartupScorePath(const muse::io::path_t& scorePat
settings()->setSharedValue(STARTUP_SCORE_PATH, Val(scorePath.toStdString()));
}

async::Notification AppShellConfiguration::startupScorePathChanged() const
{
return m_startupScorePathChanged;
}

muse::io::path_t AppShellConfiguration::userDataPath() const
{
return globalConfiguration()->userDataPath();
Expand Down Expand Up @@ -213,7 +230,7 @@ void AppShellConfiguration::rollbackSettings()
settings()->rollbackTransaction();
}

void AppShellConfiguration::revertToFactorySettings(bool keepDefaultSettings, bool notifyAboutChanges) const
void AppShellConfiguration::revertToFactorySettings(bool keepDefaultSettings, bool notifyAboutChanges)
{
settings()->reset(keepDefaultSettings, notifyAboutChanges);
}
Expand Down
7 changes: 6 additions & 1 deletion src/appshell/internal/appshellconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ class AppShellConfiguration : public IAppShellConfiguration, public muse::Inject

StartupModeType startupModeType() const override;
void setStartupModeType(StartupModeType type) override;
muse::async::Notification startupModeTypeChanged() const override;

muse::io::path_t startupScorePath() const override;
void setStartupScorePath(const muse::io::path_t& scorePath) override;
muse::async::Notification startupScorePathChanged() const override;

muse::io::path_t userDataPath() const override;

Expand Down Expand Up @@ -92,7 +94,7 @@ class AppShellConfiguration : public IAppShellConfiguration, public muse::Inject
void applySettings() override;
void rollbackSettings() override;

void revertToFactorySettings(bool keepDefaultSettings = false, bool notifyAboutChanges = true) const override;
void revertToFactorySettings(bool keepDefaultSettings = false, bool notifyAboutChanges = true) override;

muse::io::paths_t sessionProjectsPaths() const override;
muse::Ret setSessionProjectsPaths(const muse::io::paths_t& paths) override;
Expand All @@ -111,6 +113,9 @@ class AppShellConfiguration : public IAppShellConfiguration, public muse::Inject
muse::io::paths_t parseSessionProjectsPaths(const QByteArray& json) const;

QString m_preferencesDialogCurrentPageId;

muse::async::Notification m_startupModeTypeChanged;
muse::async::Notification m_startupScorePathChanged;
};
}

Expand Down
4 changes: 4 additions & 0 deletions src/appshell/qml/Preferences/BraillePreferencesPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ PreferencesPage {
id: preferencesModel
}

Component.onCompleted: {
preferencesModel.load()
}

Column {
width: parent.width
spacing: root.sectionsSpacing
Expand Down
5 changes: 5 additions & 0 deletions src/appshell/qml/Preferences/ImportPreferencesPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ PreferencesPage {
spacing: root.sectionsSpacing

ImportStyleSection {
id: importStyleSection
styleFileImportPath: importPreferencesModel.styleFileImportPath
fileChooseTitle: importPreferencesModel.styleChooseTitle()
filePathFilter: importPreferencesModel.stylePathFilter()
Expand Down Expand Up @@ -145,4 +146,8 @@ PreferencesPage {
}
}
}

function reset() {
importStyleSection.reset()
}
}
4 changes: 4 additions & 0 deletions src/appshell/qml/Preferences/PreferencesDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ StyledDialogView {
navigation.order: 100000

onRevertFactorySettingsRequested: {
if (!preferencesModel.askForConfirmationOfPreferencesReset()) {
return;
}

var pages = preferencesModel.availablePages()

for (var i in pages) {
Expand Down
4 changes: 4 additions & 0 deletions src/appshell/qml/Preferences/UpdatePreferencesPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ PreferencesPage {
id: updateModel
}

Component.onCompleted: {
updateModel.load()
}

Column {
width: parent.width
spacing: root.sectionsSpacing
Expand Down
11 changes: 8 additions & 3 deletions src/appshell/qml/Preferences/internal/ImportStyleSection.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ BaseSection {
QtObject {
id: prv

property bool useStyleFile: root.styleFileImportPath !== ""
property bool useStyleFileExplicitlySet: root.styleFileImportPath !== ""
property bool useStyleFile: prv.useStyleFileExplicitlySet || root.styleFileImportPath !== ""
}

function reset() {
prv.useStyleFileExplicitlySet = false
}

RoundedRadioButton {
Expand All @@ -57,7 +62,7 @@ BaseSection {
navigation.column: 0

onToggled: {
prv.useStyleFile = false
prv.useStyleFileExplicitlySet = false
root.styleFileImportPathChangeRequested("")
}
}
Expand All @@ -81,7 +86,7 @@ BaseSection {
navigation.column: 0

onToggled: {
prv.useStyleFile = true
prv.useStyleFileExplicitlySet = true
}
}

Expand Down
40 changes: 34 additions & 6 deletions src/appshell/view/preferences/advancedpreferencesmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool AdvancedPreferencesModel::setData(const QModelIndex& index, const QVariant&

switch (role) {
case ValueRole:
changeVal(index.row(), value);
changeVal(index.row(), Val::fromQVariant(value));
emit dataChanged(index, index, { ValueRole });
return true;
default:
Expand Down Expand Up @@ -96,28 +96,56 @@ void AdvancedPreferencesModel::load()
for (auto it = items.cbegin(); it != items.cend(); ++it) {
if (it->second.canBeManuallyEdited) {
m_items << it->second;

muse::Settings::Key key = it->second.key;
settings()->valueChanged(key).onReceive(this, [this, key](const Val& val) {
QModelIndex index = findIndex(key);
if (!index.isValid() || m_items[index.row()].value == val) {
return;
}

changeModelVal(m_items[index.row()], val);
emit dataChanged(index, index, { ValueRole });
});
}
}

endResetModel();
}

void AdvancedPreferencesModel::changeVal(int index, QVariant newVal)
QModelIndex AdvancedPreferencesModel::findIndex(const muse::Settings::Key& key)
{
for (int i = 0; i < m_items.size(); ++i) {
if (m_items[i].key == key) {
return index(i, 0);
}
}
return QModelIndex();
}

void AdvancedPreferencesModel::changeVal(int index, const Val& newVal)
{
Settings::Item& item = m_items[index];
changeModelVal(item, newVal);
settings()->setSharedValue(item.key, item.value);
}

void AdvancedPreferencesModel::changeModelVal(Settings::Item& item, const Val& newVal)
{
if (item.value == newVal) {
return;
}
Val::Type type = item.value.type();
item.value = Val::fromQVariant(newVal);
item.value = newVal;
item.value.setType(type);

settings()->setSharedValue(item.key, item.value);
}

void AdvancedPreferencesModel::resetToDefault()
{
beginResetModel();

for (int i = 0; i < m_items.size(); ++i) {
changeVal(i, m_items[i].defaultValue.toQVariant());
changeVal(i, m_items[i].defaultValue);
}

endResetModel();
Expand Down
7 changes: 5 additions & 2 deletions src/appshell/view/preferences/advancedpreferencesmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@

#include <QAbstractListModel>

#include "async/asyncable.h"
#include "settings.h"

namespace mu::appshell {
class AdvancedPreferencesModel : public QAbstractListModel
class AdvancedPreferencesModel : public QAbstractListModel, public muse::async::Asyncable
{
Q_OBJECT

Expand All @@ -53,7 +54,9 @@ class AdvancedPreferencesModel : public QAbstractListModel
MaxValueRole
};

void changeVal(int index, QVariant newVal);
QModelIndex findIndex(const muse::Settings::Key& key);
void changeVal(int index, const muse::Val& newVal);
void changeModelVal(muse::Settings::Item& item, const muse::Val& newVal);
QString typeToString(muse::Val::Type type) const;

QList<muse::Settings::Item> m_items;
Expand Down
4 changes: 4 additions & 0 deletions src/appshell/view/preferences/audiomidipreferencesmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ void AudioMidiPreferencesModel::init()
emit midiOutputDeviceIdChanged();
});

midiConfiguration()->useMIDI20OutputChanged().onReceive(this, [this](bool) {
emit useMIDI20OutputChanged();
});

playbackConfiguration()->muteHiddenInstrumentsChanged().onReceive(this, [this](bool mute) {
emit muteHiddenInstrumentsChanged(mute);
});
Expand Down
15 changes: 15 additions & 0 deletions src/appshell/view/preferences/braillepreferencesmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ BraillePreferencesModel::BraillePreferencesModel(QObject* parent)
{
}

void BraillePreferencesModel::load()
{
brailleConfiguration()->braillePanelEnabledChanged().onNotify(this, [this]() {
emit braillePanelEnabledChanged(braillePanelEnabled());
});

brailleConfiguration()->intervalDirectionChanged().onNotify(this, [this]() {
emit intervalDirectionChanged(intervalDirection());
});

brailleConfiguration()->brailleTableChanged().onNotify(this, [this]() {
emit brailleTableChanged(brailleTable());
});
}

bool BraillePreferencesModel::braillePanelEnabled() const
{
return brailleConfiguration()->braillePanelEnabled();
Expand Down
5 changes: 4 additions & 1 deletion src/appshell/view/preferences/braillepreferencesmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@

#include <QObject>

#include "async/asyncable.h"
#include "modularity/ioc.h"
#include "braille/ibrailleconfiguration.h"

namespace mu::appshell {
class BraillePreferencesModel : public QObject, public muse::Injectable
class BraillePreferencesModel : public QObject, public muse::Injectable, public muse::async::Asyncable
{
Q_OBJECT

Expand All @@ -42,6 +43,8 @@ class BraillePreferencesModel : public QObject, public muse::Injectable
public:
explicit BraillePreferencesModel(QObject* parent = nullptr);

Q_INVOKABLE void load();

bool braillePanelEnabled() const;
QString brailleTable() const;
int intervalDirection() const;
Expand Down
Loading