Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2025 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 "networkconfiguration.h"
23 :
24 : #include "global/configreader.h"
25 :
26 : using namespace muse;
27 : using namespace muse::network;
28 :
29 0 : void NetworkConfiguration::init()
30 : {
31 0 : m_userAgentConfig = ConfigReader::read(":/configs/user_agent.cfg");
32 0 : }
33 :
34 0 : RequestHeaders NetworkConfiguration::defaultHeaders(const std::string& userAgentName) const
35 : {
36 0 : RequestHeaders headers;
37 :
38 0 : headers.knownHeaders[QNetworkRequest::UserAgentHeader] = makeUserAgent(userAgentName);
39 :
40 0 : return headers;
41 0 : }
42 :
43 0 : bool NetworkConfiguration::isOffline() const
44 : {
45 0 : return m_offline;
46 : }
47 :
48 0 : void NetworkConfiguration::setOffline(bool offline)
49 : {
50 0 : m_offline = offline;
51 0 : }
52 :
53 0 : QString NetworkConfiguration::makeUserAgent(const std::string& tplName) const
54 : {
55 0 : std::string _tplName = tplName;
56 0 : if (_tplName.empty()) {
57 0 : static const std::string GLOBAL_USER_AGENT = "general";
58 0 : _tplName = GLOBAL_USER_AGENT;
59 : }
60 :
61 0 : QString osName;
62 : #if defined(Q_OS_WIN)
63 : osName = "Windows";
64 : #elif defined (Q_OS_MACOS)
65 : osName = "Mac";
66 : #else
67 0 : osName = "Linux";
68 : #endif
69 :
70 0 : const static QString kernelType = QSysInfo::kernelType();
71 0 : const static QString kernelVersion = QSysInfo::kernelVersion();
72 0 : const static QString osVersion = QSysInfo::productVersion();
73 0 : const static QString cpuArchitecture = QSysInfo::currentCpuArchitecture();
74 :
75 0 : QString result = m_userAgentConfig.value(_tplName).toQString();
76 0 : result = result.replace("{app_version}", application()->version().toString());
77 0 : result = result.replace("{app_build}", application()->build());
78 :
79 0 : result = result.replace("{kernel_type}", kernelType);
80 0 : result = result.replace("{kernel_version}", kernelVersion);
81 0 : result = result.replace("{os_name}", osName);
82 0 : result = result.replace("{os_version}", osVersion);
83 0 : result = result.replace("{cpu_arch}", cpuArchitecture);
84 :
85 0 : return result;
86 0 : }
|