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) 2021 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 "workspacesdataprovider.h"
23 :
24 : #include "log.h"
25 :
26 : using namespace muse;
27 : using namespace muse::workspace;
28 :
29 0 : void WorkspacesDataProvider::init()
30 : {
31 0 : manager()->currentWorkspaceChanged().onNotify(this, [this]() {
32 0 : m_workspaceChanged.notify();
33 0 : for (auto& n : m_dataNotifications) {
34 0 : n.second.notify();
35 : }
36 0 : });
37 0 : }
38 :
39 0 : RetVal<QByteArray> WorkspacesDataProvider::rawData(DataKey key) const
40 : {
41 0 : IWorkspacePtr current = manager()->currentWorkspace();
42 0 : IF_ASSERT_FAILED(current) {
43 0 : return RetVal<QByteArray>(make_ret(Ret::Code::InternalError));
44 : }
45 :
46 0 : return current->rawData(key);
47 0 : }
48 :
49 0 : Ret WorkspacesDataProvider::setRawData(DataKey key, const QByteArray& data)
50 : {
51 0 : IWorkspacePtr current = manager()->currentWorkspace();
52 0 : IF_ASSERT_FAILED(current) {
53 0 : return make_ret(Ret::Code::InternalError);
54 : }
55 :
56 0 : Ret ret = current->setRawData(key, data);
57 :
58 0 : if (ret) {
59 0 : auto n = m_dataNotifications.find(key);
60 0 : if (n != m_dataNotifications.end()) {
61 0 : n->second.notify();
62 : }
63 : }
64 :
65 0 : return ret;
66 0 : }
67 :
68 0 : async::Notification WorkspacesDataProvider::dataChanged(DataKey key) const
69 : {
70 0 : return m_dataNotifications[key];
71 : }
72 :
73 0 : async::Notification WorkspacesDataProvider::workspaceChanged() const
74 : {
75 0 : return m_workspaceChanged;
76 : }
|