blob: 8022b36f173051a55b1a37e2a9e24338e2c784c2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-2.1-or-later OR GPL-3.0-or-later
#include "workspace.h"
#include "dockmanager.h"
namespace ADS {
Workspace::Workspace() {}
Workspace::Workspace(const Utils::FilePath &filePath, bool isPreset)
: m_filePath(filePath)
, m_preset(isPreset)
{
if (m_filePath.isEmpty())
return;
QString name = DockManager::readDisplayName(m_filePath);
if (name.isEmpty()) {
name = baseName();
// Remove "-" and "_" remove
name.replace("-", " ");
name.replace("_", " ");
setName(name);
} else {
m_name = name;
}
QString mcusEnabled = DockManager::readMcusEnabled(m_filePath);
if (mcusEnabled.isEmpty())
setMcusEnabled(true);
else
m_mcusEnabled = QVariant::fromValue(mcusEnabled).toBool();
}
void Workspace::setName(const QString &name)
{
if (DockManager::writeDisplayName(filePath(), name))
m_name = name;
}
const QString &Workspace::name() const
{
return m_name;
}
const Utils::FilePath &Workspace::filePath() const
{
return m_filePath;
}
QString Workspace::fileName() const
{
return m_filePath.fileName();
}
QString Workspace::baseName() const
{
return m_filePath.baseName();
}
QDateTime Workspace::lastModified() const
{
return m_filePath.lastModified();
}
bool Workspace::exists() const
{
return m_filePath.exists();
}
bool Workspace::isValid() const
{
if (m_filePath.isEmpty())
return false;
return exists();
}
void Workspace::setPreset(bool value)
{
m_preset = value;
}
bool Workspace::isPreset() const
{
return m_preset;
}
void Workspace::setMcusEnabled(bool enabled)
{
QString mcusEnabled = QVariant::fromValue(enabled).toString();
if (DockManager::writeMcusEnabled(filePath(), mcusEnabled))
m_mcusEnabled = enabled;
}
bool Workspace::isMcusEnabled() const
{
return m_mcusEnabled;
}
Workspace::operator QString() const
{
return QString("Workspace %1 Preset[%2] %3")
.arg(name())
.arg(isPreset())
.arg(filePath().toUserOutput());
}
} // namespace ADS
|