LCOV - code coverage report
Current view: top level - src/preferences/qml/MuseScore/Preferences - generalpreferencesmodel.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 0.0 % 160 0
Test Date: 2026-11-05 04:07:02

            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              : #include "generalpreferencesmodel.h"
      23              : 
      24              : #include "languages/languageserrors.h"
      25              : 
      26              : #include "log.h"
      27              : #include "translation.h"
      28              : 
      29              : using namespace mu::preferences;
      30              : using namespace muse;
      31              : using namespace muse::languages;
      32              : 
      33            0 : GeneralPreferencesModel::GeneralPreferencesModel(QObject* parent)
      34            0 :     : QObject(parent), muse::Contextable(muse::iocCtxForQmlObject(this))
      35              : {
      36            0 : }
      37              : 
      38            0 : void GeneralPreferencesModel::load()
      39              : {
      40            0 :     languagesConfiguration()->currentLanguageCode().ch.onReceive(this, [this](const QString& languageCode) {
      41            0 :         emit currentLanguageCodeChanged(languageCode);
      42            0 :     });
      43              : 
      44            0 :     setRestartRequired(languagesService()->restartRequiredToApplyLanguage());
      45            0 :     languagesService()->restartRequiredToApplyLanguageChanged().onReceive(this, [this](bool required) {
      46            0 :         setRestartRequired(required);
      47            0 :     });
      48              : 
      49            0 :     configuration()->startupModeTypeChanged().onNotify(this, [this]() {
      50            0 :         emit currentStartupModeChanged();
      51            0 :     });
      52              : 
      53            0 :     configuration()->startupScorePathChanged().onNotify(this, [this]() {
      54            0 :         emit startupScorePathChanged();
      55            0 :     });
      56              : 
      57            0 :     configuration()->welcomeDialogShowOnStartupChanged().onNotify(this, [this]() {
      58            0 :         emit showWelcomeDialogChanged();
      59            0 :     });
      60              : 
      61            0 :     updateConfiguration()->needCheckForUpdateChanged().onNotify(this, [this]() {
      62            0 :         emit needCheckForNewAppVersionChanged(needCheckForNewAppVersion());
      63            0 :     });
      64            0 : }
      65              : 
      66            0 : void GeneralPreferencesModel::checkUpdateForCurrentLanguage()
      67              : {
      68            0 :     QString languageCode = currentLanguageCode();
      69              : 
      70            0 :     m_languageUpdateProgress = languagesService()->update(languageCode);
      71              : 
      72            0 :     m_languageUpdateProgress.progressChanged().onReceive(this, [this](int64_t current, int64_t total, const std::string& status) {
      73            0 :         emit receivingUpdateForCurrentLanguage(current, total, QString::fromStdString(status));
      74            0 :     });
      75              : 
      76            0 :     m_languageUpdateProgress.finished().onReceive(this, [this, languageCode](const ProgressResult& res) {
      77            0 :         if (res.ret.code() == static_cast<int>(Err::AlreadyUpToDate)) {
      78            0 :             QString msg = muse::qtrc("preferences", "Your version of %1 is up to date.")
      79            0 :                           .arg(languagesService()->language(languageCode).name);
      80            0 :             interactive()->info(msg.toStdString(), std::string());
      81            0 :         }
      82            0 :     });
      83            0 : }
      84              : 
      85            0 : QVariantList GeneralPreferencesModel::languages() const
      86              : {
      87            0 :     QList<Language> languages = languagesService()->languages().values();
      88              : 
      89            0 :     std::sort(languages.begin(), languages.end(), [](const Language& l, const Language& r) {
      90            0 :         return l.code < r.code;
      91              :     });
      92              : 
      93            0 :     QVariantList result;
      94              : 
      95            0 :     for (const Language& language : languages) {
      96            0 :         QVariantMap languageObj;
      97            0 :         languageObj["code"] = language.code;
      98            0 :         languageObj["name"] = language.name;
      99            0 :         result << languageObj;
     100            0 :     }
     101              : 
     102            0 :     if (languagesService()->hasPlaceholderLanguage()) {
     103            0 :         QVariantMap placeholderLanguageObj;
     104            0 :         placeholderLanguageObj["code"] = PLACEHOLDER_LANGUAGE_CODE;
     105            0 :         placeholderLanguageObj["name"] = "«Placeholder translations»";
     106            0 :         result.prepend(placeholderLanguageObj);
     107            0 :     }
     108              : 
     109            0 :     QVariantMap systemLanguageObj;
     110            0 :     systemLanguageObj["code"] = SYSTEM_LANGUAGE_CODE;
     111            0 :     systemLanguageObj["name"] = muse::qtrc("preferences", "System default");
     112            0 :     result.prepend(systemLanguageObj);
     113              : 
     114            0 :     return result;
     115            0 : }
     116              : 
     117            0 : QString GeneralPreferencesModel::currentLanguageCode() const
     118              : {
     119            0 :     return languagesConfiguration()->currentLanguageCode().val;
     120              : }
     121              : 
     122            0 : QStringList GeneralPreferencesModel::keyboardLayouts() const
     123              : {
     124            0 :     NOT_IMPLEMENTED;
     125            0 :     return { "US-QWERTY", "UK-QWERTY", "QWERTZ", "AZERTY" };
     126              : }
     127              : 
     128            0 : QString GeneralPreferencesModel::currentKeyboardLayout() const
     129              : {
     130            0 :     return shortcutsConfiguration()->currentKeyboardLayout();
     131              : }
     132              : 
     133            0 : bool GeneralPreferencesModel::isOSCRemoteControl() const
     134              : {
     135            0 :     return false;
     136              : }
     137              : 
     138            0 : int GeneralPreferencesModel::oscPort() const
     139              : {
     140            0 :     return 0;
     141              : }
     142              : 
     143            0 : void GeneralPreferencesModel::setCurrentLanguageCode(const QString& currentLanguageCode)
     144              : {
     145            0 :     if (currentLanguageCode == this->currentLanguageCode()) {
     146            0 :         return;
     147              :     }
     148              : 
     149            0 :     languagesConfiguration()->setCurrentLanguageCode(currentLanguageCode);
     150              : }
     151              : 
     152            0 : void GeneralPreferencesModel::setCurrentKeyboardLayout(const QString& keyboardLayout)
     153              : {
     154            0 :     if (keyboardLayout == this->currentKeyboardLayout()) {
     155            0 :         return;
     156              :     }
     157              : 
     158            0 :     shortcutsConfiguration()->setCurrentKeyboardLayout(keyboardLayout);
     159            0 :     emit currentKeyboardLayoutChanged();
     160              : }
     161              : 
     162            0 : void GeneralPreferencesModel::setIsOSCRemoteControl(bool isOSCRemoteControl)
     163              : {
     164            0 :     NOT_IMPLEMENTED;
     165            0 :     emit isOSCRemoteControlChanged(isOSCRemoteControl);
     166            0 : }
     167              : 
     168            0 : void GeneralPreferencesModel::setOscPort(int oscPort)
     169              : {
     170            0 :     NOT_IMPLEMENTED;
     171            0 :     emit oscPortChanged(oscPort);
     172            0 : }
     173              : 
     174            0 : bool GeneralPreferencesModel::restartRequired() const
     175              : {
     176            0 :     return m_restartRequired;
     177              : }
     178              : 
     179            0 : void GeneralPreferencesModel::setRestartRequired(bool restartRequired)
     180              : {
     181            0 :     if (m_restartRequired == restartRequired) {
     182            0 :         return;
     183              :     }
     184            0 :     m_restartRequired = restartRequired;
     185            0 :     emit restartRequiredChanged();
     186              : }
     187              : 
     188            0 : QVariantList GeneralPreferencesModel::startupModes() const
     189              : {
     190              :     const QVariantList result {
     191            0 :         QVariantMap {
     192            0 :             { "title", muse::qtrc("preferences", "Start empty") },
     193            0 :             { "value", static_cast<int>(appshell::StartupModeType::StartEmpty) },
     194            0 :         },
     195            0 :         QVariantMap {
     196            0 :             { "title", muse::qtrc("preferences", "Continue last session") },
     197            0 :             { "value", static_cast<int>(appshell::StartupModeType::ContinueLastSession) },
     198            0 :         },
     199            0 :         QVariantMap {
     200            0 :             { "title", muse::qtrc("preferences", "Start with new score") },
     201            0 :             { "value", static_cast<int>(appshell::StartupModeType::StartWithNewScore) },
     202            0 :         },
     203            0 :         QVariantMap {
     204            0 :             { "title", muse::qtrc("preferences", "Start with score") },
     205            0 :             { "value", static_cast<int>(appshell::StartupModeType::StartWithScore) },
     206              :             { "isStartWithScore", true },
     207            0 :         },
     208            0 :     };
     209              : 
     210            0 :     return result;
     211            0 : }
     212              : 
     213            0 : int GeneralPreferencesModel::currentStartupMode() const
     214              : {
     215            0 :     return static_cast<int>(configuration()->startupModeType());
     216              : }
     217              : 
     218            0 : void GeneralPreferencesModel::setCurrentStartupMode(int modeIndex)
     219              : {
     220            0 :     if (modeIndex < 0 || modeIndex >= 4) {
     221            0 :         return;
     222              :     }
     223              : 
     224            0 :     appshell::StartupModeType selectedType = static_cast<appshell::StartupModeType>(modeIndex);
     225            0 :     if (selectedType == configuration()->startupModeType()) {
     226            0 :         return;
     227              :     }
     228              : 
     229            0 :     configuration()->setStartupModeType(selectedType);
     230              : }
     231              : 
     232            0 : QString GeneralPreferencesModel::startupScorePath() const
     233              : {
     234            0 :     return configuration()->startupScorePath().toQString();
     235              : }
     236              : 
     237            0 : void GeneralPreferencesModel::setStartupScorePath(const QString& scorePath)
     238              : {
     239            0 :     if (scorePath.isEmpty() || scorePath == startupScorePath()) {
     240            0 :         return;
     241              :     }
     242              : 
     243            0 :     configuration()->setStartupScorePath(scorePath);
     244              : }
     245              : 
     246            0 : QStringList GeneralPreferencesModel::scorePathFilter() const
     247              : {
     248            0 :     return { muse::qtrc("preferences", "MuseScore file") + " (*.mscz)",
     249            0 :              muse::qtrc("preferences", "All") + " (*)" };
     250            0 : }
     251              : 
     252            0 : bool GeneralPreferencesModel::showWelcomeDialog() const
     253              : {
     254            0 :     return configuration()->welcomeDialogShowOnStartup();
     255              : }
     256              : 
     257            0 : void GeneralPreferencesModel::setShowWelcomeDialog(bool show)
     258              : {
     259            0 :     if (configuration()->welcomeDialogShowOnStartup() == show) {
     260            0 :         return;
     261              :     }
     262              : 
     263            0 :     configuration()->setWelcomeDialogShowOnStartup(show);
     264              : }
     265              : 
     266            0 : bool GeneralPreferencesModel::isAppUpdatable() const
     267              : {
     268            0 :     return updateConfiguration()->isAppUpdatable();
     269              : }
     270              : 
     271            0 : bool GeneralPreferencesModel::needCheckForNewAppVersion() const
     272              : {
     273            0 :     return updateConfiguration()->needCheckForUpdate();
     274              : }
     275              : 
     276            0 : void GeneralPreferencesModel::setNeedCheckForNewAppVersion(bool value)
     277              : {
     278            0 :     if (value == needCheckForNewAppVersion()) {
     279            0 :         return;
     280              :     }
     281              : 
     282            0 :     updateConfiguration()->setNeedCheckForUpdate(value);
     283            0 :     emit needCheckForNewAppVersionChanged(value);
     284              : 
     285              :     //! NOTE: Updates can not be downloaded without checking for them; once checking
     286              :     //! is turned on again, downloading is turned on with it, whatever it was before
     287            0 :     setAutoUpdateNewAppVersion(value);
     288              : }
     289              : 
     290            0 : bool GeneralPreferencesModel::autoUpdateNewAppVersion() const
     291              : {
     292            0 :     return updateConfiguration()->autoUpdateEnabled();
     293              : }
     294              : 
     295            0 : void GeneralPreferencesModel::setAutoUpdateNewAppVersion(bool value)
     296              : {
     297            0 :     if (value == autoUpdateNewAppVersion()) {
     298            0 :         return;
     299              :     }
     300              : 
     301            0 :     updateConfiguration()->setAutoUpdateEnabled(value);
     302            0 :     emit autoUpdateNewAppVersionChanged(value);
     303              : }
     304              : 
     305            0 : QString GeneralPreferencesModel::museScorePrivacyPolicyUrl() const
     306              : {
     307            0 :     return QString::fromStdString(updateConfiguration()->privacyPolicyUrl());
     308              : }
        

Generated by: LCOV version 2.0-1