Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2024 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #include "musesoundsconfiguration.h"
23 :
24 : #include <QLocale>
25 :
26 : #include "settings.h"
27 : #include "translation.h"
28 : #include "log.h"
29 :
30 : using namespace mu::musesounds;
31 : using namespace muse;
32 : using namespace muse::network;
33 :
34 : static const std::string module_name("musesounds");
35 : static const Settings::Key CHECK_FOR_MUSESOUNDS_UPDATE_KEY(module_name, "musesounds/checkForUpdate");
36 : static const Settings::Key GET_SOUNDS_TEST_MODE_KEY(module_name, "musesounds/getSoundsTestMode");
37 : static const Settings::Key LAST_MUSESOUNDS_SHOWN_VERSION_KEY(module_name, "application/lastShownMuseSoundsReleaseVersion");
38 : static const Settings::Key SHOW_LOADING_FAILED_WARNING_KEY(module_name, "musesounds/showLoadingFailedWarning");
39 :
40 : static const Settings::Key MUSESOUNDS_CHECK_FOR_UPDATE_TEST_MODE(module_name, "musesounds/checkForUpdateTestMode");
41 :
42 : static const muse::String OPEN_SOUND_URL("https://www.musehub.com/muse-sounds/");
43 :
44 0 : static QString osCode()
45 : {
46 : #if defined(Q_OS_WIN)
47 : return "win";
48 : #elif defined(Q_OS_MAC)
49 : return "mac";
50 : #elif defined(Q_OS_LINUX)
51 0 : return "linux";
52 : #else
53 : UNREACHABLE;
54 : return QString();
55 : #endif
56 : }
57 :
58 0 : void MuseSoundsConfiguration::init()
59 : {
60 0 : settings()->setDefaultValue(CHECK_FOR_MUSESOUNDS_UPDATE_KEY, Val(true));
61 0 : settings()->setCanBeManuallyEdited(CHECK_FOR_MUSESOUNDS_UPDATE_KEY, true);
62 0 : settings()->setDescription(CHECK_FOR_MUSESOUNDS_UPDATE_KEY, muse::trc("musesounds", "Show occasional MuseHub promotions"));
63 0 : settings()->setDefaultValue(GET_SOUNDS_TEST_MODE_KEY, Val(false));
64 0 : settings()->setDefaultValue(MUSESOUNDS_CHECK_FOR_UPDATE_TEST_MODE, Val(false));
65 0 : settings()->setDefaultValue(SHOW_LOADING_FAILED_WARNING_KEY, Val(true));
66 0 : }
67 :
68 0 : bool MuseSoundsConfiguration::needCheckForMuseSoundsUpdate() const
69 : {
70 0 : return settings()->value(CHECK_FOR_MUSESOUNDS_UPDATE_KEY).toBool();
71 : }
72 :
73 0 : RequestHeaders MuseSoundsConfiguration::headers() const
74 : {
75 0 : RequestHeaders headers;
76 0 : headers.rawHeaders["Content-Type"] = "application/json";
77 0 : return headers;
78 0 : }
79 :
80 0 : UriQuery MuseSoundsConfiguration::soundsUri() const
81 : {
82 0 : return !getSoundsTestMode()
83 0 : ? UriQuery("https://customers-api.musehub.com/graphql/v3")
84 0 : : UriQuery("https://customers-api-dev.musehub.com/graphql/v3");
85 : }
86 :
87 0 : UriQuery MuseSoundsConfiguration::soundPageUri(const muse::String& soundCode) const
88 : {
89 0 : String utm = String("?utm_source=mss-app&utm_medium=mh-cta&utm_campaign=mss-app-home-mh-%1").arg(soundCode);
90 0 : return UriQuery(OPEN_SOUND_URL + soundCode + utm);
91 0 : }
92 :
93 0 : QUrl MuseSoundsConfiguration::checkForMuseSoundsUpdateUrl() const
94 : {
95 0 : return !getSoundsTestMode()
96 0 : ? QUrl("https://updates.musescore.org/feed/musesounds.latest.xml")
97 0 : : QUrl("https://updates.musescore.org/feed/musesounds.latest.test.xml");
98 : }
99 :
100 0 : QUrl MuseSoundsConfiguration::checkForMuseSamplerUpdateUrl() const
101 : {
102 0 : return QUrl("https://customers-api.musehub.com/graphql/v3");
103 : }
104 :
105 0 : QUrl MuseSoundsConfiguration::museSoundsTroubleshootUrl() const
106 : {
107 0 : return QUrl(QString("https://support.musehub.com/%1/articles/15070619-musesounds-missing-in-musescore-studio")
108 0 : .arg(QLocale().bcp47Name()));
109 : }
110 :
111 0 : QString MuseSoundsConfiguration::getMuseSamplerVersionQuery() const
112 : {
113 0 : return QString("{\"query\": \"{ product(id: \\\"8428d876-f808-4524-918b-63ae5ca3c70e\\\", productType: application) { "
114 0 : "... on ProductApplication { assets(os: %1) { version } } } }\"}").arg(osCode());
115 : }
116 :
117 0 : std::string MuseSoundsConfiguration::lastShownMuseSoundsReleaseVersion() const
118 : {
119 0 : return settings()->value(LAST_MUSESOUNDS_SHOWN_VERSION_KEY).toString();
120 : }
121 :
122 0 : void MuseSoundsConfiguration::setLastShownMuseSoundsReleaseVersion(const std::string& version)
123 : {
124 0 : settings()->setSharedValue(LAST_MUSESOUNDS_SHOWN_VERSION_KEY, Val(version));
125 0 : }
126 :
127 0 : bool MuseSoundsConfiguration::showLoadingFailedWarning() const
128 : {
129 0 : return settings()->value(SHOW_LOADING_FAILED_WARNING_KEY).toBool();
130 : }
131 :
132 0 : void MuseSoundsConfiguration::setShowLoadingFailedWarning(bool show)
133 : {
134 0 : settings()->setSharedValue(SHOW_LOADING_FAILED_WARNING_KEY, Val(show));
135 0 : }
136 :
137 0 : bool MuseSoundsConfiguration::museSoundsCheckForUpdateTestMode() const
138 : {
139 0 : return settings()->value(MUSESOUNDS_CHECK_FOR_UPDATE_TEST_MODE).toBool();
140 : }
141 :
142 0 : bool MuseSoundsConfiguration::getSoundsTestMode() const
143 : {
144 0 : return settings()->value(GET_SOUNDS_TEST_MODE_KEY).toBool();
145 : }
146 :
147 0 : void MuseSoundsConfiguration::setSoundsTestMode(bool enabled)
148 : {
149 0 : settings()->setSharedValue(GET_SOUNDS_TEST_MODE_KEY, Val(enabled));
150 0 : }
|