Merge lp:~saviq/unity8/cache-network-data into lp:unity8

Proposed by Michał Sawicz
Status: Superseded
Proposed branch: lp:~saviq/unity8/cache-network-data
Merge into: lp:unity8
Diff against target: 123 lines (+77/-2)
4 files modified
src/CMakeLists.txt (+1/-0)
src/CachingNetworkManagerFactory.cpp (+34/-0)
src/CachingNetworkManagerFactory.h (+37/-0)
src/main.cpp (+5/-2)
To merge this branch: bzr merge lp:~saviq/unity8/cache-network-data
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Florian Boucault Pending
Review via email: mp+221079@code.launchpad.net

Commit message

Implement a caching network access manager to cache images.

Description of the change

It's the first step to improving our network usage and dash icon loading speed.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~saviq/unity8/cache-network-data updated
919. By Michał Sawicz

Merge trunk.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2014-03-07 18:36:53 +0000
3+++ src/CMakeLists.txt 2014-06-04 11:13:15 +0000
4@@ -19,6 +19,7 @@
5 ApplicationArguments.h
6 main.cpp
7 MouseTouchAdaptor.cpp
8+ CachingNetworkManagerFactory.cpp
9 ${QML_FILES} # This is to make qml and image files appear in the IDE's project tree
10 )
11 add_executable(${SHELL_APP} ${COMMON_SRCS})
12
13=== added file 'src/CachingNetworkManagerFactory.cpp'
14--- src/CachingNetworkManagerFactory.cpp 1970-01-01 00:00:00 +0000
15+++ src/CachingNetworkManagerFactory.cpp 2014-06-04 11:13:15 +0000
16@@ -0,0 +1,34 @@
17+/*
18+ * Copyright (C) 2014 Canonical, Ltd.
19+ *
20+ * This program is free software; you can redistribute it and/or modify
21+ * it under the terms of the GNU General Public License as published by
22+ * the Free Software Foundation; version 3.
23+ *
24+ * This program is distributed in the hope that it will be useful,
25+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
26+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+ * GNU General Public License for more details.
28+ *
29+ * You should have received a copy of the GNU General Public License
30+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
31+ *
32+ */
33+
34+#include "CachingNetworkManagerFactory.h"
35+
36+#include <QNetworkDiskCache>
37+#include <QNetworkAccessManager>
38+#include <QStandardPaths>
39+
40+CachingNetworkManagerFactory::CachingNetworkManagerFactory()
41+ : m_cache(new QNetworkDiskCache())
42+{
43+ m_cache->setCacheDirectory(QString("%1/network").arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)));
44+}
45+
46+QNetworkAccessManager *CachingNetworkManagerFactory::create(QObject *parent) {
47+ QNetworkAccessManager *manager = new QNetworkAccessManager(parent);
48+ manager->setCache(m_cache);
49+ return manager;
50+}
51
52=== added file 'src/CachingNetworkManagerFactory.h'
53--- src/CachingNetworkManagerFactory.h 1970-01-01 00:00:00 +0000
54+++ src/CachingNetworkManagerFactory.h 2014-06-04 11:13:15 +0000
55@@ -0,0 +1,37 @@
56+/*
57+ * Copyright (C) 2014 Canonical, Ltd.
58+ *
59+ * This program is free software; you can redistribute it and/or modify
60+ * it under the terms of the GNU General Public License as published by
61+ * the Free Software Foundation; version 3.
62+ *
63+ * This program is distributed in the hope that it will be useful,
64+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
65+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66+ * GNU General Public License for more details.
67+ *
68+ * You should have received a copy of the GNU General Public License
69+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
70+ *
71+ */
72+
73+#ifndef CACHINGNETWORKMANAGERFACTORY_H
74+#define CACHINGNETWORKMANAGERFACTORY_H
75+
76+#include <QQmlNetworkAccessManagerFactory>
77+
78+class QNetworkDiskCache;
79+class QNetworkAccessManager;
80+
81+class CachingNetworkManagerFactory : public QQmlNetworkAccessManagerFactory
82+{
83+public:
84+ CachingNetworkManagerFactory();
85+
86+ QNetworkAccessManager *create(QObject *parent) override;
87+
88+private:
89+ QNetworkDiskCache *m_cache;
90+};
91+
92+#endif // CACHINGNETWORKMANAGERFACTORY_H
93
94=== modified file 'src/main.cpp'
95--- src/main.cpp 2014-05-20 03:01:51 +0000
96+++ src/main.cpp 2014-06-04 11:13:15 +0000
97@@ -35,15 +35,15 @@
98 #include <paths.h>
99 #include "MouseTouchAdaptor.h"
100 #include "ApplicationArguments.h"
101+#include "CachingNetworkManagerFactory.h"
102
103 #include <unity-mir/qmirserver.h>
104
105-
106 int startShell(int argc, const char** argv, void* server)
107 {
108 const bool isUbuntuMirServer = qgetenv("QT_QPA_PLATFORM") == "ubuntumirserver";
109
110- QGuiApplication::setApplicationName(UNITY8_GREETER ? "Unity 8 Greeter" : "Unity 8");
111+ QGuiApplication::setApplicationName(UNITY8_GREETER ? "unity8-greeter" : "unity8");
112 QGuiApplication *application;
113
114 QCommandLineParser parser;
115@@ -160,6 +160,9 @@
116 }
117 appendImportPaths(view->engine(), ::fallbackImportPaths());
118
119+ CachingNetworkManagerFactory *managerFactory = new CachingNetworkManagerFactory();
120+ view->engine()->setNetworkAccessManagerFactory(managerFactory);
121+
122 view->setSource(source);
123 view->setColor(Qt::transparent);
124

Subscribers

People subscribed via source and target branches