@@ -0,0 +1,80 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "Workspace.h"
18+#include "WorkspaceModel.h"
19+#include "WorkspaceManager.h"
20+#include "TopLevelWindowModel.h"
21+
22+#include "windowmanagementpolicy.h"
23+
24+Workspace::Workspace(QObject *parent)
25+ : QObject(parent)
26+ , m_model(nullptr)
27+ , m_windowModel(new TopLevelWindowModel)
28+ , m_active(false)
29+{
30+ connect(WorkspaceManager::instance(), &WorkspaceManager::activeWorkspaceChanged, this, [this]() {
31+ bool newActive = WorkspaceManager::instance()->activeWorkspace() == this;
32+ if (newActive != m_active) {
33+ m_active = newActive;
34+ Q_EMIT activeChanged(m_active);
35+ }
36+ });
37+ connect(this, &Workspace::activeChanged, m_windowModel.data(), &TopLevelWindowModel::setActive);
38+}
39+
40+Workspace::~Workspace()
41+{
42+ unassign();
43+}
44+
45+void Workspace::assign(WorkspaceModel *model)
46+{
47+ if (m_model == model) return;
48+
49+ if (m_model) {
50+ disconnect(model);
51+ m_model->remove(this);
52+ }
53+
54+ m_model = model ? model : WorkspaceManager::instance();
55+
56+ if (m_model) {
57+ m_model->append(this);
58+
59+ connect(m_model, &QObject::destroyed, this, [this]() {
60+ m_model->remove(this);
61+ m_model = nullptr;
62+ });
63+ Q_EMIT assigned();
64+ }
65+}
66+
67+void Workspace::activate()
68+{
69+ WorkspaceManager::instance()->setActiveWorkspace(this);
70+}
71+
72+void Workspace::unassign()
73+{
74+ assign(nullptr);
75+}
76+
77+TopLevelWindowModel *Workspace::windowModel() const
78+{
79+ return m_windowModel.data();
80+}