on xenial help sign in
Reduce code duplication and clean up CMakeLists and includes in indicator tests.
3f1caf5Michał Sawicz
CMakeLists.txt+2−10
@@ -108,11 +108,7 @@ declare_autopilot_test(shell unity8.shell ${CMAKE_SOURCE_DIR}/tests/autopilot/)
108
108
109set(SHELL_APP unity8)
109set(SHELL_APP unity8)
110
110
111−set(shell_app_HDRS
112− )
113−
114add_executable(${SHELL_APP}
111add_executable(${SHELL_APP}
115− ${shellapplication_MOC_SRCS}
116 ApplicationArguments.h
112 ApplicationArguments.h
117 main.cpp
113 main.cpp
118 MouseTouchAdaptor.cpp
114 MouseTouchAdaptor.cpp
@@ -123,14 +119,10 @@ pkg_check_modules(XCB REQUIRED xcb)
123
119
124if (NOT "${XCB_INCLUDE_DIRS}" STREQUAL "")
120if (NOT "${XCB_INCLUDE_DIRS}" STREQUAL "")
125 set_target_properties(${SHELL_APP} PROPERTIES INCLUDE_DIRECTORIES ${XCB_INCLUDE_DIRS})
121 set_target_properties(${SHELL_APP} PROPERTIES INCLUDE_DIRECTORIES ${XCB_INCLUDE_DIRS})
122+
123+ target_link_libraries(${SHELL_APP} ${XCB_LDFLAGS})
126endif()
124endif()
127
125
128−target_link_libraries(${SHELL_APP}
129− ${Qt5Qml_LIBRARIES}
130− ${Qt5Quick_LIBRARIES}
131− ${XCB_LDFLAGS}
132− ${CMAKE_DL_LIBS}
133− )
134
126
135# install binaries
127# install binaries
136install(TARGETS ${SHELL_APP}
128install(TARGETS ${SHELL_APP}
main.cpp−40
@@ -19,7 +19,6 @@
19
19
20// Qt
20// Qt
21#include <QtQuick/QQuickView>
21#include <QtQuick/QQuickView>
22−#include <QtGui/QIcon>
23#include <QtGui/QGuiApplication>
22#include <QtGui/QGuiApplication>
24#include <QtQml/QQmlEngine>
23#include <QtQml/QQmlEngine>
25#include <QtQml/QQmlContext>
24#include <QtQml/QQmlContext>
@@ -37,45 +36,6 @@
37
36
38#include <unity-mir/qmirserver.h>
37#include <unity-mir/qmirserver.h>
39
38
40−namespace {
41−
42−void prependImportPaths(QQmlEngine *engine, const QStringList &paths)
43−{
44− QStringList importPathList = engine->importPathList();
45− for (int i = paths.count() -1; i >= 0; i--) {
46− // don't duplicate
47− const QString& path = paths[i];
48− QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
49− if (iter == importPathList.end()) {
50− engine->addImportPath(path);
51− }
52− }
53−}
54−
55−/* When you append and import path to the list of import paths it will be the *last*
56− place where Qt will search for QML modules.
57− The usual QQmlEngine::addImportPath() actually prepends the given path.*/
58−void appendImportPaths(QQmlEngine *engine, const QStringList &paths)
59−{
60− QStringList importPathList = engine->importPathList();
61− Q_FOREACH(const QString& path, paths) {
62− // don't duplicate
63− QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
64− if (iter == importPathList.end()) {
65− importPathList.append(path);
66− }
67− }
68− engine->setImportPathList(importPathList);
69−}
70−
71−void resolveIconTheme() {
72− const char *ubuntuIconTheme = getenv("UBUNTU_ICON_THEME");
73− if (ubuntuIconTheme == NULL) {
74− ubuntuIconTheme = "ubuntu-mobile";
75− }
76− QIcon::setThemeName(ubuntuIconTheme);
77−}
78−} // namespace {
79
39
80int startShell(int argc, const char** argv, void* server)
40int startShell(int argc, const char** argv, void* server)
81{
41{
paths.h.in+39
@@ -23,6 +23,8 @@
23// Qt
23// Qt
24#include <QtCore/QCoreApplication>
24#include <QtCore/QCoreApplication>
25#include <QtCore/QDir>
25#include <QtCore/QDir>
26+#include <QtGui/QIcon>
27+#include <QtQml/QQmlEngine>
26#include <QStandardPaths>
28#include <QStandardPaths>
27
29
28inline bool isRunningInstalled() {
30inline bool isRunningInstalled() {
@@ -86,4 +88,41 @@ inline QString sourceDirectory() {
86 return QString("@CMAKE_SOURCE_DIR@/");
88 return QString("@CMAKE_SOURCE_DIR@/");
87}
89}
88
90
91+inline void prependImportPaths(QQmlEngine *engine, const QStringList &paths)
92+{
93+ QStringList importPathList = engine->importPathList();
94+ for (int i = paths.count() -1; i >= 0; i--) {
95+ // don't duplicate
96+ const QString& path = paths[i];
97+ QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
98+ if (iter == importPathList.end()) {
99+ engine->addImportPath(path);
100+ }
101+ }
102+}
103+
104+/* When you append and import path to the list of import paths it will be the *last*
105+ place where Qt will search for QML modules.
106+ The usual QQmlEngine::addImportPath() actually prepends the given path.*/
107+inline void appendImportPaths(QQmlEngine *engine, const QStringList &paths)
108+{
109+ QStringList importPathList = engine->importPathList();
110+ Q_FOREACH(const QString& path, paths) {
111+ // don't duplicate
112+ QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
113+ if (iter == importPathList.end()) {
114+ importPathList.append(path);
115+ }
116+ }
117+ engine->setImportPathList(importPathList);
118+}
119+
120+inline void resolveIconTheme() {
121+ const char *ubuntuIconTheme = getenv("UBUNTU_ICON_THEME");
122+ if (ubuntuIconTheme == NULL) {
123+ ubuntuIconTheme = "ubuntu-mobile";
124+ }
125+ QIcon::setThemeName(ubuntuIconTheme);
126+}
127+
89#endif
128#endif
src/Panel/Indicators/client/indicatorsclient.cpp−35
@@ -26,41 +26,6 @@
26#include <QQmlEngine>
26#include <QQmlEngine>
27#include <QDebug>
27#include <QDebug>
28
28
29−namespace {
30−
31−void prependImportPaths(QQmlEngine *engine, const QStringList &paths)
32−{
33− QStringList importPathList = engine->importPathList();
34− for (int i = paths.count()-1; i >= 0; i--) {
35− importPathList.prepend(paths[i]);
36− }
37− engine->setImportPathList(importPathList);
38−}
39−
40−/* When you append and import path to the list of import paths it will be the *last*
41− place where Qt will search for QML modules.
42− The usual QQmlEngine::addImportPath() actually prepends the given path.*/
43−void appendImportPaths(QQmlEngine *engine, const QStringList &paths)
44−{
45− QStringList importPathList = engine->importPathList();
46− Q_FOREACH(const QString& path, paths) {
47− // don't duplicate
48− QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
49− if (iter == importPathList.end()) {
50− importPathList.append(path);
51− }
52− }
53− engine->setImportPathList(importPathList);
54−}
55−
56−void resolveIconTheme() {
57− QString ubuntuIconTheme = getenv("UBUNTU_ICON_THEME");
58− if (ubuntuIconTheme.isEmpty()) {
59− QIcon::setThemeName("ubuntu-mobile");
60− }
61−}
62−} // namespace
63−
64IndicatorsClient::IndicatorsClient(int &argc, char **argv)
29IndicatorsClient::IndicatorsClient(int &argc, char **argv)
65 : QObject(0),
30 : QObject(0),
66 m_view(0)
31 m_view(0)
tests/plugins/Unity/Indicators/menucontentactivatortest.cpp−1
@@ -18,7 +18,6 @@
18 */
18 */
19
19
20#include "menucontentactivator.h"
20#include "menucontentactivator.h"
21−#include "paths.h"
22
21
23#include <QtTest>
22#include <QtTest>
24#include <QDebug>
23#include <QDebug>
tests/plugins/Unity/Indicators/unitymenumodelstacktest.cpp−1
@@ -18,7 +18,6 @@
18 */
18 */
19
19
20#include "indicatorsmanager.h"
20#include "indicatorsmanager.h"
21−#include "paths.h"
22#include "unitymenumodelstack.h"
21#include "unitymenumodelstack.h"
23
22
24#include <QtTest>
23#include <QtTest>