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) 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 : #ifndef MU_PROJECT_PROJECTAUTOSAVER_H
23 : #define MU_PROJECT_PROJECTAUTOSAVER_H
24 :
25 : #include <QTimer>
26 :
27 : #include "async/asyncable.h"
28 :
29 : #include "modularity/ioc.h"
30 : #include "project/iprojectsession.h"
31 : #include "io/ifilesystem.h"
32 : #include "iprojectconfiguration.h"
33 :
34 : #include "../iprojectautosaver.h"
35 :
36 : namespace mu::project {
37 : class ProjectAutoSaver : public IProjectAutoSaver, public muse::async::Asyncable, public muse::Contextable
38 : {
39 : muse::GlobalInject<muse::io::IFileSystem> fileSystem;
40 : muse::GlobalInject<IProjectConfiguration> configuration;
41 : muse::ContextInject<project::IProjectSession> projectSession = { this };
42 :
43 : public:
44 0 : ProjectAutoSaver(const muse::modularity::ContextPtr& iocCtx)
45 0 : : muse::Contextable(iocCtx)
46 0 : {}
47 :
48 : void init();
49 :
50 : bool projectHasUnsavedChanges(const muse::io::path_t& projectPath) const override;
51 : void removeProjectUnsavedChanges(const muse::io::path_t& projectPath) override;
52 :
53 : bool isAutosaveOfNewlyCreatedProject(const muse::io::path_t& projectPath) const override;
54 :
55 : muse::io::path_t projectOriginalPath(const muse::io::path_t& projectAutoSavePath) const override;
56 : muse::io::path_t projectAutoSavePath(const muse::io::path_t& projectPath) const override;
57 :
58 : private:
59 : INotationProjectPtr currentProject() const;
60 :
61 : void update();
62 :
63 : void onTrySave();
64 :
65 : muse::io::path_t projectPath(INotationProjectPtr project) const;
66 :
67 : QTimer m_timer;
68 : muse::io::path_t m_lastProjectPathNeedingAutosave;
69 : };
70 : }
71 :
72 : #endif // MU_PROJECT_PROJECTAUTOSAVER_H
|