on xenial help sign in
mock Unity.Screens
commitfe035f23854576f2430dfaf51adac0f042700088 authorMichael Zanetti <michael.zanetti@canonical.com> dateWed 2 Dec 2015, 14:23 (11 years ago) parent4d27450
7 files changed+241
tests/mocks/Unity/CMakeLists.txt+1 tests/mocks/Unity/Screens/CMakeLists.txt+14 tests/mocks/Unity/Screens/plugin.cpp+29 tests/mocks/Unity/Screens/plugin.h+25 tests/mocks/Unity/Screens/qmldir+2 tests/mocks/Unity/Screens/screens.cpp+92 tests/mocks/Unity/Screens/screens.h+78
tests/mocks/Unity/CMakeLists.txt+1
@@ -5,6 +5,7 @@ add_subdirectory(InputInfo)
55add_subdirectory(Launcher)
66add_subdirectory(Notifications)
77add_subdirectory(DashCommunicator)
8+add_subdirectory(Screens)
89
910pkg_search_module(GOBJECT gobject-2.0 REQUIRED)
1011pkg_check_modules(SCOPES_API REQUIRED unity-shell-scopes=8)
tests/mocks/Unity/Screens/CMakeLists.txtnew file+14
@@ -0,0 +1,14 @@
1+include_directories(
2+ ${CMAKE_CURRENT_SOURCE_DIR}
3+)
4+
5+set(MockScreens_SOURCES
6+ plugin.cpp
7+ screens.cpp
8+)
9+
10+add_library(MockScreensPlugin MODULE ${MockScreens_SOURCES})
11+
12+qt5_use_modules(MockScreensPlugin Gui Qml)
13+
14+add_unity8_mock(Unity.Screens 0.1 Unity/Screens TARGETS MockScreensPlugin)
tests/mocks/Unity/Screens/plugin.cppnew file+29
@@ -0,0 +1,29 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "plugin.h"
18+#include "screens.h"
19+
20+#include <QScreen>
21+
22+void UnityScreensPlugin::registerTypes(const char* uri)
23+{
24+ Q_ASSERT(QLatin1String(uri) == QLatin1String("Unity.Screens"));
25+
26+ qRegisterMetaType<QScreen*>("QScreen*");
27+
28+ qmlRegisterType<Screens>(uri, 0, 1, "Screens");
29+}
tests/mocks/Unity/Screens/plugin.hnew file+25
@@ -0,0 +1,25 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include <QQmlExtensionPlugin>
18+#include <QtQml/qqml.h>
19+
20+class UnityScreensPlugin : public QQmlExtensionPlugin {
21+ Q_OBJECT
22+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0")
23+public:
24+ virtual void registerTypes(const char* uri);
25+};
tests/mocks/Unity/Screens/qmldirnew file+2
@@ -0,0 +1,2 @@
1+module Unity.Screens
2+plugin MockScreensPlugin
tests/mocks/Unity/Screens/screens.cppnew file+92
@@ -0,0 +1,92 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "screens.h"
18+
19+// Qt
20+#include <QGuiApplication>
21+#include <QScreen>
22+
23+Q_DECLARE_METATYPE(QScreen*)
24+
25+Screens::Screens(QObject *parent) :
26+ QAbstractListModel(parent)
27+{
28+}
29+
30+Screens::~Screens()
31+{
32+ qDeleteAll(m_screenList);
33+}
34+
35+QHash<int, QByteArray> Screens::roleNames() const
36+{
37+ QHash<int, QByteArray> roles;
38+ roles[ScreenRole] = "screen";
39+ roles[OutputTypeRole] = "outputType";
40+ return roles;
41+}
42+
43+QVariant Screens::data(const QModelIndex &index, int role) const
44+{
45+ if (!index.isValid() || index.row() >= m_screenList.size()) {
46+ return QVariant();
47+ }
48+
49+ switch(role) {
50+ case ScreenRole:
51+ return QVariant::fromValue(m_screenList.at(index.row()));
52+ case OutputTypeRole:
53+ return OutputTypes::Unknown;
54+ }
55+
56+ return QVariant();
57+}
58+
59+int Screens::rowCount(const QModelIndex &) const
60+{
61+ return count();
62+}
63+
64+int Screens::count() const
65+{
66+ return m_screenList.size();
67+}
68+
69+void Screens::onScreenAdded(QScreen *screen)
70+{
71+ if (m_screenList.contains(screen))
72+ return;
73+
74+ beginInsertRows(QModelIndex(), count(), count());
75+ m_screenList.push_back(screen);
76+ endInsertRows();
77+ Q_EMIT screenAdded(screen);
78+ Q_EMIT countChanged();
79+}
80+
81+void Screens::onScreenRemoved(QScreen *screen)
82+{
83+ int index = m_screenList.indexOf(screen);
84+ if (index < 0)
85+ return;
86+
87+ beginRemoveRows(QModelIndex(), index, index);
88+ m_screenList.removeAt(index);
89+ endRemoveRows();
90+ Q_EMIT screenRemoved(screen);
91+ Q_EMIT countChanged();
92+}
tests/mocks/Unity/Screens/screens.hnew file+78
@@ -0,0 +1,78 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef SCREENS_H
18+#define SCREENS_H
19+
20+#include <QAbstractListModel>
21+
22+class QScreen;
23+
24+class Screens : public QAbstractListModel
25+{
26+ Q_OBJECT
27+ Q_ENUMS(OutputTypes)
28+
29+ Q_PROPERTY(int count READ count NOTIFY countChanged)
30+
31+public:
32+ enum ItemRoles {
33+ ScreenRole = Qt::UserRole + 1,
34+ OutputTypeRole
35+ };
36+
37+ enum OutputTypes {
38+ Unknown,
39+ VGA,
40+ DVII,
41+ DVID,
42+ DVIA,
43+ Composite,
44+ SVideo,
45+ LVDS,
46+ Component,
47+ NinePinDIN,
48+ DisplayPort,
49+ HDMIA,
50+ HDMIB,
51+ TV,
52+ EDP
53+ };
54+
55+ explicit Screens(QObject *parent = 0);
56+ virtual ~Screens() noexcept;
57+
58+ /* QAbstractItemModel */
59+ QHash<int, QByteArray> roleNames() const override;
60+ QVariant data(const QModelIndex &index, int role = ScreenRole) const override;
61+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
62+
63+ int count() const;
64+
65+Q_SIGNALS:
66+ void countChanged();
67+ void screenAdded(QScreen *screen);
68+ void screenRemoved(QScreen *screen);
69+
70+private Q_SLOTS:
71+ void onScreenAdded(QScreen *screen);
72+ void onScreenRemoved(QScreen *screen);
73+
74+private:
75+ QList<QScreen *> m_screenList;
76+};
77+
78+#endif // SCREENS_H