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 :
23 : #include "mainwindowtitleprovider.h"
24 :
25 : #include "translation.h"
26 :
27 : #include "notation/inotation.h"
28 : #include "project/inotationproject.h"
29 :
30 : using namespace mu::appshell;
31 :
32 0 : MainWindowTitleProvider::MainWindowTitleProvider(QObject* parent)
33 0 : : QObject(parent), muse::Contextable(muse::iocCtxForQmlObject(this))
34 : {
35 0 : }
36 :
37 0 : void MainWindowTitleProvider::load()
38 : {
39 0 : update();
40 :
41 0 : context()->projectChanged().onNotify(this, [this]() {
42 0 : if (auto currentProject = context()->project()) {
43 0 : currentProject->displayNameChanged().onNotify(this, [this]() {
44 0 : update();
45 0 : });
46 :
47 0 : currentProject->needSaveChanged().onNotify(this, [this]() {
48 0 : update();
49 0 : });
50 0 : }
51 0 : });
52 :
53 0 : context()->currentNotationChanged().onNotify(this, [this]() {
54 0 : update();
55 0 : });
56 0 : }
57 :
58 0 : QString MainWindowTitleProvider::title() const
59 : {
60 0 : return m_title;
61 : }
62 :
63 0 : QString MainWindowTitleProvider::filePath() const
64 : {
65 0 : return m_filePath;
66 : }
67 :
68 0 : bool MainWindowTitleProvider::fileModified() const
69 : {
70 0 : return m_fileModified;
71 : }
72 :
73 0 : void MainWindowTitleProvider::setTitle(const QString& title)
74 : {
75 0 : if (title == m_title) {
76 0 : return;
77 : }
78 :
79 0 : m_title = title;
80 0 : emit titleChanged(title);
81 : }
82 :
83 0 : void MainWindowTitleProvider::setFilePath(const QString& filePath)
84 : {
85 0 : if (filePath == m_filePath) {
86 0 : return;
87 : }
88 :
89 0 : m_filePath = filePath;
90 0 : emit filePathChanged(filePath);
91 : }
92 :
93 0 : void MainWindowTitleProvider::setFileModified(bool fileModified)
94 : {
95 0 : if (fileModified == m_fileModified) {
96 0 : return;
97 : }
98 :
99 0 : m_fileModified = fileModified;
100 0 : emit fileModifiedChanged(fileModified);
101 : }
102 :
103 0 : void MainWindowTitleProvider::update()
104 : {
105 0 : project::INotationProjectPtr project = context()->project();
106 :
107 0 : if (!project) {
108 0 : setTitle(muse::qtrc("appshell", "MuseScore Studio"));
109 0 : setFilePath("");
110 0 : setFileModified(false);
111 0 : return;
112 : }
113 :
114 0 : notation::INotationPtr notation = context()->currentNotation();
115 0 : setTitle(notation->projectNameAndPartName());
116 :
117 0 : setFilePath((project->isNewlyCreated() || project->isCloudProject())
118 0 : ? "" : project->path().toQString());
119 0 : setFileModified(project->isNeedSave());
120 0 : }
|