Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2026 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 "deletecloudscorescenario.h"
23 :
24 : #include <QString>
25 : #include <QVariantMap>
26 :
27 : #include "translation.h"
28 : #include "types/uri.h"
29 : #include "types/val.h"
30 :
31 : #include "log.h"
32 :
33 : using namespace mu::project;
34 : using namespace muse;
35 :
36 : static const Uri DELETE_CLOUD_SCORE_URI("musescore://project/deletecloudscore");
37 :
38 6 : DeleteCloudScoreScenario::DeleteCloudScoreScenario(const modularity::ContextPtr& iocCtx)
39 12 : : Contextable(iocCtx)
40 : {
41 12 : }
42 :
43 7 : void DeleteCloudScoreScenario::deleteScore(int scoreId, const QString& scoreName)
44 : {
45 7 : if (scoreId <= 0) {
46 2 : return;
47 : }
48 :
49 5 : UriQuery query(DELETE_CLOUD_SCORE_URI);
50 15 : query.addParam("scoreName", Val(scoreName));
51 :
52 5 : interactive()->open(query)
53 5 : .onResolve(this, [this, scoreId](const Val& val) {
54 5 : const QVariantMap map = val.toQVariant().toMap();
55 5 : if (map.value("agreesToDelete").toBool()) {
56 3 : doDeleteScore(scoreId);
57 : }
58 5 : });
59 5 : }
60 :
61 5 : async::Channel<int> DeleteCloudScoreScenario::scoreDeleted() const
62 : {
63 5 : return m_scoreDeleted;
64 : }
65 :
66 3 : void DeleteCloudScoreScenario::doDeleteScore(int scoreId)
67 : {
68 3 : museScoreComService()->deleteScore(scoreId)
69 3 : .onResolve(this, [this, scoreId](const Ret& ret) {
70 3 : if (!ret) {
71 1 : LOGE() << ret.toString();
72 4 : interactive()->error(muse::trc("project/cloud", "Unable to delete the score"),
73 2 : muse::trc("global", "Please check your internet connection or try again later."),
74 : { IInteractive::Button::Ok });
75 1 : return;
76 : }
77 :
78 2 : const io::path_t localPath = configuration()->cloudProjectPath(scoreId);
79 2 : recentFilesController()->removeRecentFile(localPath);
80 :
81 2 : const Ret removeRet = fileSystem()->remove(localPath);
82 2 : if (!removeRet) {
83 1 : LOGE() << removeRet.toString();
84 : }
85 :
86 2 : m_scoreDeleted.send(scoreId);
87 2 : });
88 3 : }
|