55 * MuseScore
66 * Music Composition & Notation
77 *
8- * Copyright (C) 2024 MuseScore Limited and others
8+ * Copyright (C) 2025 MuseScore Limited and others
99 *
1010 * This program is free software: you can redistribute it and/or modify
1111 * it under the terms of the GNU General Public License version 3 as
2424
2525#include " serialization/json.h"
2626
27- #include " global/concurrency/concurrent.h"
28-
2927using namespace mu ::musesounds;
3028using namespace muse ;
3129using namespace muse ::network;
@@ -46,37 +44,7 @@ static muse::UriQuery correctThumbnailSize(const UriQuery& uri)
4644 return UriQuery (uriStr.toStdString ());
4745}
4846
49- void MuseSoundsRepository::init ()
50- {
51- auto soundsCallBack = [this ](const RetVal<SoundCatalogueInfoList>& result) {
52- if (!result.ret ) {
53- LOGE () << result.ret .toString ();
54- return ;
55- }
56-
57- {
58- std::lock_guard lock (m_mutex);
59- m_soundsСatalogs = result.val ;
60- }
61-
62- m_soundsСatalogsChanged.notify ();
63- };
64-
65- Concurrent::run (this , &MuseSoundsRepository::th_requestSounds, configuration ()->soundsUri (), soundsCallBack);
66- }
67-
68- const SoundCatalogueInfoList& MuseSoundsRepository::soundsCatalogueList () const
69- {
70- std::lock_guard lock (m_mutex);
71- return m_soundsСatalogs;
72- }
73-
74- async::Notification MuseSoundsRepository::soundsCatalogueListChanged () const
75- {
76- return m_soundsСatalogsChanged;
77- }
78-
79- QByteArray MuseSoundsRepository::soundsRequestJson () const
47+ static QByteArray soundsRequestJson ()
8048{
8149 QLocale locale = QLocale ();
8250 String localeStr = locale.bcp47Name () + " -" + QLocale::territoryToCode (locale.territory ());
@@ -114,35 +82,51 @@ QByteArray MuseSoundsRepository::soundsRequestJson() const
11482 return JsonDocument (json).toJson (JsonDocument::Format::Compact).toQByteArray ();
11583}
11684
117- void MuseSoundsRepository::th_requestSounds ( const UriQuery& soundsUri, std::function< void (RetVal<SoundCatalogueInfoList>)> callBack) const
85+ void MuseSoundsRepository::init ()
11886{
11987 TRACEFUNC;
12088
121- network::deprecated::INetworkManagerPtr networkManager = networkManagerCreator ()->makeDeprecatedNetworkManager ();
89+ QUrl url = QUrl (QString::fromStdString (configuration ()->soundsUri ().toString ()));
90+ QByteArray jsonData = soundsRequestJson ();
12291 RequestHeaders headers = configuration ()->headers ();
12392
124- QByteArray jsonData = soundsRequestJson ();
125- QBuffer receivedData (& jsonData);
126- OutgoingDevice device (& receivedData);
93+ auto device = std::make_shared<QBuffer> ();
94+ device-> setData ( jsonData);
95+ auto receivedData = std::make_shared<QBuffer>( );
12796
128- Ret soundsItemsRet = networkManager->post (QUrl (QString::fromStdString (soundsUri.toString ())), &device, &receivedData, headers);
129- if (!soundsItemsRet) {
130- callBack (soundsItemsRet);
131- return ;
132- }
97+ m_networkManager = networkManagerCreator ()->makeNetworkManager ();
98+ m_networkManager->post (url, device, receivedData, headers)
99+ .onResolve (this , [this , receivedData](const muse::Ret& ret) {
100+ if (!ret) {
101+ LOGE () << ret.toString ();
102+ return ;
103+ }
133104
134- RetVal<SoundCatalogueInfoList> result;
105+ RetVal<SoundCatalogueInfoList> result;
135106
136- std::string err;
137- JsonDocument soundsInfoDoc = JsonDocument::fromJson (ByteArray::fromQByteArray (receivedData.data ()), &err);
138- if (!err.empty ()) {
139- result.ret = make_ret (Ret::Code::InternalError, err);
140- } else {
141- result.ret = make_ok ();
142- result.val = parseSounds (soundsInfoDoc);
143- }
107+ std::string err;
108+ JsonDocument soundsInfoDoc = JsonDocument::fromJson (ByteArray::fromQByteArray (receivedData->data ()), &err);
109+ if (!err.empty ()) {
110+ result.ret = make_ret (Ret::Code::InternalError, err);
111+ } else {
112+ result.ret = make_ok ();
113+ result.val = parseSounds (soundsInfoDoc);
114+ }
115+
116+ m_soundsСatalogs = result.val ;
117+ m_soundsСatalogsChanged.notify ();
118+ m_networkManager = nullptr ;
119+ });
120+ }
121+
122+ const SoundCatalogueInfoList& MuseSoundsRepository::soundsCatalogueList () const
123+ {
124+ return m_soundsСatalogs;
125+ }
144126
145- callBack (result);
127+ async::Notification MuseSoundsRepository::soundsCatalogueListChanged () const
128+ {
129+ return m_soundsСatalogsChanged;
146130}
147131
148132SoundCatalogueInfoList MuseSoundsRepository::parseSounds (const JsonDocument& soundsDoc) const
0 commit comments