From daa4f22b86c0755ee2badaf813309f64ecc63a86 Mon Sep 17 00:00:00 2001 From: Phil Hoffmann Date: Mon, 13 Nov 2023 22:36:05 +0100 Subject: [PATCH] Important colors can now be set by the user; refactored quick settings manager --- .qmllint.ini | 2 +- app/main.cpp | 10 +- app/ui/CMakeLists.txt | 6 +- app/ui/CustomComponents/CMakeLists.txt | 1 + app/ui/CustomComponents/CustomColorButton.qml | 37 ++ app/ui/CustomComponents/CustomToolBar.qml | 3 +- app/ui/Main.qml | 25 +- app/ui/Style/ComboBox.qml | 4 +- app/ui/common/TreeViewItem.qml | 54 +- app/ui/main/MessageDialog.qml | 28 +- app/ui/main/SideMenuButton.qml | 5 +- app/ui/tools/Dice.qml | 7 +- app/ui/tools/DiceAlt.qml | 28 +- app/ui/tools/audio/VolumeSlider.qml | 2 +- .../audio/editor/EditorElementColumn.qml | 19 +- app/ui/tools/audio/editor/EditorHeader.qml | 3 +- .../editor/dialogs/EditorNewThingDialog.qml | 3 +- .../element_properties/ElementNameView.qml | 62 +-- .../element_properties/PlaybackModeView.qml | 20 +- .../characters/classic/ImageControlBar.qml | 11 - app/ui/tools/combat_tracker/ListSpinBox.qml | 3 +- .../ConverterEditorNewThingDialog.qml | 72 ++- app/ui/tools/dice/DiceButton.qml | 6 +- app/ui/tools/maps/MapMarkerEditor.qml | 18 +- app/ui/tools/maps/MapViewerControlBar.qml | 11 - app/ui/tools/settings/GeneralPage.qml | 481 +++++++++++++----- .../settings/accounts/BaseAccountPage.qml | 10 +- .../settings/accounts/GoogleDriveAccount.qml | 38 +- .../settings/accounts/NextCloudAccount.qml | 24 +- .../settings/accounts/SpotifyAccount.qml | 91 ++-- app/ui/tools/settings/accounts/StatusBar.qml | 43 +- app/ui/tools/shop/shop_editor/ShopInfo.qml | 11 +- src/addons/addonmanager.cpp | 1 + src/addons/addonrepositorymanager.cpp | 4 +- src/common/CMakeLists.txt | 15 +- .../settings/abstractsettingsmanager.cpp | 8 +- src/common/settings/abstractsettingsmanager.h | 41 +- src/common/settings/quick/colors.h | 54 ++ src/common/settings/quick/google.h | 27 + src/common/settings/quick/macros.h | 35 ++ src/common/settings/quick/nextcloud.h | 33 ++ src/common/settings/quick/services.h | 46 ++ src/common/settings/quick/settingsmanager.cpp | 59 +++ src/common/settings/quick/settingsmanager.h | 81 +++ src/common/settings/quick/spotify.h | 47 ++ src/common/settings/quicksettingsmanager.cpp | 73 --- src/common/settings/quicksettingsmanager.h | 94 ---- src/common/settings/settingsmanager.cpp | 23 +- src/common/settings/settingsmanager.h | 22 +- src/common/updates/updatemanager.cpp | 5 +- src/common/utils/stringutils.h | 7 - src/filesystem/file.cpp | 1 + src/services/google/googledrive.cpp | 9 +- .../google/googledriveconnectorlocal.cpp | 5 +- src/services/nextcloud/nextcloud.cpp | 1 + src/services/nextcloud/nextcloud.h | 2 +- .../rest/restserviceconnectorlocal.cpp | 1 + src/services/rest/restserviceconnectorlocal.h | 4 +- src/services/service.cpp | 1 + .../spotify/clients/librespotcontroller.cpp | 3 +- src/services/spotify/spotify.cpp | 11 +- src/services/spotify/spotify.h | 2 +- .../spotify/spotifyconnectorlocal.cpp | 4 +- .../spotify/spotifyconnectorserver.cpp | 1 + src/tools/audio/audiosaveload.cpp | 1 + src/tools/audio/editor/audioeditor.cpp | 1 + src/tools/audio/editor/audioeditor.h | 2 +- .../audio/editor/audioeditorfilebrowser.cpp | 1 + src/tools/audio/editor/audioexporter.cpp | 1 + .../audio/players/bufferedaudioplayer.cpp | 1 + .../audio/playlist/resolvingaudioplaylist.cpp | 3 +- src/tools/audio/thumbnails/audiothumbnail.cpp | 1 + .../thumbnails/loaders/tagimageloader.cpp | 4 +- src/tools/characters/charactertool.cpp | 1 + src/tools/converter/convertertool.cpp | 1 + src/tools/dicetool.cpp | 16 +- src/tools/generators/names/namegenerator.cpp | 3 + src/tools/generators/names/namegenerator.h | 3 - src/tools/maps/map.cpp | 1 + src/tools/maps/maptool.cpp | 2 + src/tools/notes/notessaveload.cpp | 1 + src/tools/shop/baseshoptool.cpp | 1 + src/tools/shop/itemeditor.cpp | 1 + src/tools/shop/shopeditor.cpp | 1 + tests/common/settings/testsettingsmanager.cpp | 1 + tests/common/utils/teststringutils.cpp | 7 - tests/filesystem/testnextcloudaccess.cpp | 1 + tests/testhelper/abstracttest.cpp | 1 + .../audio/testresolvingaudioplaylist.cpp | 1 + tests/tools/converter/testconvertertool.cpp | 2 + tests/tools/notes/testnotestool.cpp | 1 + tests/tools/shop/testshopeditor.cpp | 2 + tests/tools/shop/testshoptool.cpp | 2 + 93 files changed, 1193 insertions(+), 729 deletions(-) create mode 100644 app/ui/CustomComponents/CustomColorButton.qml create mode 100644 src/common/settings/quick/colors.h create mode 100644 src/common/settings/quick/google.h create mode 100644 src/common/settings/quick/macros.h create mode 100644 src/common/settings/quick/nextcloud.h create mode 100644 src/common/settings/quick/services.h create mode 100644 src/common/settings/quick/settingsmanager.cpp create mode 100644 src/common/settings/quick/settingsmanager.h create mode 100644 src/common/settings/quick/spotify.h delete mode 100644 src/common/settings/quicksettingsmanager.cpp delete mode 100644 src/common/settings/quicksettingsmanager.h diff --git a/.qmllint.ini b/.qmllint.ini index e08a30e4..79a0e003 100644 --- a/.qmllint.ini +++ b/.qmllint.ini @@ -14,7 +14,7 @@ ControlsSanity=disable Deprecated=warning DuplicatePropertyBinding=warning DuplicatedName=warning -ImportFailure=warning +ImportFailure=info IncompatibleType=warning InheritanceCycle=warning InvalidLintDirective=warning diff --git a/app/main.cpp b/app/main.cpp index 6124e1d5..db48f834 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -1,7 +1,7 @@ #include "filesystem/file.h" #include "logger.h" #include "services/nextcloud/nextcloud.h" -#include "settings/quicksettingsmanager.h" +#include "settings/quick/settingsmanager.h" #include "tools/audio/thumbnails/audiothumbnailprovider.h" #include "updates/version.h" #include @@ -20,6 +20,7 @@ #include using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmMain, "gm.main") @@ -54,7 +55,7 @@ void initTranslations(QTranslator &translator, QQmlEngine &engine) updateTranslation(translator); - QObject::connect(QuickSettingsManager::instance(), &QuickSettingsManager::languageChanged, &translator, + QObject::connect(Quick::SettingsManager::instance(), &Quick::SettingsManager::languageChanged, &translator, [&translator, &engine]() { updateTranslation(translator); engine.retranslate(); @@ -75,9 +76,10 @@ void setPalette() palette.setColor(QPalette::ColorRole::AlternateBase, "#343a43"_L1); palette.setColor(QPalette::ColorRole::Window, "#2e2e2e"_L1); palette.setColor(QPalette::ColorRole::WindowText, "#f6f7f8"_L1); - palette.setColor(QPalette::ColorRole::Button, "#8f9aa9"_L1); // 3f4957 + palette.setColor(QPalette::ColorRole::Button, "#8f9aa9"_L1); palette.setColor(QPalette::ColorRole::ButtonText, "#f6f7f8"_L1); - palette.setColor(QPalette::ColorRole::Light, "#ebedef"_L1); + palette.setColor(QPalette::ColorRole::Light, + "#1f1f1f"_L1); // same a dark so that qt dialogs still look ok, was #ebedef before palette.setColor(QPalette::ColorRole::Midlight, "#d5dade"_L1); palette.setColor(QPalette::ColorRole::Mid, "#bfc6cd"_L1); palette.setColor(QPalette::ColorRole::Dark, "#1f1f1f"_L1); diff --git a/app/ui/CMakeLists.txt b/app/ui/CMakeLists.txt index 093596a0..7191b6f8 100644 --- a/app/ui/CMakeLists.txt +++ b/app/ui/CMakeLists.txt @@ -38,6 +38,8 @@ qt_add_qml_module(gm-companion-ui src OPTIONAL_IMPORTS Style + DEPENDENCIES + QtQuick QML_FILES Main.qml Sizes.qml @@ -168,4 +170,6 @@ target_link_libraries(gm-companion-ui common commonplugin qml-icon-fonts - qml-icon-fontsplugin) + qml-icon-fontsplugin + Qt6::Qml + Qt6::Quick) diff --git a/app/ui/CustomComponents/CMakeLists.txt b/app/ui/CustomComponents/CMakeLists.txt index b345306d..28407033 100644 --- a/app/ui/CustomComponents/CMakeLists.txt +++ b/app/ui/CustomComponents/CMakeLists.txt @@ -16,6 +16,7 @@ qt_add_qml_module(gm-companion-ui-cc QML_FILES CustomButton.qml CustomComboBox.qml + CustomColorButton.qml CustomMenuItem.qml CustomRadioButton.qml CustomScrollLabel.qml diff --git a/app/ui/CustomComponents/CustomColorButton.qml b/app/ui/CustomComponents/CustomColorButton.qml new file mode 100644 index 00000000..1d2baa38 --- /dev/null +++ b/app/ui/CustomComponents/CustomColorButton.qml @@ -0,0 +1,37 @@ +import QtQuick +import IconFonts + +Rectangle { + id: root + + property bool enableReset: false + + signal clicked + signal resetClicked + + implicitWidth: 100 + implicitHeight: 40 + + color: "blue" + + border.width: mouse_area.containsMouse ? 1 : 0 + border.color: mouse_area.pressed ? CCColors.buttonPressed : palette.button + + MouseArea { + id: mouse_area + anchors.fill: parent + hoverEnabled: true + + onClicked: root.clicked() + } + + CustomButton { + visible: root.enableReset + anchors.right: parent.right + anchors.top: parent.top + anchors.bottom: parent.bottom + + iconText: FontAwesome.rotateLeft + onClicked: root.resetClicked() + } +} diff --git a/app/ui/CustomComponents/CustomToolBar.qml b/app/ui/CustomComponents/CustomToolBar.qml index 45c633e8..eb907968 100644 --- a/app/ui/CustomComponents/CustomToolBar.qml +++ b/app/ui/CustomComponents/CustomToolBar.qml @@ -1,5 +1,6 @@ import QtQuick import IconFonts +import common Rectangle { id: root @@ -62,7 +63,7 @@ Rectangle { Text { visible: !root.isSaved text: FontAwesome.asterisk - color: "darkred" + color: SettingsManager.colors.error font.family: FontAwesome.fontSolid.family font.styleName: FontAwesome.fontSolid.styleName anchors.right: parent.right diff --git a/app/ui/Main.qml b/app/ui/Main.qml index 5c797c3f..2fbf3da5 100644 --- a/app/ui/Main.qml +++ b/app/ui/Main.qml @@ -1,5 +1,4 @@ pragma ComponentBehavior: Bound - import QtQuick import QtQuick.Controls import IconFonts @@ -62,7 +61,7 @@ ApplicationWindow { target: UpdateManager function onUpdateAvailable() { - update_dialog.open() + update_dialog.open(); } } @@ -76,12 +75,11 @@ ApplicationWindow { Component.onCompleted: { if (SettingsManager.checkForUpdates) { - UpdateManager.checkForUpdates() + UpdateManager.checkForUpdates(); } - if (!SettingsManager.has("crashReports", "Telemetry")) { - console.debug("CrashReports preference has not been set.") - new_settings_dialog.open() + console.debug("CrashReports preference has not been set."); + new_settings_dialog.open(); } } @@ -143,7 +141,7 @@ ApplicationWindow { onClicked: setTool() function setTool() { - root.currentToolIndex = index + root.currentToolIndex = index; } } } @@ -156,17 +154,17 @@ ApplicationWindow { toolName: qsTr("Messages") faIcon: FontAwesome.circleExclamation - altColor: "orange" + altColor: SettingsManager.colors.warning useAltColor: MessageManager.hasNewErrors visible: message_dialog.hasMessages onClicked: { if (message_dialog.opened) { - message_dialog.close() + message_dialog.close(); } else { - message_dialog.open() - MessageManager.markAllAsRead() + message_dialog.open(); + MessageManager.markAllAsRead(); } } } @@ -179,7 +177,7 @@ ApplicationWindow { faIcon: FontAwesome.gear onClicked: { - root.currentToolIndex = -1 + root.currentToolIndex = -1; } } } @@ -191,8 +189,7 @@ ApplicationWindow { anchors.bottom: parent.bottom anchors.right: parent.right asynchronous: true - source: root.currentToolIndex - < 0 ? "tools/Settings.qml" : root.tools[root.currentToolIndex].source + source: root.currentToolIndex < 0 ? "tools/Settings.qml" : root.tools[root.currentToolIndex].source active: true onLoaded: splash.close() diff --git a/app/ui/Style/ComboBox.qml b/app/ui/Style/ComboBox.qml index b3680218..d7dcd554 100644 --- a/app/ui/Style/ComboBox.qml +++ b/app/ui/Style/ComboBox.qml @@ -44,7 +44,7 @@ T.ComboBox { contentItem: TextField { leftPadding: !control.mirrored ? 12 : control.editable && activeFocus ? 3 : 1 - rightPadding: control.mirrored ? 12 : control.editable && activeFocus ? 3 : 1 + rightPadding: control.mirrored ? 12 : control.editable && activeFocus ? 3 : 12 topPadding: 6 - control.padding bottomPadding: 6 - control.padding text: control.editable ? control.editText : control.displayText @@ -86,7 +86,7 @@ T.ComboBox { topMargin: 5 bottomMargin: 5 padding: 0 - modal: control && control.model && control.model.length + modal: control && control.model && control.model.length > 0 transformOrigin: Item.Top enter: Transition { diff --git a/app/ui/common/TreeViewItem.qml b/app/ui/common/TreeViewItem.qml index a630f490..12629ea0 100644 --- a/app/ui/common/TreeViewItem.qml +++ b/app/ui/common/TreeViewItem.qml @@ -1,5 +1,4 @@ pragma ComponentBehavior: Bound - import QtQuick import QtQuick.Controls import CustomComponents @@ -17,8 +16,7 @@ CustomButton { anchors.right: parent ? parent.right : undefined anchors.left: parent ? parent.left : undefined - anchors.leftMargin: modelData ? modelData.depth * 5 + (!modelData.canToggle - && itemIcon === "" ? 22 : 0) : 0 + anchors.leftMargin: modelData ? modelData.depth * 5 + (!modelData.canToggle && itemIcon === "" ? 22 : 0) : 0 iconText: modelData && modelData.canToggle ? (modelData.isOpen ? FontAwesome.caretDown : FontAwesome.caretRight) : itemIcon @@ -27,12 +25,12 @@ CustomButton { mainRow.spacing: checkbox.visible ? checkbox.width + 10 : 10 onClicked: { - modelData.toggle() + modelData.toggle(); } onRightClicked: { if (contextMenu) { - contextMenu.open() + contextMenu.open(); } } @@ -49,14 +47,14 @@ CustomButton { checkState: { switch (root.modelData ? root.modelData.isChecked : 0) { case 0: - Qt.Unchecked - break + Qt.Unchecked; + break; case 1: - Qt.PartiallyChecked - break + Qt.PartiallyChecked; + break; case 2: - Qt.Checked - break + Qt.Checked; + break; } } @@ -67,7 +65,7 @@ CustomButton { anchors.fill: parent onClicked: { - root.modelData.isChecked = root.modelData.isChecked < 2 ? 2 : 0 + root.modelData.isChecked = root.modelData.isChecked < 2 ? 2 : 0; } } } @@ -81,12 +79,12 @@ CustomButton { modal: true onOpened: { - rename_field.selectAll() - rename_field.forceActiveFocus() + rename_field.selectAll(); + rename_field.forceActiveFocus(); } onAccepted: { - root.modelData.rename(rename_field.text) + root.modelData.rename(rename_field.text); } contentItem: TextField { @@ -96,7 +94,7 @@ CustomButton { padding: 0 onAccepted: { - rename_dialog.accept() + rename_dialog.accept(); } } } @@ -111,12 +109,12 @@ CustomButton { modal: true onOpened: { - name_field.selectAll() - name_field.forceActiveFocus() + name_field.selectAll(); + name_field.forceActiveFocus(); } onAccepted: { - root.modelData.create(new_thing_dialog.type, name_field.text) + root.modelData.create(new_thing_dialog.type, name_field.text); } contentItem: TextField { @@ -125,7 +123,7 @@ CustomButton { placeholderText: qsTr("Name") onAccepted: { - new_thing_dialog.accept() + new_thing_dialog.accept(); } } } @@ -140,7 +138,7 @@ CustomButton { modal: true onAccepted: { - root.modelData.remove() + root.modelData.remove(); } contentItem: Item { @@ -156,7 +154,7 @@ CustomButton { width: parent.width / 2 - 5 onClicked: { - delete_dialog.accept() + delete_dialog.accept(); } } @@ -198,10 +196,10 @@ CustomButton { text: qsTr("New") + " " + modelData + " ..." onTriggered: { - new_thing_dialog.title = text - new_thing_dialog.type = modelData - new_thing_dialog.y = y - new_thing_dialog.open() + new_thing_dialog.title = text; + new_thing_dialog.type = modelData; + new_thing_dialog.y = y; + new_thing_dialog.open(); } } } @@ -209,10 +207,10 @@ CustomButton { CustomMenuItem { id: delete_item text: qsTr("Delete") - textColor: "darkred" + textColor: SettingsManager.colors.error onTriggered: { - delete_dialog.open() + delete_dialog.open(); } } } diff --git a/app/ui/main/MessageDialog.qml b/app/ui/main/MessageDialog.qml index 67776fdf..ed46a432 100644 --- a/app/ui/main/MessageDialog.qml +++ b/app/ui/main/MessageDialog.qml @@ -2,6 +2,7 @@ import QtQuick import QtQuick.Controls import IconFonts import src +import common Dialog { id: root @@ -72,16 +73,16 @@ Dialog { color: "transparent" border.color: switch (type) { - case 1: - "orange" - break - case 2: - case 3: - "red" - break - default: - palette.button - } + case 1: + SettingsManager.colors.warning; + break; + case 2: + case 3: + SettingsManager.colors.error; + break; + default: + palette.button; + } border.width: 1 height: header.height + text_field.height @@ -124,9 +125,7 @@ Dialog { anchors.top: parent.top anchors.bottom: parent.bottom - text: message_box.timestamp.toLocaleString( - Qt.locale("en_US"), - Locale.ShortFormat) + text: message_box.timestamp.toLocaleString(Qt.locale("en_US"), Locale.ShortFormat) font.pointSize: 10 wrapMode: Label.NoWrap verticalAlignment: Text.AlignVCenter @@ -157,7 +156,8 @@ Dialog { wrapMode: Label.WrapAtWordBoundaryOrAnywhere readOnly: true selectByMouse: true - background: Item {} + background: Item { + } } } } diff --git a/app/ui/main/SideMenuButton.qml b/app/ui/main/SideMenuButton.qml index e0dd13c2..57b73d4f 100644 --- a/app/ui/main/SideMenuButton.qml +++ b/app/ui/main/SideMenuButton.qml @@ -9,7 +9,7 @@ Button { property string toolName property string faIcon - property string altColor + property color altColor property bool currentTool: false property bool useAltColor: false @@ -18,7 +18,8 @@ Button { height: Sizes.toolbarHeight hoverEnabled: true - background: Item {} + background: Item { + } font.bold: false diff --git a/app/ui/tools/Dice.qml b/app/ui/tools/Dice.qml index 864d0f73..467ecdd4 100644 --- a/app/ui/tools/Dice.qml +++ b/app/ui/tools/Dice.qml @@ -4,6 +4,7 @@ import QtQuick.Controls import CustomComponents import IconFonts import src +import common import ".." import "./dice" import "../common" @@ -20,19 +21,19 @@ Page { target: DiceTool function onMixedCriticalResult() { - roll_result.color = "orange"; + roll_result.color = SettingsManager.colors.warning; roll_result_help.visible = true; roll_result_help.helpText = qsTr("Result contained both critical failures and successes"); } function onSuccessfulCriticalResult() { - roll_result.color = "green"; + roll_result.color = SettingsManager.colors.success; roll_result_help.visible = true; roll_result_help.helpText = qsTr("Result contained at least one critical success"); } function onFailedCriticalResult() { - roll_result.color = "red"; + roll_result.color = SettingsManager.colors.error; roll_result_help.visible = true; roll_result_help.helpText = qsTr("Result contained at least one critical failure"); } diff --git a/app/ui/tools/DiceAlt.qml b/app/ui/tools/DiceAlt.qml index bbfd2186..bfca1b8e 100644 --- a/app/ui/tools/DiceAlt.qml +++ b/app/ui/tools/DiceAlt.qml @@ -2,6 +2,7 @@ import QtQuick import QtQuick.Controls import IconFonts import src +import common import "../common" Item { @@ -12,29 +13,26 @@ Item { target: DiceTool function onMixedCriticalResult() { - roll_result.color = "orange" - roll_result_help.visible = true - roll_result_help.helpText = qsTr( - "Result contained both critical failures and successes") + roll_result.color = SettingsManager.colors.warning; + roll_result_help.visible = true; + roll_result_help.helpText = qsTr("Result contained both critical failures and successes"); } function onSuccessfulCriticalResult() { - roll_result.color = "green" - roll_result_help.visible = true - roll_result_help.helpText = qsTr( - "Result contained at least one critical success") + roll_result.color = SettingsManager.colors.success; + roll_result_help.visible = true; + roll_result_help.helpText = qsTr("Result contained at least one critical success"); } function onFailedCriticalResult() { - roll_result.color = "red" - roll_result_help.visible = true - roll_result_help.helpText = qsTr( - "Result contained at least one critical failure") + roll_result.color = SettingsManager.colors.error; + roll_result_help.visible = true; + roll_result_help.helpText = qsTr("Result contained at least one critical failure"); } function onNormalResult() { - roll_result.color = dice_page.palette.text - roll_result_help.visible = false + roll_result.color = dice_page.palette.text; + roll_result_help.visible = false; } } @@ -115,7 +113,7 @@ Item { hoverEnabled: true onClicked: { - DiceTool.roll() + DiceTool.roll(); } } diff --git a/app/ui/tools/audio/VolumeSlider.qml b/app/ui/tools/audio/VolumeSlider.qml index e8cad20c..b03d39c3 100644 --- a/app/ui/tools/audio/VolumeSlider.qml +++ b/app/ui/tools/audio/VolumeSlider.qml @@ -21,7 +21,7 @@ Slider { implicitWidth: 26 implicitHeight: 26 radius: 13 - color: slider.pressed ? palette.light : palette.midlight + color: slider.pressed ? palette.text : palette.midlight border.color: palette.dark Text { diff --git a/app/ui/tools/audio/editor/EditorElementColumn.qml b/app/ui/tools/audio/editor/EditorElementColumn.qml index 6e3bdac7..3f830bfb 100644 --- a/app/ui/tools/audio/editor/EditorElementColumn.qml +++ b/app/ui/tools/audio/editor/EditorElementColumn.qml @@ -24,8 +24,7 @@ Pane { clip: true spacing: 10 - model: (AudioTool.editor.currentProject - && AudioTool.editor.currentProject.currentScenario) ? AudioTool.editor.currentProject.currentScenario.model : [] + model: (AudioTool.editor.currentProject && AudioTool.editor.currentProject.currentScenario) ? AudioTool.editor.currentProject.currentScenario.model : [] ScrollBar.vertical: ScrollBar { id: scroll_bar @@ -48,7 +47,9 @@ Pane { anchors.right: parent.right height: subscenario_text.height + 4 visible: elements_column.modelData.isSubscenario - color: palette.button + color: palette.dark + border.color: palette.button + border.width: 1 Label { id: subscenario_text @@ -94,11 +95,11 @@ Pane { anchors.margins: 0 pointSize: 10 onClicked: { - root.deleteDialog.x = root.width - root.deleteDialog.y = Sizes.toolbarHeight - root.deleteDialog.mode = 3 - root.deleteDialog.element = elements_column.modelData - root.deleteDialog.open() + root.deleteDialog.x = root.width; + root.deleteDialog.y = Sizes.toolbarHeight; + root.deleteDialog.mode = 3; + root.deleteDialog.element = elements_column.modelData; + root.deleteDialog.open(); } } } @@ -123,7 +124,7 @@ Pane { anchors.right: elements_column.right onClicked: { - AudioTool.editor.loadElement(modelData) + AudioTool.editor.loadElement(modelData); } } } diff --git a/app/ui/tools/audio/editor/EditorHeader.qml b/app/ui/tools/audio/editor/EditorHeader.qml index 409c7f35..342e957d 100644 --- a/app/ui/tools/audio/editor/EditorHeader.qml +++ b/app/ui/tools/audio/editor/EditorHeader.qml @@ -4,6 +4,7 @@ import QtQuick.Controls import CustomComponents import IconFonts import src +import common import "./dialogs" import "../audio_exporter" @@ -214,7 +215,7 @@ CustomToolBar { CustomToolBarButton { iconText: FontAwesome.fileAudio - iconColor: "darkred" + iconColor: SettingsManager.colors.error toolTipText: qsTr("Remove missing files") diff --git a/app/ui/tools/audio/editor/dialogs/EditorNewThingDialog.qml b/app/ui/tools/audio/editor/dialogs/EditorNewThingDialog.qml index 6e2d7006..71af42da 100644 --- a/app/ui/tools/audio/editor/dialogs/EditorNewThingDialog.qml +++ b/app/ui/tools/audio/editor/dialogs/EditorNewThingDialog.qml @@ -3,6 +3,7 @@ import QtQuick.Controls import CustomComponents import IconFonts import src +import common Dialog { id: root @@ -137,7 +138,7 @@ Dialog { font.family: FontAwesome.fontSolid.family font.styleName: FontAwesome.fontSolid.styleName font.pointSize: 12 - color: "red" + color: SettingsManager.colors.error } } } diff --git a/app/ui/tools/audio/editor/views/element_properties/ElementNameView.qml b/app/ui/tools/audio/editor/views/element_properties/ElementNameView.qml index a57d28a8..0314af11 100644 --- a/app/ui/tools/audio/editor/views/element_properties/ElementNameView.qml +++ b/app/ui/tools/audio/editor/views/element_properties/ElementNameView.qml @@ -1,10 +1,10 @@ pragma ComponentBehavior: Bound - import QtQuick import QtQuick.Controls import CustomComponents import IconFonts import src +import common import "../../../../.." Item { @@ -23,7 +23,7 @@ Item { target: AudioTool.editor function onCurrentElementChanged() { - element_name_field.text = AudioTool.editor.currentElement ? AudioTool.editor.currentElement.name : "" // qmllint disable missing-property + element_name_field.text = AudioTool.editor.currentElement ? AudioTool.editor.currentElement.name : ""; // qmllint disable missing-property } } @@ -48,18 +48,17 @@ Item { text: qsTr("No Subscenario") onClicked: { - AudioTool.editor.setSubscenario(-1) - subscenario_dialog.accept() + AudioTool.editor.setSubscenario(-1); + subscenario_dialog.accept(); } } Repeater { model: { - if (AudioTool.editor.currentProject - && AudioTool.editor.currentProject.currentScenario) { - AudioTool.editor.currentProject.currentScenario.scenarios + if (AudioTool.editor.currentProject && AudioTool.editor.currentProject.currentScenario) { + AudioTool.editor.currentProject.currentScenario.scenarios; } else { - [] + []; } } @@ -73,8 +72,8 @@ Item { text: modelData.name // qmllint disable missing-property onClicked: { - AudioTool.editor.setSubscenario(index) - subscenario_dialog.accept() + AudioTool.editor.setSubscenario(index); + subscenario_dialog.accept(); } } } @@ -104,7 +103,7 @@ Item { text: element_name_field.edit_mode ? FontAwesome.circleCheck : FontAwesome.chevronUp font.family: FontAwesome.fontSolid.family font.styleName: FontAwesome.fontSolid.styleName - color: element_name_field.edit_mode ? "limegreen" : palette.text + color: element_name_field.edit_mode ? SettingsManager.colors.success : palette.text anchors.fill: parent verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter @@ -112,15 +111,13 @@ Item { onClicked: { if (element_name_field.edit_mode) { - element_name_field.edit_mode = false - + element_name_field.edit_mode = false; if (AudioTool.editor.currentElement) { - AudioTool.editor.currentElement.name = element_name_field.text + AudioTool.editor.currentElement.name = element_name_field.text; } - - element_up_down.visible = enableMoveButtons + element_up_down.visible = enableMoveButtons; } else { - AudioTool.editor.moveElement(AudioTool.editor.currentElement, -1) + AudioTool.editor.moveElement(AudioTool.editor.currentElement, -1); } } } @@ -140,7 +137,7 @@ Item { text: element_name_field.edit_mode ? FontAwesome.circleXmark : FontAwesome.chevronDown font.family: FontAwesome.fontSolid.family font.styleName: FontAwesome.fontSolid.styleName - color: element_name_field.edit_mode ? "red" : palette.text + color: element_name_field.edit_mode ? SettingsManager.colors.error : palette.text anchors.fill: parent verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter @@ -148,11 +145,11 @@ Item { onClicked: { if (element_name_field.edit_mode) { - element_name_field.edit_mode = false - element_name_field.text = AudioTool.editor.currentElement ? AudioTool.editor.currentElement.name : "" // qmllint disable missing-property - element_up_down.visible = root.enableMoveButtons + element_name_field.edit_mode = false; + element_name_field.text = AudioTool.editor.currentElement ? AudioTool.editor.currentElement.name : ""; // qmllint disable missing-property + element_up_down.visible = root.enableMoveButtons; } else { - AudioTool.editor.moveElement(AudioTool.editor.currentElement, 1) + AudioTool.editor.moveElement(AudioTool.editor.currentElement, 1); } } } @@ -188,9 +185,7 @@ Item { activeFocusOnPress: edit_mode focus: edit_mode - rightPadding: leftPadding - + (element_delete_button.visible ? element_delete_button.width : 0) - + (element_edit_name_button.visible ? element_edit_name_button.width : 0) + rightPadding: leftPadding + (element_delete_button.visible ? element_delete_button.width : 0) + (element_edit_name_button.visible ? element_edit_name_button.width : 0) CustomToolBarButton { id: element_edit_name_button @@ -203,8 +198,8 @@ Item { pointSize: 12 onClicked: { - element_up_down.visible = true - element_name_field.edit_mode = true + element_up_down.visible = true; + element_name_field.edit_mode = true; } } @@ -266,17 +261,16 @@ Item { text: FontAwesome.circleCheck font.family: FontAwesome.fontSolid.family font.styleName: FontAwesome.fontSolid.styleName - color: "limegreen" + color: SettingsManager.colors.success anchors.fill: parent verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter } onClicked: { - root.deleteClicked() - element_delete_overlay.visible = false - - AudioTool.editor.deleteCurrentElement() + root.deleteClicked(); + element_delete_overlay.visible = false; + AudioTool.editor.deleteCurrentElement(); } } @@ -294,14 +288,14 @@ Item { text: FontAwesome.circleXmark font.family: FontAwesome.fontSolid.family font.styleName: FontAwesome.fontSolid.styleName - color: "red" + color: SettingsManager.colors.error anchors.fill: parent verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter } onClicked: { - element_delete_overlay.visible = false + element_delete_overlay.visible = false; } } } diff --git a/app/ui/tools/audio/editor/views/element_properties/PlaybackModeView.qml b/app/ui/tools/audio/editor/views/element_properties/PlaybackModeView.qml index 27206a46..f055569a 100644 --- a/app/ui/tools/audio/editor/views/element_properties/PlaybackModeView.qml +++ b/app/ui/tools/audio/editor/views/element_properties/PlaybackModeView.qml @@ -3,6 +3,7 @@ import QtQuick.Controls import IconFonts import CustomComponents import src +import common import "../../../../.." Rectangle { @@ -26,8 +27,7 @@ Rectangle { toolTipText: qsTr("Playlist is shuffled before playing. Loops.") iconText: FontAwesome.listOl pointSize: 18 - iconColor: AudioTool.editor.currentElement - && AudioTool.editor.currentElement.mode === 0 ? "green" : palette.text + iconColor: AudioTool.editor.currentElement && AudioTool.editor.currentElement.mode === 0 ? SettingsManager.colors.success : palette.text Label { text: FontAwesome.shuffle @@ -40,8 +40,7 @@ Rectangle { x: parent.width - width * 1.5 y: parent.height - height * 1.5 - color: AudioTool.editor.currentElement && AudioTool.editor.currentElement.mode - === parent.modeNum ? "limegreen" : (parent.pressed ? "grey" : parent.hovered ? "lightgrey" : "white") + color: AudioTool.editor.currentElement && AudioTool.editor.currentElement.mode === parent.modeNum ? SettingsManager.colors.success : (parent.pressed ? "grey" : parent.hovered ? "lightgrey" : "white") background: Rectangle { radius: 5 @@ -57,8 +56,7 @@ Rectangle { toolTipText: qsTr("Files are played randomly, does not stop.") iconText: FontAwesome.shuffle pointSize: 18 - iconColor: AudioTool.editor.currentElement - && AudioTool.editor.currentElement.mode === modeNum ? "green" : palette.text + iconColor: AudioTool.editor.currentElement && AudioTool.editor.currentElement.mode === modeNum ? SettingsManager.colors.success : palette.text onClicked: AudioTool.editor.currentElement.mode = modeNum } @@ -69,8 +67,7 @@ Rectangle { toolTipText: qsTr("Playlist loops in sequential order.") iconText: FontAwesome.listOl pointSize: 18 - iconColor: AudioTool.editor.currentElement - && AudioTool.editor.currentElement.mode === 2 ? "green" : palette.text + iconColor: AudioTool.editor.currentElement && AudioTool.editor.currentElement.mode === 2 ? SettingsManager.colors.success : palette.text Label { text: FontAwesome.rotate @@ -83,9 +80,7 @@ Rectangle { x: parent.width - width * 1.5 y: parent.height - height * 1.5 - color: AudioTool.editor.currentElement - && AudioTool.editor.currentElement.mode - === parent.modeNum ? "limegreen" : (parent.pressed ? "grey" : parent.hovered ? "lightgrey" : "white") + color: AudioTool.editor.currentElement && AudioTool.editor.currentElement.mode === parent.modeNum ? SettingsManager.colors.success : (parent.pressed ? "grey" : parent.hovered ? "lightgrey" : "white") background: Rectangle { radius: 5 @@ -101,8 +96,7 @@ Rectangle { toolTipText: qsTr("Playlist is played in set order. Does not loop.") iconText: FontAwesome.listOl pointSize: 18 - iconColor: AudioTool.editor.currentElement - && AudioTool.editor.currentElement.mode === modeNum ? "green" : palette.text + iconColor: AudioTool.editor.currentElement && AudioTool.editor.currentElement.mode === modeNum ? SettingsManager.colors.success : palette.text onClicked: AudioTool.editor.currentElement.mode = modeNum } diff --git a/app/ui/tools/characters/classic/ImageControlBar.qml b/app/ui/tools/characters/classic/ImageControlBar.qml index 4865ce33..2ff3452a 100644 --- a/app/ui/tools/characters/classic/ImageControlBar.qml +++ b/app/ui/tools/characters/classic/ImageControlBar.qml @@ -59,17 +59,6 @@ Rectangle { onMoved: root.setScale(value) - handle: Rectangle { - x: scale_slider.leftPadding + scale_slider.availableWidth / 2 - width / 2 - y: scale_slider.bottomPadding + scale_slider.visualPosition - * (scale_slider.availableHeight - height) - implicitWidth: 26 - implicitHeight: 26 - radius: 13 - color: scale_slider.pressed ? palette.light : palette.midlight - border.color: palette.dark - } - background: Rectangle { anchors.horizontalCenter: parent.horizontalCenter y: scale_slider.topPadding diff --git a/app/ui/tools/combat_tracker/ListSpinBox.qml b/app/ui/tools/combat_tracker/ListSpinBox.qml index 5f70f1aa..e7438894 100644 --- a/app/ui/tools/combat_tracker/ListSpinBox.qml +++ b/app/ui/tools/combat_tracker/ListSpinBox.qml @@ -1,6 +1,7 @@ import QtQuick import QtQuick.Controls import IconFonts +import common import "../.." Item { @@ -67,7 +68,7 @@ Item { anchors.right: parent.right anchors.margins: 10 font.pixelSize: parent.height - 30 - color: "green" + color: SettingsManager.colors.success } MouseArea { diff --git a/app/ui/tools/converter/ConverterEditorNewThingDialog.qml b/app/ui/tools/converter/ConverterEditorNewThingDialog.qml index 17ec993e..606fbe41 100644 --- a/app/ui/tools/converter/ConverterEditorNewThingDialog.qml +++ b/app/ui/tools/converter/ConverterEditorNewThingDialog.qml @@ -10,9 +10,9 @@ Dialog { modal: true enum Mode { - Project = 0, - Category = 1, - Unit = 2 + Project, + Category, + Unit } property bool canAccept: true @@ -21,26 +21,25 @@ Dialog { function updateCanAccept() { if (!ConverterTool.editor) { - canAccept = false - return + canAccept = false; + return; } - switch (currentMode) { case ConverterEditorNewThingDialog.Mode.Project: - canAccept = true - break + canAccept = true; + break; case ConverterEditorNewThingDialog.Mode.Category: - canAccept = ConverterTool.editor.currentProject - error_label.text = qsTr("No Project!") - break + canAccept = ConverterTool.editor.currentProject; + error_label.text = qsTr("No Project!"); + break; case ConverterEditorNewThingDialog.Mode.Unit: - canAccept = ConverterTool.editor.currentCategory - error_label.text = qsTr("No Category!") - break + canAccept = ConverterTool.editor.currentCategory; + error_label.text = qsTr("No Category!"); + break; default: - canAccept = false - error_label.text = qsTr("Unknown Error") - break + canAccept = false; + error_label.text = qsTr("Unknown Error"); + break; } } @@ -53,8 +52,8 @@ Dialog { width: name_field.width onCurrentIndexChanged: { - root.updateCanAccept() - name_field.forceActiveFocus() + root.updateCanAccept(); + name_field.forceActiveFocus(); } } @@ -66,12 +65,11 @@ Dialog { visible: root.canAccept onAccepted: { if (root.currentMode !== ConverterEditorNewThingDialog.Mode.Unit) { - root.accept() - return + root.accept(); + return; } - if (value_field.acceptableInput) { - root.accept() + root.accept(); } } } @@ -83,8 +81,7 @@ Dialog { selectByMouse: true onAccepted: root.accept() enabled: root.canAccept - visible: root.canAccept - && root.currentMode === ConverterEditorNewThingDialog.Mode.Unit + visible: root.canAccept && root.currentMode === ConverterEditorNewThingDialog.Mode.Unit validator: DoubleValidator { notation: DoubleValidator.ScientificNotation @@ -110,7 +107,7 @@ Dialog { font.family: FontAwesome.fontSolid.family font.styleName: FontAwesome.fontSolid.styleName font.pointSize: 12 - color: "red" + color: SettingsManager.colors.error } } } @@ -118,31 +115,28 @@ Dialog { standardButtons: Dialog.Ok | Dialog.Cancel onOpened: { - type_combo_box.currentIndex = lastMode - - name_field.forceActiveFocus() + type_combo_box.currentIndex = lastMode; + name_field.forceActiveFocus(); } onAccepted: { if (name_field.text !== "" && canAccept) { - switch (currentMode) { case ConverterEditorNewThingDialog.Mode.Project: - ConverterTool.editor.createProject(name_field.text) - break + ConverterTool.editor.createProject(name_field.text); + break; case ConverterEditorNewThingDialog.Mode.Category: - ConverterTool.editor.createCategory(name_field.text) - break + ConverterTool.editor.createCategory(name_field.text); + break; case ConverterEditorNewThingDialog.Mode.Unit: - ConverterTool.editor.createUnit(name_field.text, value_field.text) - break + ConverterTool.editor.createUnit(name_field.text, value_field.text); + break; } } - - name_field.clear() + name_field.clear(); } onClosed: { - lastMode = currentMode + lastMode = currentMode; } } diff --git a/app/ui/tools/dice/DiceButton.qml b/app/ui/tools/dice/DiceButton.qml index 50f8282c..69929146 100644 --- a/app/ui/tools/dice/DiceButton.qml +++ b/app/ui/tools/dice/DiceButton.qml @@ -1,6 +1,7 @@ import QtQuick import QtQuick.Controls import QtQuick.Effects +import common Button { id: root @@ -12,7 +13,8 @@ Button { width: height - background: Item {} + background: Item { + } Image { id: image @@ -27,7 +29,7 @@ Button { anchors.fill: image source: image colorization: 1 - colorizationColor: parent.pressed ? "grey" : root.isCurrentType ? "tomato" : "white" + colorizationColor: parent.pressed ? "grey" : root.isCurrentType ? SettingsManager.colors.error : "white" } ToolTip.text: toolTipText diff --git a/app/ui/tools/maps/MapMarkerEditor.qml b/app/ui/tools/maps/MapMarkerEditor.qml index 9ae75948..cc1718e9 100644 --- a/app/ui/tools/maps/MapMarkerEditor.qml +++ b/app/ui/tools/maps/MapMarkerEditor.qml @@ -159,25 +159,15 @@ Dialog { Repeater { model: ["orange", "red", "crimson", "darkred", "blueviolet", "blue", "cornflowerblue", "dodgerblue", "deepskyblue", "cadetblue", "green", "limegreen", "yellowgreen", "chartreuse", "gold", "yellow", "khaki", "moccasin", "darkslategray", "slategrey", "grey", "silver", "lightsteelblue", "lightgrey"] - Rectangle { - id: color_delegate + CustomColorButton { required property string modelData + color: modelData width: (parent.width - color_grid.spacing * 3) / 4 height: width - color: modelData - border.width: color_mouse_area.containsMouse ? 2 : 0 - border.color: color_mouse_area.pressed ? Colors.buttonPressed : palette.button - - MouseArea { - id: color_mouse_area - anchors.fill: parent - hoverEnabled: true - - onClicked: { - color_field.text = color_delegate.modelData; - } + onClicked: { + color_field.text = modelData; } } } diff --git a/app/ui/tools/maps/MapViewerControlBar.qml b/app/ui/tools/maps/MapViewerControlBar.qml index d87d7dff..0d5ac37d 100644 --- a/app/ui/tools/maps/MapViewerControlBar.qml +++ b/app/ui/tools/maps/MapViewerControlBar.qml @@ -55,17 +55,6 @@ Column { onMoved: root.setScale(value) - handle: Rectangle { - x: scale_slider.leftPadding + scale_slider.availableWidth / 2 - width / 2 - y: scale_slider.bottomPadding + scale_slider.visualPosition - * (scale_slider.availableHeight - height) - implicitWidth: 26 - implicitHeight: 26 - radius: 13 - color: scale_slider.pressed ? palette.light : palette.midlight - border.color: palette.dark - } - background: Rectangle { anchors.horizontalCenter: parent.horizontalCenter y: scale_slider.topPadding diff --git a/app/ui/tools/settings/GeneralPage.qml b/app/ui/tools/settings/GeneralPage.qml index 49392c61..52cc7b61 100644 --- a/app/ui/tools/settings/GeneralPage.qml +++ b/app/ui/tools/settings/GeneralPage.qml @@ -1,185 +1,414 @@ import QtQuick import QtQuick.Controls +import QtQuick.Dialogs +import CustomComponents +import IconFonts import common import "../../common" -Column { - id: general_column - spacing: 20 - padding: 10 +SplitView { + id: root - // Language - Column { - spacing: 10 + handle: Item { + } - Label { - text: qsTr("Language") - font.bold: true - } + ColorDialog { + id: color_dialog + title: qsTr("Choose a color") + } - Row { + Column { + id: left_column + spacing: 20 + padding: 10 + + // UI + Column { spacing: 10 Label { - text: qsTr("Select Language") - width: language_box.width - anchors.verticalCenter: parent.verticalCenter + text: qsTr("User Interface") + font.bold: true } - ComboBox { - id: language_box + Row { + spacing: 10 + + Label { + text: qsTr("Select Language") + width: Math.max(implicitWidth, language_box.width) + anchors.verticalCenter: parent.verticalCenter + } + + ComboBox { + id: language_box - property bool loaded: false + property bool loaded: false - model: SettingsManager.getLanguageNames() - width: general_column.width / 6 + model: SettingsManager.getLanguageNames() - onCurrentTextChanged: { - if (loaded) { - SettingsManager.setLanguage(currentText) + onCurrentTextChanged: { + if (loaded) { + SettingsManager.setLanguage(currentText); + } } - } - Component.onCompleted: { - currentIndex = SettingsManager.getLanguageIndex() - loaded = true + Component.onCompleted: { + currentIndex = SettingsManager.getLanguageIndex(); + loaded = true; + } } } - } - } - // UI - Column { - spacing: 10 + // Show Tool Names + CheckBox { + text: qsTr("Show tool names in menu") + checked: SettingsManager.showToolNames + onClicked: SettingsManager.showToolNames = checked + } - Label { - text: qsTr("User Interface") - font.bold: true - } + Row { + spacing: 10 - // Show Tool Names - CheckBox { - text: qsTr("Show tool names in menu") - checked: SettingsManager.showToolNames - onClicked: SettingsManager.showToolNames = checked - } - } + CustomColorButton { + color: SettingsManager.colors.info + enableReset: true - // Telemetry - Column { - spacing: 10 + property bool active: false - Label { - text: qsTr("Telemetry") - font.bold: true - } + function saveColor() { + if (!active) + return; + disconnect(); + SettingsManager.colors.info = color_dialog.selectedColor; + } - // Crash Reports - Row { - CheckBox { - text: qsTr("Automated crash reports") - checked: SettingsManager.crashReports - onClicked: SettingsManager.crashReports = checked - } + function disconnect() { + color_dialog.accepted.disconnect(saveColor); + color_dialog.rejected.disconnect(disconnect); + active = false; + } + + onClicked: { + active = true; + color_dialog.accepted.connect(saveColor); + color_dialog.rejected.connect(disconnect); + color_dialog.selectedColor = SettingsManager.colors.info; + color_dialog.open(); + } + + onResetClicked: SettingsManager.colors.resetInfo() + } + + Label { + font.family: FontAwesome.fontSolid.family + font.styleName: FontAwesome.fontSolid.styleName + font.pointSize: 12 + verticalAlignment: Text.AlignVCenter + anchors.verticalCenter: parent.verticalCenter + + color: SettingsManager.colors.info + text: FontAwesome.circleInfo + } - HelpAnnotation { - anchors.verticalCenter: parent.verticalCenter - helpText: qsTr("When the application crashes, a report will be uploaded to sentry.io \nso that the issue can be fixed in a future release.") + Label { + anchors.verticalCenter: parent.verticalCenter + verticalAlignment: Text.AlignVCenter + text: qsTr("Info") + } } - } - // Session Tracking - Row { - CheckBox { - text: qsTr("Session tracking") - checked: SettingsManager.sessionTracking - onClicked: SettingsManager.sessionTracking = checked + Row { + spacing: 10 + + CustomColorButton { + color: SettingsManager.colors.success + enableReset: true + + property bool active: false + + function saveColor() { + if (!active) + return; + disconnect(); + SettingsManager.colors.success = color_dialog.selectedColor; + } + + function disconnect() { + color_dialog.accepted.disconnect(saveColor); + color_dialog.rejected.disconnect(disconnect); + active = false; + } + + onClicked: { + active = true; + color_dialog.accepted.connect(saveColor); + color_dialog.rejected.connect(disconnect); + color_dialog.selectedColor = SettingsManager.colors.success; + color_dialog.open(); + } + + onResetClicked: SettingsManager.colors.resetSuccess() + } + + Label { + font.family: FontAwesome.fontSolid.family + font.styleName: FontAwesome.fontSolid.styleName + font.pointSize: 12 + verticalAlignment: Text.AlignVCenter + anchors.verticalCenter: parent.verticalCenter + + color: SettingsManager.colors.success + text: FontAwesome.circleCheck + } + + Label { + anchors.verticalCenter: parent.verticalCenter + verticalAlignment: Text.AlignVCenter + text: qsTr("Success") + } } - HelpAnnotation { - anchors.verticalCenter: parent.verticalCenter - helpText: qsTr("The application will keep track of how long it is used and if any errors occured. \nIt will then send an anonymous report to sentry.io so that we know how stable the application is.") + Row { + spacing: 10 + + CustomColorButton { + color: SettingsManager.colors.warning + enableReset: true + + property bool active: false + + function saveColor() { + if (!active) + return; + disconnect(); + SettingsManager.colors.warning = color_dialog.selectedColor; + } + + function disconnect() { + color_dialog.accepted.disconnect(saveColor); + color_dialog.rejected.disconnect(disconnect); + active = false; + } + + onClicked: { + active = true; + color_dialog.accepted.connect(saveColor); + color_dialog.rejected.connect(disconnect); + color_dialog.selectedColor = SettingsManager.colors.warning; + color_dialog.open(); + } + + onResetClicked: SettingsManager.colors.resetWarning() + } + + Label { + font.family: FontAwesome.fontSolid.family + font.styleName: FontAwesome.fontSolid.styleName + font.pointSize: 12 + verticalAlignment: Text.AlignVCenter + anchors.verticalCenter: parent.verticalCenter + + color: SettingsManager.colors.warning + text: FontAwesome.triangleExclamation + } + + Label { + anchors.verticalCenter: parent.verticalCenter + verticalAlignment: Text.AlignVCenter + text: qsTr("Warning") + } } - } - } - // Updates - Connections { - target: UpdateManager + Row { + spacing: 10 - function onUpdateAvailable() { - update_text.text = qsTr( - "Found new Version: ") + UpdateManager.newestVersion - update_text.visible = true - open_downloads_button.visible = true - update_busy_indicator.visible = false - } + CustomColorButton { + color: SettingsManager.colors.error + enableReset: true + + property bool active: false + + function saveColor() { + if (!active) + return; + disconnect(); + SettingsManager.colors.error = color_dialog.selectedColor; + } + + function disconnect() { + color_dialog.accepted.disconnect(saveColor); + color_dialog.rejected.disconnect(disconnect); + active = false; + } + + onClicked: { + active = true; + color_dialog.accepted.connect(saveColor); + color_dialog.rejected.connect(disconnect); + color_dialog.selectedColor = SettingsManager.colors.error; + color_dialog.open(); + } + + onResetClicked: SettingsManager.colors.resetError() + } + + Label { + font.family: FontAwesome.fontSolid.family + font.styleName: FontAwesome.fontSolid.styleName + font.pointSize: 12 + verticalAlignment: Text.AlignVCenter + anchors.verticalCenter: parent.verticalCenter - function onNoUpdateAvailable() { - update_text.text = qsTr("No newer version found") - update_text.visible = true - update_busy_indicator.visible = false + color: SettingsManager.colors.error + text: FontAwesome.circleExclamation + } + + Label { + anchors.verticalCenter: parent.verticalCenter + verticalAlignment: Text.AlignVCenter + text: qsTr("Error") + } + } } } Column { - spacing: 10 + id: right_column + spacing: 20 + padding: 10 + + // Telemetry + Column { + spacing: 10 + + Label { + text: qsTr("Telemetry") + font.bold: true + } + + // Crash Reports + Row { + CheckBox { + text: qsTr("Automated crash reports") + checked: SettingsManager.crashReports + onClicked: SettingsManager.crashReports = checked + } + + HelpAnnotation { + anchors.verticalCenter: parent.verticalCenter + helpText: qsTr("When the application crashes, a report will be uploaded to sentry.io \nso that the issue can be fixed in a future release.") + } + } + + // Session Tracking + Row { + CheckBox { + text: qsTr("Session tracking") + checked: SettingsManager.sessionTracking + onClicked: SettingsManager.sessionTracking = checked + } - Label { - text: qsTr("Updates") - font.bold: true + HelpAnnotation { + anchors.verticalCenter: parent.verticalCenter + helpText: qsTr("The application will keep track of how long it is used and if any errors occured. \nIt will then send an anonymous report to sentry.io so that we know how stable the application is.") + } + } } - Row { - CheckBox { - text: qsTr("Automatically check for updates") - checked: SettingsManager.checkForUpdates - onClicked: SettingsManager.checkForUpdates = checked + // Updates + Connections { + target: UpdateManager + + function onUpdateAvailable() { + update_text.text = qsTr("Found new Version: ") + UpdateManager.newestVersion; + update_text.visible = true; + update_icon.text = FontAwesome.circleInfo; + update_icon.color = SettingsManager.colors.info; + open_downloads_button.visible = true; + update_busy_indicator.visible = false; } - HelpAnnotation { - anchors.verticalCenter: parent.verticalCenter - helpText: qsTr("If enabled, the application will automatically check if there are any updates available and notify you if that is the case.\nThis is disabled by default if you installed the application through a package manager.") + function onNoUpdateAvailable() { + update_text.text = qsTr("No newer version found"); + update_text.visible = true; + update_icon.text = FontAwesome.circleCheck; + update_icon.color = SettingsManager.colors.success; + update_busy_indicator.visible = false; } } - Row { - spacing: 5 + Column { + spacing: 10 - Button { - id: check_for_updates_button - text: qsTr("Check for Updates") + Label { + text: qsTr("Updates") + font.bold: true + } - onClicked: { - update_text.visible = false - update_busy_indicator.visible = true - UpdateManager.checkForUpdates() + Row { + CheckBox { + text: qsTr("Automatically check for updates") + checked: SettingsManager.checkForUpdates + onClicked: SettingsManager.checkForUpdates = checked } - } - BusyIndicator { - id: update_busy_indicator - visible: false - width: check_for_updates_button.height - height: width + HelpAnnotation { + anchors.verticalCenter: parent.verticalCenter + helpText: qsTr("If enabled, the application will automatically check if there are any updates available and notify you if that is the case.\nThis is disabled by default if you installed the application through a package manager.") + } } - Label { - id: update_text - anchors.verticalCenter: parent.verticalCenter - visible: false - color: "green" + Row { + spacing: 5 + + Button { + id: check_for_updates_button + text: qsTr("Check for Updates") + + onClicked: { + update_text.visible = false; + update_busy_indicator.visible = true; + UpdateManager.checkForUpdates(); + } + } + + BusyIndicator { + id: update_busy_indicator + visible: false + width: check_for_updates_button.height + height: width + } + + Label { + id: update_icon + visible: update_text.visible + + font.family: FontAwesome.fontSolid.family + font.styleName: FontAwesome.fontSolid.styleName + font.pointSize: 12 + verticalAlignment: Text.AlignVCenter + anchors.verticalCenter: parent.verticalCenter + + text: FontAwesome.circleCheck + color: SettingsManager.colors.success + } + + Label { + id: update_text + anchors.verticalCenter: parent.verticalCenter + visible: false + } } - } - Button { - id: open_downloads_button - visible: false - text: qsTr("Open Download Page") + Button { + id: open_downloads_button + visible: false + text: qsTr("Open Download Page") - onClicked: { - Qt.openUrlExternally( - "https://github.com/PhilInTheGaps/GM-Companion/releases") + onClicked: { + Qt.openUrlExternally("https://github.com/PhilInTheGaps/GM-Companion/releases"); + } } } } diff --git a/app/ui/tools/settings/accounts/BaseAccountPage.qml b/app/ui/tools/settings/accounts/BaseAccountPage.qml index 744bb5d9..20a01f85 100644 --- a/app/ui/tools/settings/accounts/BaseAccountPage.qml +++ b/app/ui/tools/settings/accounts/BaseAccountPage.qml @@ -1,7 +1,8 @@ import QtQuick import QtQuick.Controls import IconFonts -import services +import services as Services +import common as Common import "./../../.." Item { @@ -54,7 +55,7 @@ Item { anchors.verticalCenter: parent.verticalCenter verticalAlignment: Text.AlignVCenter visible: root.isExperimental - color: "orange" + color: Common.SettingsManager.colors.warning } } @@ -73,8 +74,7 @@ Item { anchors.top: parent.top anchors.bottom: parent.bottom anchors.left: parent.left - width: root.rightPanel - || parent.width > 1200 ? parent.width / 2 - 10 : parent.width + width: root.rightPanel || parent.width > 1200 ? parent.width / 2 - 10 : parent.width } Rectangle { @@ -111,7 +111,7 @@ Item { StatusBar { id: status_label - required property Status modelData + required property Services.Status modelData anchors.left: parent.left anchors.right: parent.right diff --git a/app/ui/tools/settings/accounts/GoogleDriveAccount.qml b/app/ui/tools/settings/accounts/GoogleDriveAccount.qml index 20e83acb..c7dbd532 100644 --- a/app/ui/tools/settings/accounts/GoogleDriveAccount.qml +++ b/app/ui/tools/settings/accounts/GoogleDriveAccount.qml @@ -2,7 +2,8 @@ import QtQuick import QtQuick.Controls import QtQuick.Layouts import IconFonts -import common +import common as Common + //import services BaseAccountPage { @@ -11,14 +12,15 @@ BaseAccountPage { name: "GoogleDrive" icon: FontAwesome.googleDrive iconFont: FontAwesome.fontBrands -// statuses: [GoogleDrive.status] + + // statuses: [GoogleDrive.status] leftPanel: Column { spacing: 10 // Connected GridLayout { -// visible: GoogleDrive.connected + // visible: GoogleDrive.connected columns: 2 columnSpacing: 10 anchors.left: parent.left @@ -30,7 +32,7 @@ BaseAccountPage { } Label { -// Component.onCompleted: text = GoogleDrive.clientId + // Component.onCompleted: text = GoogleDrive.clientId wrapMode: Label.WrapAnywhere Layout.fillWidth: true } @@ -38,7 +40,7 @@ BaseAccountPage { // Not connected GridLayout { -// visible: !GoogleDrive.connected + // visible: !GoogleDrive.connected columns: 2 columnSpacing: 10 anchors.left: parent.left @@ -53,7 +55,7 @@ BaseAccountPage { id: google_id_textfield selectByMouse: true Layout.fillWidth: true - Component.onCompleted: text = SettingsManager.googleID + Component.onCompleted: text = Common.SettingsManager.services.google.clientId } Label { @@ -65,22 +67,22 @@ BaseAccountPage { id: google_secret_textfield selectByMouse: true Layout.fillWidth: true - Component.onCompleted: text = SettingsManager.googleSecret + Component.onCompleted: text = Common.SettingsManager.services.google.clientSecret } } + // text: GoogleDrive.connected ? qsTr("Disconnect") : qsTr("Connect") + // onClicked: { + // if (GoogleDrive.connected) { + // GoogleDrive.disconnectService() + // } else { + // SettingsManager.googleID = google_id_textfield.text + // SettingsManager.googleSecret = google_secret_textfield.text + // google_secret_textfield.text = "" + // GoogleDrive.connectService() + // } + // } Button { -// text: GoogleDrive.connected ? qsTr("Disconnect") : qsTr("Connect") -// onClicked: { -// if (GoogleDrive.connected) { -// GoogleDrive.disconnectService() -// } else { -// SettingsManager.googleID = google_id_textfield.text -// SettingsManager.googleSecret = google_secret_textfield.text -// google_secret_textfield.text = "" -// GoogleDrive.connectService() -// } -// } } } } diff --git a/app/ui/tools/settings/accounts/NextCloudAccount.qml b/app/ui/tools/settings/accounts/NextCloudAccount.qml index 8fd1c13c..16524be9 100644 --- a/app/ui/tools/settings/accounts/NextCloudAccount.qml +++ b/app/ui/tools/settings/accounts/NextCloudAccount.qml @@ -2,8 +2,8 @@ import QtQuick import QtQuick.Controls import QtQuick.Layouts import IconFonts -import common -import services +import common as Common +import services as Services BaseAccountPage { id: root @@ -11,14 +11,14 @@ BaseAccountPage { name: "NextCloud" icon: FontAwesome.cloud iconFont: FontAwesome.fontSolid - statuses: [NextCloud.status] + statuses: [Services.NextCloud.status] leftPanel: Column { spacing: 10 // Login to new server Column { - visible: !NextCloud.connected + visible: !Services.NextCloud.connected spacing: 10 anchors.left: parent.left anchors.right: parent.right @@ -39,24 +39,22 @@ BaseAccountPage { selectByMouse: true Layout.fillWidth: true placeholderText: "https://" - Component.onCompleted: text = SettingsManager.getServerUrl( - "NextCloud", false) + Component.onCompleted: text = Common.SettingsManager.services.nextcloud.getServerUrl() } } Button { text: qsTr("Login") onClicked: { - SettingsManager.setServerUrl(server_textfield.text, - "NextCloud") - NextCloud.connectService() + Common.SettingsManager.services.nextcloud.setServerUrl(server_textfield.text); + Services.NextCloud.connectService(); } } } // Logged in Column { - visible: NextCloud.connected + visible: Services.NextCloud.connected spacing: 10 anchors.left: parent.left anchors.right: parent.right @@ -74,7 +72,7 @@ BaseAccountPage { } Label { - text: NextCloud.loginName + text: Services.NextCloud.loginName Layout.alignment: Qt.AlignTop Layout.fillWidth: true wrapMode: Label.WrapAnywhere @@ -86,7 +84,7 @@ BaseAccountPage { } Label { - text: NextCloud.serverUrl + text: Services.NextCloud.serverUrl Layout.alignment: Qt.AlignTop Layout.fillWidth: true wrapMode: Label.WrapAnywhere @@ -95,7 +93,7 @@ BaseAccountPage { Button { text: qsTr("Logout") - onClicked: NextCloud.disconnectService() + onClicked: Services.NextCloud.disconnectService() } } } diff --git a/app/ui/tools/settings/accounts/SpotifyAccount.qml b/app/ui/tools/settings/accounts/SpotifyAccount.qml index 7bd63c1a..143bc5fe 100644 --- a/app/ui/tools/settings/accounts/SpotifyAccount.qml +++ b/app/ui/tools/settings/accounts/SpotifyAccount.qml @@ -2,8 +2,8 @@ import QtQuick import QtQuick.Controls import QtQuick.Layouts import IconFonts -import common -import services +import common as Common +import services as Services BaseAccountPage { id: root @@ -11,28 +11,24 @@ BaseAccountPage { name: "Spotify" icon: FontAwesome.spotify iconFont: FontAwesome.fontBrands - statuses: [Spotify.status, Spotify.clientStatus] + statuses: [Services.Spotify.status, Services.Spotify.clientStatus] leftPanel: Column { id: left_panel spacing: 10 function saveConnectionSettings() { - SettingsManager.spotifyUsername = username_textfield.text - SettingsManager.setPassword(username_textfield.text, - password_textfield.text, "Spotify") - - SettingsManager.spotifyID = spotify_id_textfield.text - SettingsManager.spotifySecret = spotify_secret_textfield.text - SettingsManager.setServerUrl(custom_server_textfield.text, - "Spotify") - + Common.SettingsManager.services.spotify.username = username_textfield.text; + Common.SettingsManager.services.spotify.setPassword(username_textfield.text, password_textfield.text); + Common.SettingsManager.services.spotify.clientId = spotify_id_textfield.text; + Common.SettingsManager.services.spotify.clientSecret = spotify_secret_textfield.text; + Common.SettingsManager.services.spotify.setServerUrl(custom_server_textfield.text); if (default_server_radio_button.checked) { - SettingsManager.spotifyConnection = "default" + Common.SettingsManager.services.spotify.connection = "default"; } else if (custom_server_radio_button.checked) { - SettingsManager.spotifyConnection = "custom" + Common.SettingsManager.services.spotify.connection = "custom"; } else { - SettingsManager.spotifyConnection = "local" + Common.SettingsManager.services.spotify.connection = "local"; } } @@ -45,8 +41,8 @@ BaseAccountPage { // if connected, show username Label { - visible: Spotify.connected - text: qsTr("Username: ") + Spotify.username + visible: Services.Spotify.connected + text: qsTr("Username: ") + Services.Spotify.username anchors.left: parent.left anchors.right: parent.right wrapMode: Label.WrapAtWordBoundaryOrAnywhere @@ -54,7 +50,7 @@ BaseAccountPage { // Login for librespot GridLayout { - visible: !Spotify.connected + visible: !Services.Spotify.connected columns: 2 columnSpacing: 10 anchors.left: parent.left @@ -70,7 +66,7 @@ BaseAccountPage { id: username_textfield selectByMouse: true Layout.fillWidth: true - Component.onCompleted: text = SettingsManager.spotifyUsername + Component.onCompleted: text = Common.SettingsManager.services.spotify.username } Label { @@ -89,7 +85,7 @@ BaseAccountPage { // Connection settings Column { - visible: !Spotify.connected + visible: !Services.Spotify.connected spacing: 10 anchors.left: parent.left anchors.right: parent.right @@ -100,7 +96,7 @@ BaseAccountPage { text: qsTr("Use default server") anchors.left: parent.left anchors.right: parent.right - checked: SettingsManager.spotifyConnection === "default" + checked: Common.SettingsManager.services.spotify.connection === "default" } // Custom Server @@ -109,7 +105,7 @@ BaseAccountPage { text: qsTr("Use custom server") anchors.left: parent.left anchors.right: parent.right - checked: SettingsManager.spotifyConnection === "custom" + checked: Common.SettingsManager.services.spotify.connection === "custom" } GridLayout { @@ -130,8 +126,7 @@ BaseAccountPage { selectByMouse: true Layout.fillWidth: true - Component.onCompleted: text = SettingsManager.getServerUrl( - "Spotify", true) + Component.onCompleted: text = Common.SettingsManager.services.spotify.getServerUrl() } } @@ -141,7 +136,7 @@ BaseAccountPage { text: qsTr("Client ID and Secret") anchors.left: parent.left anchors.right: parent.right - checked: SettingsManager.spotifyConnection === "local" + checked: Common.SettingsManager.services.spotify.connection === "local" } GridLayout { @@ -162,7 +157,7 @@ BaseAccountPage { selectByMouse: true Layout.fillWidth: true - Component.onCompleted: text = SettingsManager.spotifyID + Component.onCompleted: text = Common.SettingsManager.services.spotify.clientId } Label { @@ -176,28 +171,23 @@ BaseAccountPage { selectByMouse: true Layout.fillWidth: true - Component.onCompleted: text = SettingsManager.spotifySecret + Component.onCompleted: text = Common.SettingsManager.services.spotify.clientSecret } } } Button { - text: Spotify.connected ? qsTr("Disconnect") : qsTr("Connect") + text: Services.Spotify.connected ? qsTr("Disconnect") : qsTr("Connect") // Only enable if all required text field are filled out - enabled: Spotify.connected - || (username_textfield.text !== "" - && password_textfield.text !== "" - && (default_server_radio_button.checked || (custom_server_radio_button.checked && custom_server_textfield.text !== "") - || (client_id_secret_radio_button.checked && spotify_id_textfield.text - !== "" && spotify_secret_textfield.text !== ""))) + enabled: Services.Spotify.connected || (username_textfield.text !== "" && password_textfield.text !== "" && (default_server_radio_button.checked || (custom_server_radio_button.checked && custom_server_textfield.text !== "") || (client_id_secret_radio_button.checked && spotify_id_textfield.text !== "" && spotify_secret_textfield.text !== ""))) onClicked: { - if (Spotify.connected) { - Spotify.disconnectService() + if (Services.Spotify.connected) { + Services.Spotify.disconnectService(); } else { - left_panel.saveConnectionSettings() - Spotify.connectService() + left_panel.saveConnectionSettings(); + Services.Spotify.connectService(); } } } @@ -208,19 +198,18 @@ BaseAccountPage { spacing: 10 function saveQualitySettings() { - SettingsManager.spotifyEnableCache = enable_audio_cache_checkbox.checked - SettingsManager.spotifyEnableVolumeNormalization - = enable_volume_normalization_checkbox.checked - SettingsManager.spotifyBitrate = getNewBitrate() + Common.SettingsManager.services.spotify.enableCache = enable_audio_cache_checkbox.checked; + Common.SettingsManager.services.spotify.enableVolumeNormalization = enable_volume_normalization_checkbox.checked; + Common.SettingsManager.services.spotify.bitrate = getNewBitrate(); } function getNewBitrate() { if (bitrate_button_low.checked) - return "96" + return "96"; if (bitrate_button_mid.checked) - return "160" + return "160"; if (bitrate_button_high.checked) - return "320" + return "320"; } Label { @@ -232,7 +221,7 @@ BaseAccountPage { text: qsTr("Enable Audio Cache") anchors.left: parent.left anchors.right: parent.right - checked: SettingsManager.spotifyEnableCache + checked: Common.SettingsManager.services.spotify.enableCache } CheckBox { @@ -240,7 +229,7 @@ BaseAccountPage { text: qsTr("Enable Volume Normalization") anchors.left: parent.left anchors.right: parent.right - checked: SettingsManager.spotifyEnableVolumeNormalization + checked: Common.SettingsManager.services.spotify.enableVolumeNormalization } Column { @@ -262,7 +251,7 @@ BaseAccountPage { text: qsTr("Low (96 kbps)") anchors.left: parent.left anchors.right: parent.right - checked: SettingsManager.spotifyBitrate === "96" + checked: Common.SettingsManager.services.spotify.bitrate === "96" } RadioButton { @@ -270,7 +259,7 @@ BaseAccountPage { text: qsTr("Mid (160 kbps)") anchors.left: parent.left anchors.right: parent.right - checked: SettingsManager.spotifyBitrate === "160" + checked: Common.SettingsManager.services.spotify.bitrate === "160" } RadioButton { @@ -278,7 +267,7 @@ BaseAccountPage { text: qsTr("High (320 kbps)") anchors.left: parent.left anchors.right: parent.right - checked: SettingsManager.spotifyBitrate === "320" + checked: Common.SettingsManager.services.spotify.bitrate === "320" } } } @@ -287,7 +276,7 @@ BaseAccountPage { text: qsTr("Save") onClicked: { - right_panel.saveQualitySettings() + right_panel.saveQualitySettings(); } } } diff --git a/app/ui/tools/settings/accounts/StatusBar.qml b/app/ui/tools/settings/accounts/StatusBar.qml index ce4364f1..be756d31 100644 --- a/app/ui/tools/settings/accounts/StatusBar.qml +++ b/app/ui/tools/settings/accounts/StatusBar.qml @@ -1,14 +1,15 @@ import QtQuick import QtQuick.Controls import IconFonts -import services +import services as Services +import common as Common import "../../.." Rectangle { id: root height: Sizes.toolbarHeight - property Status status: undefined + property Services.Status status: undefined visible: status.message !== "" @@ -30,32 +31,32 @@ Rectangle { text: { switch (root.status.type) { case 1: - FontAwesome.circleCheck - break + FontAwesome.circleCheck; + break; case 2: - FontAwesome.triangleExclamation - break + FontAwesome.triangleExclamation; + break; case 3: - FontAwesome.circleExclamation - break + FontAwesome.circleExclamation; + break; default: - FontAwesome.circleInfo + FontAwesome.circleInfo; } } color: { switch (root.status.type) { case 1: - "green" - break + Common.SettingsManager.colors.success; + break; case 2: - "orange" - break + Common.SettingsManager.colors.warning; + break; case 3: - "red" - break + Common.SettingsManager.colors.error; + break; default: - "deepskyblue" + Common.SettingsManager.colors.info; } } } @@ -72,13 +73,13 @@ Rectangle { border.color: { switch (root.status.type) { case 2: - "orange" - break + Common.SettingsManager.colors.warning; + break; case 3: - "red" - break + Common.SettingsManager.colors.error; + break; default: - palette.highlight + palette.highlight; } } diff --git a/app/ui/tools/shop/shop_editor/ShopInfo.qml b/app/ui/tools/shop/shop_editor/ShopInfo.qml index 2158d682..8113f681 100644 --- a/app/ui/tools/shop/shop_editor/ShopInfo.qml +++ b/app/ui/tools/shop/shop_editor/ShopInfo.qml @@ -4,6 +4,7 @@ import QtQuick.Controls import CustomComponents import IconFonts import src +import common import "../../.." Column { @@ -43,7 +44,7 @@ Column { text: shop_name_field.editMode ? FontAwesome.circleCheck : FontAwesome.chevronUp font.family: FontAwesome.fontSolid.family font.styleName: FontAwesome.fontSolid.styleName - color: shop_name_field.editMode ? "limegreen" : palette.buttonText + color: shop_name_field.editMode ? SettingsManager.colors.success : palette.buttonText anchors.fill: parent verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter @@ -75,7 +76,7 @@ Column { text: shop_name_field.editMode ? FontAwesome.circleXmark : FontAwesome.chevronDown font.family: FontAwesome.fontSolid.family font.styleName: FontAwesome.fontSolid.styleName - color: shop_name_field.editMode ? "red" : palette.buttonText + color: shop_name_field.editMode ? SettingsManager.colors.error : palette.buttonText anchors.fill: parent verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter @@ -144,7 +145,7 @@ Column { anchors.margins: 10 verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter - color: "red" + color: SettingsManager.colors.error } onClicked: shop_delete_overlay.visible = true @@ -185,7 +186,7 @@ Column { text: FontAwesome.circleCheck font.family: FontAwesome.fontSolid.family font.styleName: FontAwesome.fontSolid.styleName - color: "limegreen" + color: SettingsManager.colors.success anchors.fill: parent verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter @@ -212,7 +213,7 @@ Column { text: FontAwesome.circleXmark font.family: FontAwesome.fontSolid.family font.styleName: FontAwesome.fontSolid.styleName - color: "red" + color: SettingsManager.colors.error anchors.fill: parent verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter diff --git a/src/addons/addonmanager.cpp b/src/addons/addonmanager.cpp index 7b08fc5f..2dae4256 100644 --- a/src/addons/addonmanager.cpp +++ b/src/addons/addonmanager.cpp @@ -13,6 +13,7 @@ #include using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmAddonManager, "gm.addons.manager") diff --git a/src/addons/addonrepositorymanager.cpp b/src/addons/addonrepositorymanager.cpp index 470d5a79..97b3dda2 100644 --- a/src/addons/addonrepositorymanager.cpp +++ b/src/addons/addonrepositorymanager.cpp @@ -3,7 +3,6 @@ #include "settings/settingsmanager.h" #include "updates/updatemanager.h" #include "utils/networkutils.h" -#include "utils/stringutils.h" #include #include #include @@ -16,8 +15,9 @@ Q_LOGGING_CATEGORY(gmAddonRepoManager, "gm.addons.repositories") using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; -constexpr ConstQString REPOSITORY_SETTING = "addonRepositories"; +constexpr auto REPOSITORY_SETTING = "addonRepositories"; constexpr int MINIMAL_COMPATIBLE_VERSION = 1; AddonRepositoryManager::AddonRepositoryManager(QObject *parent) : QObject{parent} diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index a7e90e77..b1ef50db 100755 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -33,8 +33,14 @@ set(SRC_SETTINGS settings/settingsmanager.cpp settings/abstractsettingsmanager.h settings/abstractsettingsmanager.cpp - settings/quicksettingsmanager.h - settings/quicksettingsmanager.cpp) + settings/quick/settingsmanager.h + settings/quick/settingsmanager.cpp + settings/quick/services.h + settings/quick/colors.h + settings/quick/macros.h + settings/quick/spotify.h + settings/quick/google.h + settings/quick/nextcloud.h) set(SRC_UPDATES updates/updatemanager.h @@ -66,6 +72,8 @@ qt_add_library(common STATIC) qt_add_qml_module(common URI common SOURCES ${SOURCES} + DEPENDENCIES + QtQuick ) target_precompile_headers(common PRIVATE @@ -132,7 +140,7 @@ target_include_directories(common PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/models ${CMAKE_CURRENT_SOURCE_DIR}/updates - ${CMAKE_CURRENT_SOURCE_DIR}/settings) + ${CMAKE_CURRENT_SOURCE_DIR}/settings/quick) target_link_libraries(common PUBLIC @@ -140,6 +148,7 @@ target_link_libraries(common Qt6::Core Qt6::Gui Qt6::Qml + Qt6::Quick Qt6::Network PRIVATE ${MARKDOWN_LIBRARY} diff --git a/src/common/settings/abstractsettingsmanager.cpp b/src/common/settings/abstractsettingsmanager.cpp index acf79d8c..b7711184 100644 --- a/src/common/settings/abstractsettingsmanager.cpp +++ b/src/common/settings/abstractsettingsmanager.cpp @@ -1,10 +1,8 @@ #include "abstractsettingsmanager.h" -AbstractSettingsManager::AbstractSettingsManager(QObject *parent) : QObject{parent} -{ -} +using namespace Common::Settings; -auto AbstractSettingsManager::has(const QString &setting, const QString &group) -> bool +auto AbstractSettingsManager::has(QAnyStringView setting, QAnyStringView group) -> bool { m_settings.beginGroup(group); const auto result = m_settings.contains(setting); @@ -18,7 +16,7 @@ void AbstractSettingsManager::forceSync() m_settings.sync(); } -void AbstractSettingsManager::remove(const QString &setting, const QString &group) +void AbstractSettingsManager::remove(QAnyStringView setting, QAnyStringView group) { m_settings.beginGroup(group); m_settings.remove(setting); diff --git a/src/common/settings/abstractsettingsmanager.h b/src/common/settings/abstractsettingsmanager.h index f5c2f9f4..76f0fe67 100644 --- a/src/common/settings/abstractsettingsmanager.h +++ b/src/common/settings/abstractsettingsmanager.h @@ -1,17 +1,19 @@ #pragma once -#include "utils/stringutils.h" #include #include #include #include -constexpr ConstQString DEFAULT_GROUP = ""; +namespace Common::Settings +{ + +constexpr auto DEFAULT_GROUP = QLatin1StringView(); -template struct SettingRequest +template struct Request { - SettingRequest() = default; - SettingRequest(const QString &identifier, const T &defaultValue, const QString &group = DEFAULT_GROUP) + Request() = default; + Request(const QString &identifier, const T &defaultValue, const QString &group = DEFAULT_GROUP) : identifier(identifier), defaultValue(defaultValue), group(group) { } @@ -25,32 +27,29 @@ class AbstractSettingsManager : public QObject { Q_OBJECT public: - explicit AbstractSettingsManager(QObject *parent = nullptr); + using QObject::QObject; - template - T get(const QString &setting, const T &defaultValue, const QString &group = DEFAULT_GROUP); + template T get(QAnyStringView setting, const T &defaultValue, QAnyStringView group = DEFAULT_GROUP); - template T - get(const SettingRequest &request); + template T get(const Request &request); - template - void set(const QString &setting, const T &value, const QString &group = DEFAULT_GROUP); + template void set(QAnyStringView setting, const T &value, QAnyStringView group = DEFAULT_GROUP); - Q_INVOKABLE bool has(const QString &setting, const QString &group = DEFAULT_GROUP); + Q_INVOKABLE bool has(QAnyStringView setting, QAnyStringView group = DEFAULT_GROUP); void forceSync(); protected: - template void rename(const QString ¤tName, const QString &newName, const QString &group); + template void rename(QAnyStringView currentName, QAnyStringView newName, QAnyStringView group); - void remove(const QString &setting, const QString &group); + void remove(QAnyStringView setting, QAnyStringView group); private: QSettings m_settings = QSettings(QDir::homePath() + "/.gm-companion/settings.ini", QSettings::IniFormat); }; template -auto AbstractSettingsManager::get(const QString &setting, const T &defaultValue, const QString &group) -> T +auto AbstractSettingsManager::get(QAnyStringView setting, const T &defaultValue, QAnyStringView group) -> T { m_settings.beginGroup(group); QVariant variant = m_settings.value(setting, defaultValue); @@ -58,14 +57,12 @@ auto AbstractSettingsManager::get(const QString &setting, const T &defaultValue, return variant.value(); } -template -auto AbstractSettingsManager::get(const SettingRequest &request) -> T +template auto AbstractSettingsManager::get(const Request &request) -> T { return get(request.identifier, request.defaultValue, request.group); } -template -void AbstractSettingsManager::set(const QString &setting, const T &value, const QString &group) +template void AbstractSettingsManager::set(QAnyStringView setting, const T &value, QAnyStringView group) { m_settings.beginGroup(group); m_settings.setValue(setting, value); @@ -73,7 +70,7 @@ void AbstractSettingsManager::set(const QString &setting, const T &value, const } template -void AbstractSettingsManager::rename(const QString ¤tName, const QString &newName, const QString &group) +void AbstractSettingsManager::rename(QAnyStringView currentName, QAnyStringView newName, QAnyStringView group) { if (const auto value = get(currentName, T(), group); !value.isEmpty()) { @@ -81,3 +78,5 @@ void AbstractSettingsManager::rename(const QString ¤tName, const QString & } remove(currentName, group); } + +} // namespace Common::Settings diff --git a/src/common/settings/quick/colors.h b/src/common/settings/quick/colors.h new file mode 100644 index 00000000..4d24deb9 --- /dev/null +++ b/src/common/settings/quick/colors.h @@ -0,0 +1,54 @@ +#pragma once + +#include "../settingsmanager.h" +#include "macros.h" +#include +#include +#include + +namespace Common::Settings::Quick +{ + +class Colors : public QObject +{ + Q_OBJECT + QML_ELEMENT + QML_UNCREATABLE("") + + SETTINGS_PROPERTY2(QColor, info, QColor::fromString(INFO_DEFAULT), GROUP) + SETTINGS_PROPERTY2(QColor, success, QColor::fromString(SUCCESS_DEFAULT), GROUP) + SETTINGS_PROPERTY2(QColor, warning, QColor::fromString(WARNING_DEFAULT), GROUP) + SETTINGS_PROPERTY2(QColor, error, QColor::fromString(ERROR_DEFAULT), GROUP) + + Q_INVOKABLE void resetInfo() + { + info(INFO_DEFAULT); + } + + Q_INVOKABLE void resetSuccess() + { + success(SUCCESS_DEFAULT); + } + + Q_INVOKABLE void resetWarning() + { + warning(WARNING_DEFAULT); + } + + Q_INVOKABLE void resetError() + { + error(ERROR_DEFAULT); + } + +public: + using QObject::QObject; + +private: + inline static constexpr auto GROUP = "Colors"; + inline static constexpr auto INFO_DEFAULT = "#00bfff"; + inline static constexpr auto SUCCESS_DEFAULT = "#48b749"; + inline static constexpr auto WARNING_DEFAULT = "#fce208"; + inline static constexpr auto ERROR_DEFAULT = "#ef2426"; +}; + +} // namespace Common::Settings::Quick diff --git a/src/common/settings/quick/google.h b/src/common/settings/quick/google.h new file mode 100644 index 00000000..2c699d7f --- /dev/null +++ b/src/common/settings/quick/google.h @@ -0,0 +1,27 @@ +#pragma once + +#include "../settingsmanager.h" +#include "macros.h" +#include +#include + +namespace Common::Settings::Quick +{ + +class Google : public QObject +{ + Q_OBJECT + QML_ELEMENT + QML_UNCREATABLE("") + + SETTINGS_PROPERTY2(QString, clientId, QLatin1String(), GROUP) + SETTINGS_PROPERTY2(QString, clientSecret, QLatin1String(), GROUP) + +public: + using QObject::QObject; + +private: + inline static constexpr auto GROUP = "Google"; +}; + +} // namespace Common::Settings::Quick diff --git a/src/common/settings/quick/macros.h b/src/common/settings/quick/macros.h new file mode 100644 index 00000000..74c148cb --- /dev/null +++ b/src/common/settings/quick/macros.h @@ -0,0 +1,35 @@ +#pragma once + +#define SETTINGS_PROPERTY(TYPE, NAME, DEFAULT) SETTINGS_PROPERTY2(TYPE, NAME, DEFAULT, DEFAULT_GROUP) +#define SETTINGS_PROPERTY_VAL(TYPE, NAME, DEFAULT) SETTINGS_PROPERTY_VAL2(TYPE, NAME, DEFAULT, DEFAULT_GROUP) + +#define SETTINGS_PROPERTY2(TYPE, NAME, DEFAULT, GROUP) SETTINGS_PROPERTY3(TYPE, NAME, #NAME, DEFAULT, GROUP) +#define SETTINGS_PROPERTY_VAL2(TYPE, NAME, DEFAULT, GROUP) SETTINGS_PROPERTY_VAL3(TYPE, NAME, #NAME, DEFAULT, GROUP) + +#define SETTINGS_PROPERTY3(TYPE, NAME, SETTING, DEFAULT, GROUP) \ + Q_PROPERTY(TYPE NAME READ NAME WRITE NAME NOTIFY NAME##Changed) \ +public: \ + [[nodiscard]] static auto NAME()->TYPE \ + { \ + return Common::Settings::SettingsManager::instance()->get(SETTING, DEFAULT, GROUP); \ + } \ + void NAME(const TYPE &value) \ + { \ + Common::Settings::SettingsManager::instance()->set(SETTING, value, GROUP); \ + emit NAME##Changed(value); \ + } \ + Q_SIGNAL void NAME##Changed(TYPE value); + +#define SETTINGS_PROPERTY_VAL3(TYPE, NAME, SETTING, DEFAULT, GROUP) \ + Q_PROPERTY(TYPE NAME READ NAME WRITE NAME NOTIFY NAME##Changed) \ +public: \ + [[nodiscard]] static auto NAME()->TYPE \ + { \ + return Common::Settings::SettingsManager::instance()->get(SETTING, DEFAULT, GROUP); \ + } \ + void NAME(TYPE value) \ + { \ + Common::Settings::SettingsManager::instance()->set(SETTING, value, GROUP); \ + emit NAME##Changed(value); \ + } \ + Q_SIGNAL void NAME##Changed(TYPE value); diff --git a/src/common/settings/quick/nextcloud.h b/src/common/settings/quick/nextcloud.h new file mode 100644 index 00000000..070a638c --- /dev/null +++ b/src/common/settings/quick/nextcloud.h @@ -0,0 +1,33 @@ +#pragma once + +#include "../settingsmanager.h" +#include +#include + +namespace Common::Settings::Quick +{ + +class NextCloud : public QObject +{ + Q_OBJECT + QML_ELEMENT + QML_UNCREATABLE("") + +public: + using QObject::QObject; + + Q_INVOKABLE static QString getServerUrl() + { + return SettingsManager::getServerUrl(GROUP, false); + } + + Q_INVOKABLE static void setServerUrl(const QString &url) + { + SettingsManager::setServerUrl(url, GROUP); + } + +private: + inline static constexpr auto GROUP = "NextCloud"; +}; + +} // namespace Common::Settings::Quick diff --git a/src/common/settings/quick/services.h b/src/common/settings/quick/services.h new file mode 100644 index 00000000..cdb249a8 --- /dev/null +++ b/src/common/settings/quick/services.h @@ -0,0 +1,46 @@ +#pragma once + +#include "google.h" +#include "nextcloud.h" +#include "spotify.h" +#include +#include + +namespace Common::Settings::Quick +{ + +class Services : public QObject +{ + Q_OBJECT + QML_ELEMENT + QML_UNCREATABLE("") + + Q_PROPERTY(Common::Settings::Quick::Spotify *spotify READ spotify CONSTANT FINAL) + Q_PROPERTY(Common::Settings::Quick::Google *google READ google CONSTANT FINAL) + Q_PROPERTY(Common::Settings::Quick::NextCloud *nextcloud READ nextcloud CONSTANT FINAL) + +public: + using QObject::QObject; + + auto spotify() -> Spotify * + { + return &m_spotify; + } + + auto google() -> Google * + { + return &m_google; + } + + auto nextcloud() -> NextCloud * + { + return &m_nextcloud; + } + +private: + Spotify m_spotify; + Google m_google; + NextCloud m_nextcloud; +}; + +} // namespace Common::Settings::Quick diff --git a/src/common/settings/quick/settingsmanager.cpp b/src/common/settings/quick/settingsmanager.cpp new file mode 100644 index 00000000..58d60025 --- /dev/null +++ b/src/common/settings/quick/settingsmanager.cpp @@ -0,0 +1,59 @@ +#include "settingsmanager.h" +#include "utils/utils.h" + +using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; + +auto Quick::SettingsManager::has(const QString &setting, const QString &group) -> bool +{ + return Common::Settings::SettingsManager::instance()->has(setting, group); +} + +auto Quick::SettingsManager::getPath(const QString &path) -> QString +{ + return Common::Settings::SettingsManager::getPath(path); +} + +void Quick::SettingsManager::setPath(const QString &path, const QString &value) +{ + Common::Settings::SettingsManager::setPath(path, value); +} + +auto Quick::SettingsManager::getLanguageIndex() -> qsizetype +{ + auto language = Common::Settings::SettingsManager::getLanguageString(); + auto languages = getLanguageNames(); + auto index = languages.indexOf(language); + + if (index < 0) index = languages.indexOf("English"_L1); + + return index; +} + +auto Quick::SettingsManager::getLanguageNames() -> QStringList +{ + return Common::Settings::SettingsManager::getLanguageNames(); +} + +void Quick::SettingsManager::setLanguage(const QString &language) +{ + auto languages = Common::Settings::SettingsManager::getLanguages(); + auto languageNames = getLanguageNames(); + auto index = languageNames.indexOf(language); + auto chosenLanguage = Utils::isInBounds(languages, index) ? languages[index] : u"default"_s; + + Common::Settings::SettingsManager::instance()->set(u"language"_s, chosenLanguage); + emit languageChanged(chosenLanguage); + + a_languageBcp47 = Common::Settings::SettingsManager::getLanguageBcp47(); +} + +auto Quick::SettingsManager::instance() -> SettingsManager * +{ + if (!m_instance) + { + m_instance = new SettingsManager(nullptr); + } + + return m_instance; +} diff --git a/src/common/settings/quick/settingsmanager.h b/src/common/settings/quick/settingsmanager.h new file mode 100644 index 00000000..7099c0b6 --- /dev/null +++ b/src/common/settings/quick/settingsmanager.h @@ -0,0 +1,81 @@ +#pragma once + +#include "../settingsmanager.h" +#include "colors.h" +#include "macros.h" +#include "qmlsingletonfactory.h" +#include "services.h" +#include "thirdparty/propertyhelper/PropertyHelper.h" +#include +#include +#include +#include +#include + +namespace Common::Settings::Quick +{ + +/// Settings Manager that implements specific settings as properties +/// which can be used from the QML side +class SettingsManager : public QObject +{ + Q_OBJECT + QML_ELEMENT + QML_SINGLETON + QML_SINGLETON_FACTORY(SettingsManager) + + Q_PROPERTY(Common::Settings::Quick::Services *services READ services CONSTANT FINAL) + Q_PROPERTY(Common::Settings::Quick::Colors *colors READ colors CONSTANT FINAL) + + // General Settings + SETTINGS_PROPERTY_VAL(bool, showToolNames, false) + SETTINGS_PROPERTY(QString, cloudMode, QStringLiteral("local")) + READ_PROPERTY2(QString, languageBcp47, Common::Settings::SettingsManager::instance()->getLanguageBcp47()) + +#ifdef NO_UPDATE_CHECK + SETTINGS_PROPERTY_VAL2(bool, checkForUpdates, false, "Updates") +#else + SETTINGS_PROPERTY_VAL2(bool, checkForUpdates, true, "Updates") +#endif + + // Telemetry + SETTINGS_PROPERTY_VAL2(bool, crashReports, false, "Telemetry") + SETTINGS_PROPERTY_VAL2(bool, sessionTracking, false, "Telemetry") + +public: + SettingsManager() = delete; + + Q_INVOKABLE static bool has(const QString &setting, const QString &group); + + Q_INVOKABLE static QString getPath(const QString &path); + Q_INVOKABLE static void setPath(const QString &path, const QString &value); + + Q_INVOKABLE static qsizetype getLanguageIndex(); + Q_INVOKABLE static QStringList getLanguageNames(); + Q_INVOKABLE void setLanguage(const QString &language); + + auto services() -> Services * + { + return &m_services; + } + + auto colors() -> Colors * + { + return &m_colors; + } + + static auto instance() -> SettingsManager *; + +signals: + void languageChanged(QString language); + +private: + using QObject::QObject; + + Services m_services; + Colors m_colors; + + inline static SettingsManager *m_instance = nullptr; +}; + +} // namespace Common::Settings::Quick diff --git a/src/common/settings/quick/spotify.h b/src/common/settings/quick/spotify.h new file mode 100644 index 00000000..40b71516 --- /dev/null +++ b/src/common/settings/quick/spotify.h @@ -0,0 +1,47 @@ +#pragma once + +#include "../settingsmanager.h" +#include "macros.h" +#include +#include + +namespace Common::Settings::Quick +{ + +class Spotify : public QObject +{ + Q_OBJECT + QML_ELEMENT + QML_UNCREATABLE("") + + SETTINGS_PROPERTY2(QString, username, QLatin1String(), GROUP) + SETTINGS_PROPERTY2(QString, clientSecret, QLatin1String(), GROUP) + SETTINGS_PROPERTY2(QString, clientId, QLatin1String(), GROUP) + SETTINGS_PROPERTY2(QString, connection, QLatin1String(), GROUP) + SETTINGS_PROPERTY_VAL2(bool, enableCache, true, GROUP) + SETTINGS_PROPERTY_VAL2(bool, enableVolumeNormalization, false, GROUP) + SETTINGS_PROPERTY2(QString, bitrate, QStringLiteral("160"), GROUP) + +public: + using QObject::QObject; + + Q_INVOKABLE static QString getServerUrl() + { + return SettingsManager::getServerUrl(GROUP, true); + } + + Q_INVOKABLE static void setServerUrl(const QString &url) + { + SettingsManager::setServerUrl(url, GROUP); + } + + Q_INVOKABLE static void setPassword(const QString &username, const QString &password) + { + SettingsManager::setPassword(username, password, GROUP); + } + +private: + inline static constexpr auto GROUP = "Spotify"; +}; + +} // namespace Common::Settings::Quick diff --git a/src/common/settings/quicksettingsmanager.cpp b/src/common/settings/quicksettingsmanager.cpp deleted file mode 100644 index a084b1b1..00000000 --- a/src/common/settings/quicksettingsmanager.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "quicksettingsmanager.h" -#include "utils/utils.h" - -using namespace Qt::Literals::StringLiterals; - -auto QuickSettingsManager::has(const QString &setting, const QString &group) -> bool -{ - return SettingsManager::instance()->has(setting, group); -} - -auto QuickSettingsManager::getPath(const QString &path) -> QString -{ - return SettingsManager::getPath(path); -} - -void QuickSettingsManager::setPath(const QString &path, const QString &value) -{ - SettingsManager::setPath(path, value); -} - -auto QuickSettingsManager::getLanguageIndex() -> qsizetype -{ - auto language = SettingsManager::getLanguageString(); - auto languages = getLanguageNames(); - auto index = languages.indexOf(language); - - if (index < 0) index = languages.indexOf("English"_L1); - - return index; -} - -auto QuickSettingsManager::getLanguageNames() -> QStringList -{ - return SettingsManager::getLanguageNames(); -} - -void QuickSettingsManager::setLanguage(const QString &language) -{ - auto languages = SettingsManager::getLanguages(); - auto languageNames = getLanguageNames(); - auto index = languageNames.indexOf(language); - auto chosenLanguage = Utils::isInBounds(languages, index) ? languages[index] : u"default"_s; - - SettingsManager::instance()->set(u"language"_s, chosenLanguage); - emit languageChanged(chosenLanguage); - - a_languageBcp47 = SettingsManager::getLanguageBcp47(); -} - -auto QuickSettingsManager::getServerUrl(const QString &service, bool hasDefault) -> QString -{ - return SettingsManager::getServerUrl(service, hasDefault); -} - -void QuickSettingsManager::setServerUrl(const QString &url, const QString &service) -{ - SettingsManager::setServerUrl(url, service); -} - -void QuickSettingsManager::setPassword(const QString &username, const QString &password, const QString &service) -{ - SettingsManager::setPassword(username, password, service); -} - -auto QuickSettingsManager::instance() -> QuickSettingsManager * -{ - if (!m_instance) - { - m_instance = new QuickSettingsManager(nullptr); - } - - return m_instance; -} diff --git a/src/common/settings/quicksettingsmanager.h b/src/common/settings/quicksettingsmanager.h deleted file mode 100644 index c8b5898c..00000000 --- a/src/common/settings/quicksettingsmanager.h +++ /dev/null @@ -1,94 +0,0 @@ -#pragma once - -#include "qmlsingletonfactory.h" -#include "settingsmanager.h" -#include "thirdparty/propertyhelper/PropertyHelper.h" -#include -#include -#include -#include -#include - -#define SETTINGS_PROPERTY(TYPE, NAME, DEFAULT) SETTINGS_PROPERTY2(TYPE, NAME, DEFAULT, DEFAULT_GROUP) - -#define SETTINGS_PROPERTY2(TYPE, NAME, DEFAULT, GROUP) SETTINGS_PROPERTY3(TYPE, NAME, #NAME, DEFAULT, GROUP) - -#define SETTINGS_PROPERTY3(TYPE, NAME, SETTING, DEFAULT, GROUP) \ - Q_PROPERTY(TYPE NAME READ NAME WRITE NAME NOTIFY NAME##Changed) \ -public: \ - [[nodiscard]] static auto NAME()->TYPE \ - { \ - return SettingsManager::instance()->get(SETTING, DEFAULT, GROUP); \ - } \ - void NAME(const TYPE &value) \ - { \ - SettingsManager::instance()->set(SETTING, value, GROUP); \ - emit NAME##Changed(value); \ - } \ - Q_SIGNAL void NAME##Changed(TYPE value); - -/// Settings Manager that implements specific settings as properties -/// which can be used from the QML side -class QuickSettingsManager : public QObject -{ - Q_OBJECT - QML_NAMED_ELEMENT(SettingsManager) - QML_SINGLETON - QML_SINGLETON_FACTORY(QuickSettingsManager) - - // General Settings - SETTINGS_PROPERTY(bool, showToolNames, false) - SETTINGS_PROPERTY(QString, cloudMode, QStringLiteral("local")) - READ_PROPERTY2(QString, languageBcp47, SettingsManager::instance()->getLanguageBcp47()) - -#ifdef NO_UPDATE_CHECK - SETTINGS_PROPERTY2(bool, checkForUpdates, false, QStringLiteral("Updates")) -#else - SETTINGS_PROPERTY2(bool, checkForUpdates, true, QStringLiteral("Updates")) -#endif - - // Telemetry - SETTINGS_PROPERTY2(bool, crashReports, false, QStringLiteral("Telemetry")) - SETTINGS_PROPERTY2(bool, sessionTracking, false, QStringLiteral("Telemetry")) - - // Google - SETTINGS_PROPERTY2(QString, googleID, QLatin1String(), QStringLiteral("Google")) - SETTINGS_PROPERTY2(QString, googleSecret, QLatin1String(), QStringLiteral("Google")) - - // Spotify - SETTINGS_PROPERTY2(QString, spotifyUsername, QLatin1String(), QStringLiteral("Spotify")) - SETTINGS_PROPERTY2(QString, spotifySecret, QLatin1String(), QStringLiteral("Spotify")) - SETTINGS_PROPERTY2(QString, spotifyID, QLatin1String(), QStringLiteral("Spotify")) - SETTINGS_PROPERTY3(QString, spotifyConnection, QStringLiteral("connection"), QLatin1String(), - QStringLiteral("Spotify")) - SETTINGS_PROPERTY3(bool, spotifyEnableCache, QStringLiteral("enableCache"), true, QStringLiteral("Spotify")) - SETTINGS_PROPERTY3(bool, spotifyEnableVolumeNormalization, QStringLiteral("enableVolumeNormalization"), false, - QStringLiteral("Spotify")) - SETTINGS_PROPERTY3(QString, spotifyBitrate, QStringLiteral("bitrate"), QStringLiteral("160"), - QStringLiteral("Spotify")) - -public: - QuickSettingsManager() = delete; - Q_INVOKABLE static bool has(const QString &setting, const QString &group); - - Q_INVOKABLE static QString getPath(const QString &path); - Q_INVOKABLE static void setPath(const QString &path, const QString &value); - - Q_INVOKABLE static qsizetype getLanguageIndex(); - Q_INVOKABLE static QStringList getLanguageNames(); - Q_INVOKABLE void setLanguage(const QString &language); - - Q_INVOKABLE static QString getServerUrl(const QString &service, bool hasDefault); - Q_INVOKABLE static void setServerUrl(const QString &url, const QString &service); - - Q_INVOKABLE static void setPassword(const QString &username, const QString &password, const QString &service); - - static auto instance() -> QuickSettingsManager *; - -signals: - void languageChanged(QString language); - -private: - using QObject::QObject; - inline static QuickSettingsManager *m_instance = nullptr; -}; diff --git a/src/common/settings/settingsmanager.cpp b/src/common/settings/settingsmanager.cpp index 27efa140..327cd4aa 100755 --- a/src/common/settings/settingsmanager.cpp +++ b/src/common/settings/settingsmanager.cpp @@ -4,11 +4,12 @@ #include using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmSettings, "gm.settings") -constexpr ConstQString ADDONS_GROUP = "Addons"; -constexpr ConstQString DEFAULT_SERVER_URL = "https://gm-companion.rophil.lol"; +constexpr auto ADDONS_GROUP = "Addons"; +constexpr auto DEFAULT_SERVER_URL = "https://gm-companion.rophil.lol"; auto SettingsManager::instance() -> QPointer { @@ -20,7 +21,7 @@ auto SettingsManager::instance() -> QPointer return m_instance; } -auto SettingsManager::getPath(const QString &setting, QString group) -> QString +auto SettingsManager::getPath(QAnyStringView setting, QAnyStringView group) -> QString { if (group.isEmpty()) group = getActivePathGroup(); auto value = instance()->get(setting, ""_L1, group); @@ -29,7 +30,7 @@ auto SettingsManager::getPath(const QString &setting, QString group) -> QString return value; } -void SettingsManager::setPath(const QString &setting, const QString &value, QString group) +void SettingsManager::setPath(QAnyStringView setting, const QString &value, QAnyStringView group) { if (group.isEmpty()) group = getActivePathGroup(); instance()->set(setting, value, group); @@ -97,7 +98,7 @@ auto SettingsManager::getLanguageNames() -> QStringList return strings; } -auto SettingsManager::getServerUrl(const QString &service, bool hasDefault) -> QString +auto SettingsManager::getServerUrl(QAnyStringView service, bool hasDefault) -> QString { if (hasDefault && instance()->get(u"connection"_s, u"default"_s, service) == "default"_L1) { @@ -112,7 +113,7 @@ auto SettingsManager::getServerUrl(const QString &service, bool hasDefault) -> Q return url; } -void SettingsManager::setServerUrl(const QString &url, const QString &service) +void SettingsManager::setServerUrl(const QString &url, QAnyStringView service) { instance()->set(u"server"_s, url, service); } @@ -164,13 +165,13 @@ auto SettingsManager::setPassword(const QString &username, const QString &passwo return true; } -auto SettingsManager::getDefaultPath(const QString &setting, const QString &group) -> QString +auto SettingsManager::getDefaultPath(QAnyStringView setting, QAnyStringView group) -> QString { if (setting.isEmpty()) return u""_s; - if (group != PATHS_GROUP) return u"/gm-companion/%1"_s.arg(setting); + if (group != PATHS_GROUP) return u"/gm-companion/%1"_s.arg(setting.toString()); - return u"%1/.gm-companion/%2"_s.arg(QDir::homePath(), setting); + return u"%1/.gm-companion/%2"_s.arg(QDir::homePath(), setting.toString()); } /// Get the ini group for the currently set cloud mode. @@ -185,7 +186,7 @@ auto SettingsManager::getActivePathGroup() -> QString } /// Set addon disabled or enabled -void SettingsManager::setAddonEnabled(const QString &addon, bool enabled) +void SettingsManager::setAddonEnabled(QAnyStringView addon, bool enabled) { if (addon.isEmpty()) { @@ -197,7 +198,7 @@ void SettingsManager::setAddonEnabled(const QString &addon, bool enabled) } /// Returns if addon is enabled -auto SettingsManager::getIsAddonEnabled(const QString &addon) -> bool +auto SettingsManager::getIsAddonEnabled(QAnyStringView addon) -> bool { return get(addon, false, ADDONS_GROUP); } diff --git a/src/common/settings/settingsmanager.h b/src/common/settings/settingsmanager.h index 106624b4..cb0d3b5d 100755 --- a/src/common/settings/settingsmanager.h +++ b/src/common/settings/settingsmanager.h @@ -1,14 +1,16 @@ #pragma once #include "abstractsettingsmanager.h" -#include "utils/stringutils.h" #include #include #include #include #include -constexpr ConstQString PATHS_GROUP = "Paths"; +namespace Common::Settings +{ + +constexpr auto PATHS_GROUP = QLatin1StringView("Paths"); class SettingsManager : public AbstractSettingsManager { @@ -17,8 +19,8 @@ class SettingsManager : public AbstractSettingsManager public: static auto instance() -> QPointer; - static auto getPath(const QString &setting, QString group = QLatin1String()) -> QString; - static void setPath(const QString &setting, const QString &value, QString group = QLatin1String()); + static auto getPath(QAnyStringView setting, QAnyStringView group = QLatin1StringView()) -> QString; + static void setPath(QAnyStringView setting, const QString &value, QAnyStringView group = QLatin1StringView()); static auto getLanguage() -> QLocale; static auto getLanguageBcp47() -> QString; @@ -26,21 +28,23 @@ class SettingsManager : public AbstractSettingsManager static auto getLanguages() -> QStringList; static auto getLanguageNames() -> QStringList; - static auto getServerUrl(const QString &service, bool hasDefault = true) -> QString; - static void setServerUrl(const QString &url, const QString &service); + static auto getServerUrl(QAnyStringView service, bool hasDefault = true) -> QString; + static void setServerUrl(const QString &url, QAnyStringView service); 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; + void setAddonEnabled(QAnyStringView addon, bool enabled); + auto getIsAddonEnabled(QAnyStringView addon) -> bool; private: using AbstractSettingsManager::AbstractSettingsManager; inline static QPointer m_instance = nullptr; - static auto getDefaultPath(const QString &setting, const QString &group = PATHS_GROUP) -> QString; + static auto getDefaultPath(QAnyStringView setting, QAnyStringView group = PATHS_GROUP) -> QString; static auto getActivePathGroup() -> QString; void updateSettings(); }; + +} // namespace Common::Settings diff --git a/src/common/updates/updatemanager.cpp b/src/common/updates/updatemanager.cpp index 305351dd..4375d359 100755 --- a/src/common/updates/updatemanager.cpp +++ b/src/common/updates/updatemanager.cpp @@ -1,15 +1,14 @@ #include "updatemanager.h" -#include "utils/stringutils.h" #include "version.h" #include #include Q_LOGGING_CATEGORY(gmUpdateManager, "gm.updates.manager") -constexpr ConstQString DEFAULT_FEED_URL = "https://github.com/PhilInTheGaps/GM-Companion/releases.atom"; - using namespace Qt::Literals::StringLiterals; +constexpr auto DEFAULT_FEED_URL = "https://github.com/PhilInTheGaps/GM-Companion/releases.atom"_L1; + UpdateManager::UpdateManager(QObject *parent) : QObject(parent) { qCDebug(gmUpdateManager()) << "Initializing UpdateManager ..."; diff --git a/src/common/utils/stringutils.h b/src/common/utils/stringutils.h index df807543..7c4b731a 100644 --- a/src/common/utils/stringutils.h +++ b/src/common/utils/stringutils.h @@ -5,13 +5,6 @@ #include #include -struct ConstQString : public QLatin1String -{ - constexpr ConstQString(const char *const s) : QLatin1String(s, static_cast(std::char_traits::length(s))) - { - } -}; - class StringUtils { public: diff --git a/src/filesystem/file.cpp b/src/filesystem/file.cpp index f705c837..baeed5ea 100755 --- a/src/filesystem/file.cpp +++ b/src/filesystem/file.cpp @@ -8,6 +8,7 @@ using namespace Qt::Literals::StringLiterals; using namespace Files; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmFileManager, "gm.files.manager") diff --git a/src/services/google/googledrive.cpp b/src/services/google/googledrive.cpp index b5d8b1d7..f122da13 100644 --- a/src/services/google/googledrive.cpp +++ b/src/services/google/googledrive.cpp @@ -6,6 +6,7 @@ using namespace Qt::Literals::StringLiterals; using namespace Services; +using namespace Common::Settings; constexpr auto AUTH_REQUEST_URL = "https://accounts.google.com/o/oauth2/auth"; constexpr auto AUTH_TOKEN_URL = "https://accounts.google.com/o/oauth2/token"; @@ -25,7 +26,7 @@ GoogleDrive::GoogleDrive(QNetworkAccessManager &networkManager, QObject *parent) GoogleDrive::GoogleDrive(const QString &serviceName, QNetworkAccessManager &networkManager, QObject *parent) : Service(serviceName, parent), m_networkManager(networkManager) { - clientId(SettingsManager::instance()->get(u"googleID"_s, u""_s, serviceName)); + clientId(SettingsManager::instance()->get(u"clientId"_s, u""_s, serviceName)); updateConnector(); } @@ -98,7 +99,7 @@ void GoogleDrive::updateConnector() void GoogleDrive::connectService() { qCDebug(gmGoogleDrive()) << "Connecting GoogleDrive ..."; - clientId(SettingsManager::instance()->get(u"googleID"_s, u""_s, serviceName())); + clientId(SettingsManager::instance()->get(u"clientId"_s, u""_s, serviceName())); updateConnector(); grant(); } @@ -107,8 +108,8 @@ void GoogleDrive::disconnectService() { connected(false); m_connector->disconnectService(); - SettingsManager::instance()->set(u"googleID"_s, u""_s, serviceName()); - SettingsManager::instance()->set(u"googleSecret"_s, u""_s, serviceName()); + SettingsManager::instance()->set(u"clientId"_s, u""_s, serviceName()); + SettingsManager::instance()->set(u"clientSecret"_s, u""_s, serviceName()); } void GoogleDrive::grant() diff --git a/src/services/google/googledriveconnectorlocal.cpp b/src/services/google/googledriveconnectorlocal.cpp index 668f183c..a0a16518 100644 --- a/src/services/google/googledriveconnectorlocal.cpp +++ b/src/services/google/googledriveconnectorlocal.cpp @@ -7,6 +7,7 @@ using namespace Qt::Literals::StringLiterals; using namespace Services; +using namespace Common::Settings; constexpr auto LOCAL_PORT = 59993; constexpr auto MAX_CONCURRENT_REQUESTS = 5; @@ -24,8 +25,8 @@ GoogleDriveConnectorLocal::GoogleDriveConnectorLocal(const QString &serviceName, config.port = LOCAL_PORT; config.maxConcurrentRequests = MAX_CONCURRENT_REQUESTS; config.authHeaderFormat = u"Bearer %1"_s; - config.idRequest = SettingRequest(u"googleID"_s, u""_s, serviceName); - config.secretRequest = SettingRequest(u"googleSecret"_s, u""_s, serviceName); + config.idRequest = Request(u"clientId"_s, u""_s, serviceName); + config.secretRequest = Request(u"clientSecret"_s, u""_s, serviceName); setConfig(config); diff --git a/src/services/nextcloud/nextcloud.cpp b/src/services/nextcloud/nextcloud.cpp index 166d9305..c06937b4 100644 --- a/src/services/nextcloud/nextcloud.cpp +++ b/src/services/nextcloud/nextcloud.cpp @@ -10,6 +10,7 @@ using namespace Qt::Literals::StringLiterals; using namespace Services; +using namespace Common::Settings; constexpr auto AUTH_URL = "/index.php/login/v2"; constexpr auto DAV_ENDPOINT = "/remote.php/dav/files"; diff --git a/src/services/nextcloud/nextcloud.h b/src/services/nextcloud/nextcloud.h index 72c480fd..cf3e3f64 100644 --- a/src/services/nextcloud/nextcloud.h +++ b/src/services/nextcloud/nextcloud.h @@ -18,7 +18,7 @@ class NextCloud : public Services::Service Q_OBJECT QML_ELEMENT QML_SINGLETON - QML_ONLY_SINGLETON_FACTORY(NextCloud) + QML_ONLY_SINGLETON_FACTORY(Services::NextCloud) public: explicit NextCloud(const QQmlEngine &engine, QObject *parent); diff --git a/src/services/rest/restserviceconnectorlocal.cpp b/src/services/rest/restserviceconnectorlocal.cpp index e0faf4cb..85439d85 100644 --- a/src/services/rest/restserviceconnectorlocal.cpp +++ b/src/services/rest/restserviceconnectorlocal.cpp @@ -9,6 +9,7 @@ using namespace Qt::Literals::StringLiterals; using namespace Services; +using namespace Common::Settings; RESTServiceConnectorLocal::RESTServiceConnectorLocal(QNetworkAccessManager &networkManager, O2 *o2, const QLoggingCategory &loggingCategory, QObject *parent = nullptr) diff --git a/src/services/rest/restserviceconnectorlocal.h b/src/services/rest/restserviceconnectorlocal.h index 9edbbd2a..26074311 100644 --- a/src/services/rest/restserviceconnectorlocal.h +++ b/src/services/rest/restserviceconnectorlocal.h @@ -21,8 +21,8 @@ struct RESTServiceLocalConfig int port; int maxConcurrentRequests; QString authHeaderFormat; - SettingRequest idRequest; - SettingRequest secretRequest; + Common::Settings::Request idRequest; + Common::Settings::Request secretRequest; }; class RESTServiceConnectorLocal : public RESTServiceConnector diff --git a/src/services/service.cpp b/src/services/service.cpp index d50f2fab..adfcfdbc 100644 --- a/src/services/service.cpp +++ b/src/services/service.cpp @@ -3,6 +3,7 @@ using namespace Qt::Literals::StringLiterals; using namespace Services; +using namespace Common::Settings; Service::Service(const QString &name, QObject *parent) : QObject(parent), a_status(new Status(this)), a_serviceName(name) diff --git a/src/services/spotify/clients/librespotcontroller.cpp b/src/services/spotify/clients/librespotcontroller.cpp index 583fc647..a8411f77 100644 --- a/src/services/spotify/clients/librespotcontroller.cpp +++ b/src/services/spotify/clients/librespotcontroller.cpp @@ -16,6 +16,7 @@ Q_LOGGING_CATEGORY(gmLibrespotController, "gm.service.spotify.clients.librespot" using namespace Qt::Literals::StringLiterals; using namespace Services; +using namespace Common::Settings; static constexpr int TRY_AGAIN_TIMEOUT_MS = 3000; static constexpr int PROCESS_TERMINATE_TIMEOUT_MS = 1000; @@ -39,7 +40,7 @@ auto LibrespotController::start() -> QFuture m_isExitExpected = false; - const auto username = SettingsManager::instance()->get(u"spotifyUsername"_s, u""_s, u"Spotify"_s); + const auto username = SettingsManager::instance()->get(u"username"_s, u""_s, u"Spotify"_s); auto password = SettingsManager::getPassword(username, u"Spotify"_s); if (username.isEmpty()) diff --git a/src/services/spotify/spotify.cpp b/src/services/spotify/spotify.cpp index ffa6d14a..696ddfde 100644 --- a/src/services/spotify/spotify.cpp +++ b/src/services/spotify/spotify.cpp @@ -11,13 +11,14 @@ using namespace Qt::Literals::StringLiterals; using namespace Services; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmSpotify, "gm.service.spotify") Spotify::Spotify(QObject *parent) : Service(u"Spotify"_s, parent) { m_networkManager = new QNetworkAccessManager(this); - username(SettingsManager::instance()->get(u"spotifyUsername"_s, u""_s, u"Spotify"_s)); + username(SettingsManager::instance()->get(u"username"_s, u""_s, u"Spotify"_s)); connect(m_librespotController.status(), &Status::messageChanged, this, &Spotify::forwardClientStatus); @@ -146,7 +147,7 @@ auto Spotify::clientStatus() const -> Status * void Spotify::connectService() { - username(SettingsManager::instance()->get(u"spotifyUsername"_s, u""_s, u"Spotify"_s)); + username(SettingsManager::instance()->get(u"username"_s, u""_s, u"Spotify"_s)); m_librespotController.start().then([this](bool success) { qCDebug(gmSpotify()) << "Client has started:" << success; @@ -164,9 +165,9 @@ void Spotify::disconnectService() connected(false); if (m_connector) m_connector->disconnectService(); SettingsManager::setPassword(username(), u""_s, u"Spotify"_s); - SettingsManager::instance()->set(u"spotifyUsername"_s, u""_s, u"Spotify"_s); - SettingsManager::instance()->set(u"spotifyID"_s, u""_s, u"Spotify"_s); - SettingsManager::instance()->set(u"spotifySecret"_s, u""_s, u"Spotify"_s); + SettingsManager::instance()->set(u"username"_s, u""_s, u"Spotify"_s); + SettingsManager::instance()->set(u"clientId"_s, u""_s, u"Spotify"_s); + SettingsManager::instance()->set(u"clientSecret"_s, u""_s, u"Spotify"_s); m_librespotController.stop(); } diff --git a/src/services/spotify/spotify.h b/src/services/spotify/spotify.h index 50aab9c0..1412b806 100644 --- a/src/services/spotify/spotify.h +++ b/src/services/spotify/spotify.h @@ -23,7 +23,7 @@ class Spotify : public Services::Service Q_OBJECT QML_ELEMENT QML_SINGLETON - QML_SINGLETON_FACTORY(Spotify) + QML_SINGLETON_FACTORY(Services::Spotify) Q_PROPERTY(Services::Status *clientStatus READ clientStatus NOTIFY clientStatusChanged) diff --git a/src/services/spotify/spotifyconnectorlocal.cpp b/src/services/spotify/spotifyconnectorlocal.cpp index 0f3779d6..cea9a528 100644 --- a/src/services/spotify/spotifyconnectorlocal.cpp +++ b/src/services/spotify/spotifyconnectorlocal.cpp @@ -16,8 +16,8 @@ SpotifyConnectorLocal::SpotifyConnectorLocal(QNetworkAccessManager &networkManag config.scope = SCOPE; config.port = LOCAL_PORT; config.maxConcurrentRequests = MAX_REQUESTS; - config.idRequest = SettingRequest(u"spotifyID"_s, u""_s, u"Spotify"_s); - config.secretRequest = SettingRequest(u"spotifySecret"_s, u""_s, u"Spotify"_s); + config.idRequest = Common::Settings::Request(u"clientId"_s, u""_s, u"Spotify"_s); + config.secretRequest = Common::Settings::Request(u"clientSecret"_s, u""_s, u"Spotify"_s); setConfig(config); } diff --git a/src/services/spotify/spotifyconnectorserver.cpp b/src/services/spotify/spotifyconnectorserver.cpp index 0049392c..63fbe09f 100644 --- a/src/services/spotify/spotifyconnectorserver.cpp +++ b/src/services/spotify/spotifyconnectorserver.cpp @@ -12,6 +12,7 @@ using namespace Qt::Literals::StringLiterals; using namespace Services; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmSpotifyServer, "gm.service.spotify.server") diff --git a/src/tools/audio/audiosaveload.cpp b/src/tools/audio/audiosaveload.cpp index 41b38ba6..c1d1cf8a 100644 --- a/src/tools/audio/audiosaveload.cpp +++ b/src/tools/audio/audiosaveload.cpp @@ -13,6 +13,7 @@ using namespace Qt::Literals::StringLiterals; using namespace Files; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmAudioSaveLoad, "gm.audio.saveload") diff --git a/src/tools/audio/editor/audioeditor.cpp b/src/tools/audio/editor/audioeditor.cpp index 148c8ea9..5474ecc6 100644 --- a/src/tools/audio/editor/audioeditor.cpp +++ b/src/tools/audio/editor/audioeditor.cpp @@ -10,6 +10,7 @@ using namespace Qt::Literals::StringLiterals; using namespace Services; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmAudioEditor, "gm.audio.editor") diff --git a/src/tools/audio/editor/audioeditor.h b/src/tools/audio/editor/audioeditor.h index cd830dc7..f1577981 100644 --- a/src/tools/audio/editor/audioeditor.h +++ b/src/tools/audio/editor/audioeditor.h @@ -128,7 +128,7 @@ class AudioEditor : public AbstractTool Q_INVOKABLE void loadElement(QObject *element); [[nodiscard]] Q_INVOKABLE QString resourcesPath() const { - return SettingsManager::getPath(QStringLiteral("resources")); + return Common::Settings::SettingsManager::getPath(QStringLiteral("resources")); } [[nodiscard]] Q_INVOKABLE QString basePath() const; diff --git a/src/tools/audio/editor/audioeditorfilebrowser.cpp b/src/tools/audio/editor/audioeditorfilebrowser.cpp index 5498cb55..272762de 100644 --- a/src/tools/audio/editor/audioeditorfilebrowser.cpp +++ b/src/tools/audio/editor/audioeditorfilebrowser.cpp @@ -7,6 +7,7 @@ #include using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmAudioEditorFileBrowser, "gm.audio.editor.filebrowser") diff --git a/src/tools/audio/editor/audioexporter.cpp b/src/tools/audio/editor/audioexporter.cpp index 7cfbb084..a94cd906 100644 --- a/src/tools/audio/editor/audioexporter.cpp +++ b/src/tools/audio/editor/audioexporter.cpp @@ -6,6 +6,7 @@ #include using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmAudioExporter, "gm.audio.exporter") diff --git a/src/tools/audio/players/bufferedaudioplayer.cpp b/src/tools/audio/players/bufferedaudioplayer.cpp index 991f46ba..b5efd618 100644 --- a/src/tools/audio/players/bufferedaudioplayer.cpp +++ b/src/tools/audio/players/bufferedaudioplayer.cpp @@ -7,6 +7,7 @@ #include using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmAudioBufferedPlayer, "gm.audio.buffered") diff --git a/src/tools/audio/playlist/resolvingaudioplaylist.cpp b/src/tools/audio/playlist/resolvingaudioplaylist.cpp index 920a68e0..e0a39ece 100644 --- a/src/tools/audio/playlist/resolvingaudioplaylist.cpp +++ b/src/tools/audio/playlist/resolvingaudioplaylist.cpp @@ -8,8 +8,9 @@ #include "utils/fileutils.h" #include -using namespace Services; using namespace Qt::Literals::StringLiterals; +using namespace Services; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmAudioPlaylistResolving, "gm.audio.playlist.resolving") diff --git a/src/tools/audio/thumbnails/audiothumbnail.cpp b/src/tools/audio/thumbnails/audiothumbnail.cpp index 15505187..47a92327 100755 --- a/src/tools/audio/thumbnails/audiothumbnail.cpp +++ b/src/tools/audio/thumbnails/audiothumbnail.cpp @@ -4,6 +4,7 @@ #include "utils/networkutils.h" using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; AudioThumbnail::AudioThumbnail(const QString &imageId, AudioElement *parent) : QObject(parent), element(parent), m_imageId(imageId) diff --git a/src/tools/audio/thumbnails/loaders/tagimageloader.cpp b/src/tools/audio/thumbnails/loaders/tagimageloader.cpp index 3992d290..ae9a0a67 100755 --- a/src/tools/audio/thumbnails/loaders/tagimageloader.cpp +++ b/src/tools/audio/thumbnails/loaders/tagimageloader.cpp @@ -12,11 +12,11 @@ #include using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; +using namespace TagLib; Q_LOGGING_CATEGORY(gmAudioTagImageLoader, "gm.audio.thumbnails.loaders.tag") -using namespace TagLib; - auto TagImageLoader::loadImageAsync(const AudioElement *element, const AudioFile *audioFile) -> QFuture { // Paranoid pointer check diff --git a/src/tools/characters/charactertool.cpp b/src/tools/characters/charactertool.cpp index 713eae7d..8657cad2 100644 --- a/src/tools/characters/charactertool.cpp +++ b/src/tools/characters/charactertool.cpp @@ -12,6 +12,7 @@ #include using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmCharactersTool, "gm.characters.tool") diff --git a/src/tools/converter/convertertool.cpp b/src/tools/converter/convertertool.cpp index d6222ee6..0b76e60e 100644 --- a/src/tools/converter/convertertool.cpp +++ b/src/tools/converter/convertertool.cpp @@ -10,6 +10,7 @@ #include using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmConverter, "gm.converter") diff --git a/src/tools/dicetool.cpp b/src/tools/dicetool.cpp index 6c8e5e8b..10ea8783 100644 --- a/src/tools/dicetool.cpp +++ b/src/tools/dicetool.cpp @@ -1,16 +1,16 @@ #include "dicetool.h" #include "settings/settingsmanager.h" -#include "utils/stringutils.h" #include using namespace Qt::Literals::StringLiterals; - -constexpr ConstQString DICE_SETTINGS = "Dice"; -constexpr ConstQString ENABLE_CRITICALS_SETTING = "enableCriticals"; -constexpr ConstQString SUCCESS_SETTING = "success"; -constexpr ConstQString FAILURE_SETTING = "failure"; -constexpr ConstQString USE_MIN_MAX_SETTING = "useMinMax"; -constexpr ConstQString SUCCESS_MAX_SETTING = "successMax"; +using namespace Common::Settings; + +constexpr auto DICE_SETTINGS = "Dice"; +constexpr auto ENABLE_CRITICALS_SETTING = "enableCriticals"; +constexpr auto SUCCESS_SETTING = "success"; +constexpr auto FAILURE_SETTING = "failure"; +constexpr auto USE_MIN_MAX_SETTING = "useMinMax"; +constexpr auto SUCCESS_MAX_SETTING = "successMax"; Q_LOGGING_CATEGORY(gmDiceTool, "gm.dice.tool") diff --git a/src/tools/generators/names/namegenerator.cpp b/src/tools/generators/names/namegenerator.cpp index 55b5b281..7a925368 100644 --- a/src/tools/generators/names/namegenerator.cpp +++ b/src/tools/generators/names/namegenerator.cpp @@ -13,6 +13,9 @@ using namespace Qt::Literals::StringLiterals; Q_LOGGING_CATEGORY(gmNameGenerator, "gm.generators.names") +static constexpr auto internalNamesPath = ":/names"_L1; +static constexpr auto addonNamesPath = "names"_L1; + auto NameGenerator::create(QQmlEngine *qmlEngine, QJSEngine *jsEngine) -> NameGenerator * { Q_UNUSED(jsEngine) diff --git a/src/tools/generators/names/namegenerator.h b/src/tools/generators/names/namegenerator.h index f753ab29..d185a94b 100644 --- a/src/tools/generators/names/namegenerator.h +++ b/src/tools/generators/names/namegenerator.h @@ -38,8 +38,5 @@ public slots: static auto findAndReadAllFiles(const QString &path) -> QByteArrayList; static auto findAndReadAllAddonFiles() -> QByteArrayList; - static constexpr ConstQString internalNamesPath = ":/names"; - static constexpr ConstQString addonNamesPath = "names"; - QList> m_generatorLists; }; diff --git a/src/tools/maps/map.cpp b/src/tools/maps/map.cpp index d13ed07c..bb26f8e7 100644 --- a/src/tools/maps/map.cpp +++ b/src/tools/maps/map.cpp @@ -14,6 +14,7 @@ #include using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmMapsMap, "gm.maps.map") diff --git a/src/tools/maps/maptool.cpp b/src/tools/maps/maptool.cpp index dd64d675..f8715a81 100644 --- a/src/tools/maps/maptool.cpp +++ b/src/tools/maps/maptool.cpp @@ -2,6 +2,7 @@ #include "filesystem/file.h" #include "filesystem/results/filelistresult.h" #include "settings/settingsmanager.h" +#include "utils/stringutils.h" #include "utils/utils.h" #include #include @@ -10,6 +11,7 @@ #include using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; static constexpr auto DEFAULT_COLOR = "red"; static constexpr auto DEFAULT_ICON = "\uf3c5"; diff --git a/src/tools/notes/notessaveload.cpp b/src/tools/notes/notessaveload.cpp index 261c46f4..fe87ba39 100644 --- a/src/tools/notes/notessaveload.cpp +++ b/src/tools/notes/notessaveload.cpp @@ -10,6 +10,7 @@ #include using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmNotesSaveLoad, "gm.notes.saveload") diff --git a/src/tools/shop/baseshoptool.cpp b/src/tools/shop/baseshoptool.cpp index b448895f..914a5a63 100644 --- a/src/tools/shop/baseshoptool.cpp +++ b/src/tools/shop/baseshoptool.cpp @@ -7,6 +7,7 @@ #include using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; static constexpr auto PROJECT_FILE_GLOB = "*.shop"; diff --git a/src/tools/shop/itemeditor.cpp b/src/tools/shop/itemeditor.cpp index 0f71c17d..21200fd8 100644 --- a/src/tools/shop/itemeditor.cpp +++ b/src/tools/shop/itemeditor.cpp @@ -10,6 +10,7 @@ #include using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmShopsItemEditor, "gm.shops.items.editor") diff --git a/src/tools/shop/shopeditor.cpp b/src/tools/shop/shopeditor.cpp index 5016a522..635aba8b 100644 --- a/src/tools/shop/shopeditor.cpp +++ b/src/tools/shop/shopeditor.cpp @@ -11,6 +11,7 @@ #include using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; Q_LOGGING_CATEGORY(gmShopsEditor, "gm.shops.editor") diff --git a/tests/common/settings/testsettingsmanager.cpp b/tests/common/settings/testsettingsmanager.cpp index cb7f97f4..1cbad6e8 100644 --- a/tests/common/settings/testsettingsmanager.cpp +++ b/tests/common/settings/testsettingsmanager.cpp @@ -3,6 +3,7 @@ #include using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; TEST(SettingsManagerTest, CanReadWritePassword) { diff --git a/tests/common/utils/teststringutils.cpp b/tests/common/utils/teststringutils.cpp index cee1913a..fbc714a2 100644 --- a/tests/common/utils/teststringutils.cpp +++ b/tests/common/utils/teststringutils.cpp @@ -47,13 +47,6 @@ TEST(StringUtilsTest, HasWildcardMatch) } } -constexpr ConstQString constString = "Test String"; - -TEST(StringUtilsTest, CanConstructCompileTimeString) -{ - EXPECT_EQ(constString.toString().toStdString(), "Test String"); -} - TEST(StringUtilsTest, CanConvertJpgToStringAndBack) { QImage image(64, 64, QImage::Format_RGB32); diff --git a/tests/filesystem/testnextcloudaccess.cpp b/tests/filesystem/testnextcloudaccess.cpp index 73985e28..fb29e400 100644 --- a/tests/filesystem/testnextcloudaccess.cpp +++ b/tests/filesystem/testnextcloudaccess.cpp @@ -14,6 +14,7 @@ using namespace Qt::Literals::StringLiterals; using namespace Files; using namespace Services; +using namespace Common::Settings; class NextcloudAccessTest : public AbstractAccessTest { diff --git a/tests/testhelper/abstracttest.cpp b/tests/testhelper/abstracttest.cpp index 4bdf57f9..02359202 100644 --- a/tests/testhelper/abstracttest.cpp +++ b/tests/testhelper/abstracttest.cpp @@ -7,6 +7,7 @@ using namespace Qt::Literals::StringLiterals; using namespace Files; +using namespace Common::Settings; AbstractTest::AbstractTest() : StaticAbstractTest() { diff --git a/tests/tools/audio/testresolvingaudioplaylist.cpp b/tests/tools/audio/testresolvingaudioplaylist.cpp index d1b89187..13d49dca 100644 --- a/tests/tools/audio/testresolvingaudioplaylist.cpp +++ b/tests/tools/audio/testresolvingaudioplaylist.cpp @@ -12,6 +12,7 @@ #endif using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; class PlaylistMockNetworkManager : public AbstractMockNetworkManager { diff --git a/tests/tools/converter/testconvertertool.cpp b/tests/tools/converter/testconvertertool.cpp index f2a15714..de15fafb 100644 --- a/tests/tools/converter/testconvertertool.cpp +++ b/tests/tools/converter/testconvertertool.cpp @@ -4,6 +4,8 @@ #include "tests/testhelper/staticabstracttest.h" #include +using namespace Common::Settings; + class ConverterToolTest : public StaticAbstractTest { public: diff --git a/tests/tools/notes/testnotestool.cpp b/tests/tools/notes/testnotestool.cpp index f31ca74f..7218cc82 100644 --- a/tests/tools/notes/testnotestool.cpp +++ b/tests/tools/notes/testnotestool.cpp @@ -18,6 +18,7 @@ #endif using namespace Qt::Literals::StringLiterals; +using namespace Common::Settings; class MockNetworkManager : public AbstractMockNetworkManager { diff --git a/tests/tools/shop/testshopeditor.cpp b/tests/tools/shop/testshopeditor.cpp index ebf98d23..0bc0eeea 100644 --- a/tests/tools/shop/testshopeditor.cpp +++ b/tests/tools/shop/testshopeditor.cpp @@ -6,6 +6,8 @@ #include #include +using namespace Common::Settings; + class ShopEditorTest : public StaticAbstractTest { public: diff --git a/tests/tools/shop/testshoptool.cpp b/tests/tools/shop/testshoptool.cpp index 8c67a5cb..57d0d6d0 100644 --- a/tests/tools/shop/testshoptool.cpp +++ b/tests/tools/shop/testshoptool.cpp @@ -4,6 +4,8 @@ #include "utils/fileutils.h" #include +using namespace Common::Settings; + class ShopToolTest : public StaticAbstractTest { public: