LCOV - code coverage report
Current view: top level - src/project/internal - openprojectscenario.h Coverage Total Hit
Test: filtered_coverage.info Lines: 100.0 % 6 6
Test Date: 2026-11-19 04:14:36

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

Generated by: LCOV version 2.0-1