on xenial help sign in
Reduce code duplication and clean up CMakeLists and includes in indicator tests.
commit3f1caf50bcb0fa63bc4ac9ed6c7ae53f9fa010ca authorMichał Sawicz <michal.sawicz@canonical.com> dateThu 12 Dec 2013, 13:25 (13 years ago) parent39186f6
6 files changed+41−87
CMakeLists.txt+2−10 main.cpp−40 paths.h.in+39 src/Panel/Indicators/client/indicatorsclient.cpp−35 tests/plugins/Unity/Indicators/menucontentactivatortest.cpp−1 tests/plugins/Unity/Indicators/unitymenumodelstacktest.cpp−1
CMakeLists.txt+2−10
@@ -108,11 +108,7 @@ declare_autopilot_test(shell unity8.shell ${CMAKE_SOURCE_DIR}/tests/autopilot/)
108108
109109set(SHELL_APP unity8)
110110
111−set(shell_app_HDRS
112− )
113−
114111add_executable(${SHELL_APP}
115− ${shellapplication_MOC_SRCS}
116112 ApplicationArguments.h
117113 main.cpp
118114 MouseTouchAdaptor.cpp
@@ -123,14 +119,10 @@ pkg_check_modules(XCB REQUIRED xcb)
123119
124120if (NOT "${XCB_INCLUDE_DIRS}" STREQUAL "")
125121 set_target_properties(${SHELL_APP} PROPERTIES INCLUDE_DIRECTORIES ${XCB_INCLUDE_DIRS})
122+
123+ target_link_libraries(${SHELL_APP} ${XCB_LDFLAGS})
126124endif()
127125
128−target_link_libraries(${SHELL_APP}
129− ${Qt5Qml_LIBRARIES}
130− ${Qt5Quick_LIBRARIES}
131− ${XCB_LDFLAGS}
132− ${CMAKE_DL_LIBS}
133− )
134126
135127# install binaries
136128install(TARGETS ${SHELL_APP}
main.cpp−40
@@ -19,7 +19,6 @@
1919
2020// Qt
2121#include <QtQuick/QQuickView>
22−#include <QtGui/QIcon>
2322#include <QtGui/QGuiApplication>
2423#include <QtQml/QQmlEngine>
2524#include <QtQml/QQmlContext>
@@ -37,45 +36,6 @@
3736
3837#include <unity-mir/qmirserver.h>
3938
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 {
7939
8040int startShell(int argc, const char** argv, void* server)
8141{
paths.h.in+39
@@ -23,6 +23,8 @@
2323// Qt
2424#include <QtCore/QCoreApplication>
2525#include <QtCore/QDir>
26+#include <QtGui/QIcon>
27+#include <QtQml/QQmlEngine>
2628#include <QStandardPaths>
2729
2830inline bool isRunningInstalled() {
@@ -86,4 +88,41 @@ inline QString sourceDirectory() {
8688 return QString("@CMAKE_SOURCE_DIR@/");
8789}
8890
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+
89128#endif
src/Panel/Indicators/client/indicatorsclient.cpp−35
@@ -26,41 +26,6 @@
2626#include <QQmlEngine>
2727#include <QDebug>
2828
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−
6429IndicatorsClient::IndicatorsClient(int &argc, char **argv)
6530 : QObject(0),
6631 m_view(0)
tests/plugins/Unity/Indicators/menucontentactivatortest.cpp−1
@@ -18,7 +18,6 @@
1818 */
1919
2020#include "menucontentactivator.h"
21−#include "paths.h"
2221
2322#include <QtTest>
2423#include <QDebug>
tests/plugins/Unity/Indicators/unitymenumodelstacktest.cpp−1
@@ -18,7 +18,6 @@
1818 */
1919
2020#include "indicatorsmanager.h"
21−#include "paths.h"
2221#include "unitymenumodelstack.h"
2322
2423#include <QtTest>