on xenial help sign in
Merge lp:~saviq/unity8/cache-network-data
commit82f700e325b755d4e943d88d4e3e86751086ef4f authorMichal Hruby <michal.mhr@gmail.com> dateMon 30 Jun 2014, 13:46 (12 years ago) parent9ecb67c6f8457e
4 files changed+77−2
src/CMakeLists.txt+1 src/CachingNetworkManagerFactory.cpp+34 src/CachingNetworkManagerFactory.h+37 src/main.cpp+5−2
src/CMakeLists.txt+1
@@ -19,6 +19,7 @@ add_executable(${SHELL_APP}
1919 ApplicationArguments.h
2020 main.cpp
2121 MouseTouchAdaptor.cpp
22+ CachingNetworkManagerFactory.cpp
2223 ${QML_FILES} # This is to make qml and image files appear in the IDE's project tree
2324)
2425
src/CachingNetworkManagerFactory.cppnew file+34
@@ -0,0 +1,34 @@
1+/*
2+ * Copyright (C) 2014 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+
18+#include "CachingNetworkManagerFactory.h"
19+
20+#include <QNetworkDiskCache>
21+#include <QNetworkAccessManager>
22+#include <QStandardPaths>
23+
24+CachingNetworkManagerFactory::CachingNetworkManagerFactory()
25+ : m_cache(new QNetworkDiskCache())
26+{
27+ m_cache->setCacheDirectory(QString("%1/network").arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)));
28+}
29+
30+QNetworkAccessManager *CachingNetworkManagerFactory::create(QObject *parent) {
31+ QNetworkAccessManager *manager = new QNetworkAccessManager(parent);
32+ manager->setCache(m_cache);
33+ return manager;
34+}
src/CachingNetworkManagerFactory.hnew file+37
@@ -0,0 +1,37 @@
1+/*
2+ * Copyright (C) 2014 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+
18+#ifndef CACHINGNETWORKMANAGERFACTORY_H
19+#define CACHINGNETWORKMANAGERFACTORY_H
20+
21+#include <QQmlNetworkAccessManagerFactory>
22+
23+class QNetworkDiskCache;
24+class QNetworkAccessManager;
25+
26+class CachingNetworkManagerFactory : public QQmlNetworkAccessManagerFactory
27+{
28+public:
29+ CachingNetworkManagerFactory();
30+
31+ QNetworkAccessManager *create(QObject *parent) override;
32+
33+private:
34+ QNetworkDiskCache *m_cache;
35+};
36+
37+#endif // CACHINGNETWORKMANAGERFACTORY_H
src/main.cpp+5−2
@@ -34,15 +34,15 @@
3434#include <paths.h>
3535#include "MouseTouchAdaptor.h"
3636#include "ApplicationArguments.h"
37+#include "CachingNetworkManagerFactory.h"
3738
3839#include <unity-mir/qmirserver.h>
3940
40−
4141int startShell(int argc, const char** argv, void* server)
4242{
4343 const bool isUbuntuMirServer = qgetenv("QT_QPA_PLATFORM") == "ubuntumirserver";
4444
45− QGuiApplication::setApplicationName("Unity 8");
45+ QGuiApplication::setApplicationName("unity8");
4646 QGuiApplication *application;
4747
4848 QCommandLineParser parser;
@@ -159,6 +159,9 @@ Load the testability driver");
159159 }
160160 appendImportPaths(view->engine(), ::fallbackImportPaths());
161161
162+ CachingNetworkManagerFactory *managerFactory = new CachingNetworkManagerFactory();
163+ view->engine()->setNetworkAccessManagerFactory(managerFactory);
164+
162165 view->setSource(source);
163166 view->setColor("transparent");
164167 QObject::connect(view->engine(), SIGNAL(quit()), application, SLOT(quit()));