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) 2022 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 :
23 : #pragma once
24 :
25 : #include "iopenprojectscenario.h"
26 :
27 : #include <QString>
28 : #include <QUrl>
29 :
30 : #include "modularity/ioc.h"
31 : #include "async/asyncable.h"
32 : #include "project/iprojectsession.h"
33 : #include "cloud/musescorecom/imusescorecomservice.h"
34 : #include "interactive/iinteractive.h"
35 : #include "interactive/iplatforminteractive.h"
36 : #include "io/ifilesystem.h"
37 : #include "multiwindows/imultiwindowsprovider.h"
38 : #include "musesounds/imusesamplercheckstatusscenario.h"
39 : #include "musesounds/imusesoundscheckupdatescenario.h"
40 :
41 : #include "imscmetareader.h"
42 : #include "iprojectautosaver.h"
43 : #include "iprojectconfiguration.h"
44 : #include "inotationreadersregister.h"
45 : #include "iprojectcreator.h"
46 : #include "irecentfilescontroller.h"
47 : #include "iconvertfiletoscorescenario.h"
48 :
49 : namespace mu::project {
50 : class OpenProjectScenario : public IOpenProjectScenario, public muse::Contextable, public muse::async::Asyncable
51 : {
52 : friend class OpenProjectScenarioTests;
53 :
54 : public:
55 : muse::GlobalInject<IProjectConfiguration> configuration;
56 : muse::GlobalInject<muse::io::IFileSystem> fileSystem;
57 : muse::GlobalInject<muse::mi::IMultiWindowsProvider> multiwindowsProvider;
58 : muse::GlobalInject<muse::cloud::IMuseScoreComService> museScoreComService;
59 : muse::GlobalInject<IProjectCreator> projectCreator;
60 : muse::GlobalInject<INotationReadersRegister> readers;
61 : muse::GlobalInject<IMscMetaReader> mscMetaReader;
62 : muse::GlobalInject<muse::IPlatformInteractive> platformInteractive;
63 : muse::ContextInject<IProjectAutoSaver> projectAutoSaver = { this };
64 : muse::ContextInject<IRecentFilesController> recentFilesController = { this };
65 : muse::ContextInject<muse::IInteractive> interactive = { this };
66 : muse::ContextInject<project::IProjectSession> projectSession = { this };
67 : muse::ContextInject<musesounds::IMuseSoundsCheckUpdateScenario> museSoundsCheckUpdateScenario = { this };
68 : muse::ContextInject<musesounds::IMuseSamplerCheckStatusScenario> museSamplerCheckStatusScenario = { this };
69 : muse::ContextInject<IConvertFileToScoreScenario> convertFileToScoreScenario = { this };
70 :
71 51 : OpenProjectScenario(const muse::modularity::ContextPtr& iocCtx)
72 51 : : muse::Contextable(iocCtx) {}
73 :
74 : bool isUrlSupported(const QUrl& url) const override;
75 : bool isFileSupported(const muse::io::path_t& path) const override;
76 :
77 : muse::async::Promise<muse::Ret> openProject(const ProjectFile& file) override;
78 : muse::async::Promise<muse::Ret> openProject(const muse::io::path_t& path, const QString& displayNameOverride = QString()) override;
79 : muse::async::Promise<muse::Ret> openProject(const muse::rcommand::Params& params) override;
80 :
81 : muse::async::Promise<muse::Ret> revertToLastSaved() override;
82 : muse::Ret finishOpening() override;
83 :
84 : muse::Uri resolveNotationPageUri() const override;
85 :
86 : const ProjectBeingDownloaded& projectBeingDownloaded() const override;
87 : muse::async::Notification projectBeingDownloadedChanged() const override;
88 :
89 : bool isBusy(BusyStatus status) const override;
90 : muse::async::Notification busyChanged() const override;
91 :
92 : private:
93 : template<typename T>
94 38 : static muse::async::Promise<T> resolvedPromise(const T& value)
95 : {
96 114 : return muse::async::make_promise<T>([value](auto resolve) {
97 38 : return resolve(value);
98 76 : });
99 : }
100 :
101 : bool isProjectOpened(const muse::io::path_t& scorePath) const;
102 :
103 : void setBusy(BusyStatus status, bool isBusy);
104 : muse::async::Promise<muse::Ret> runIfNotBusy(BusyStatus status, const std::function<muse::async::Promise<muse::Ret>()>& flow);
105 :
106 : muse::async::Promise<muse::RetVal<INotationProjectPtr> > loadProject(const muse::io::path_t& filePath);
107 : muse::async::Promise<muse::Ret> loadWithFallback(const std::shared_ptr<INotationProject>& project, const muse::io::path_t& loadPath,
108 : const std::string& format);
109 :
110 : muse::async::Promise<muse::Ret> doOpenProject(const muse::io::path_t& filePath);
111 : muse::async::Promise<muse::Ret> doOpenCloudProject(const muse::io::path_t& filePath, const CloudProjectInfo& info, bool isOwner = true);
112 : muse::async::Promise<muse::Ret> doOpenCloudProjectOffline(const muse::io::path_t& filePath, const QString& displayNameOverride);
113 :
114 : muse::async::Promise<muse::Ret> downloadAndOpenCloudProject(int scoreId,
115 : const QString& hash = QString(),
116 : const QString& secret = QString(), bool isOwner = true);
117 : muse::async::Promise<muse::Ret> doDownloadAndOpenCloudProject(int scoreId, const QString& hash, const QString& secret, bool isOwner);
118 : muse::async::Promise<muse::Ret> downloadCloudProject(int scoreId, const muse::io::path_t& localPath, const QString& hash,
119 : const QString& secret, const CloudProjectInfo& info, bool isOwner);
120 : muse::async::Promise<muse::Ret> openMuseScoreUrl(const QUrl& url);
121 : muse::async::Promise<muse::Ret> openScoreFromMuseScoreCom(const QUrl& url);
122 : muse::async::Promise<muse::Ret> openScoreFromMuseScoreCom(const QUrl& url, int scoreId, const muse::cloud::ScoreInfo& scoreInfo);
123 :
124 : muse::Ret openPageIfNeed(muse::Uri pageUri);
125 :
126 : muse::async::Promise<muse::RetVal<muse::Val> > openDialog(const muse::UriQuery& query) const;
127 : muse::async::Promise<muse::RetVal<muse::Val> > ensureAuthorization() const;
128 :
129 : muse::async::Promise<bool> shouldRetryLoadAfterError(const muse::Ret& ret, const muse::io::path_t& filepath);
130 : muse::async::Promise<bool> askIfUserAgreesToOpenProjectWithIncompatibleVersion(const std::string& errorText);
131 : void warnFileTooNew(const muse::io::path_t& filepath);
132 : muse::async::Promise<bool> askIfUserAgreesToOpenCorruptedProject(const muse::String& projectName, const std::string& errorText);
133 : void warnProjectCriticallyCorrupted(const muse::String& projectName, const std::string& errorText);
134 : void warnProjectCannotBeOpened(const muse::Ret& ret, const muse::io::path_t& filepath);
135 :
136 : void showCloudOpenError(const muse::Ret& ret) const;
137 :
138 : muse::async::Promise<muse::io::path_t> selectScoreOpeningFile() const;
139 :
140 : RecentFile makeRecentFile(INotationProjectPtr project);
141 :
142 : std::set<BusyStatus> m_busyStatuses;
143 : muse::async::Notification m_busyChanged;
144 :
145 : ProjectBeingDownloaded m_projectBeingDownloaded;
146 : muse::async::Notification m_projectBeingDownloadedChanged;
147 : };
148 : }
|