Improve Qt5 support

Make the source code compatible with Qt5.
This commit is contained in:
Alberto Mardegan 2014-10-22 22:26:43 -04:00
parent 9fb4199dac
commit 0a82b42f5a
3 changed files with 28 additions and 10 deletions

View file

@ -19,15 +19,18 @@
* http://www.gnu.org/licenses/.
*/
#if defined(Q_OS_SAILFISH)
#include <QtGlobal>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#include <QGuiApplication>
#include <sailfishapp.h>
#include <QQuickView>
#include <QQmlEngine>
#include <QQmlContext>
#ifdef QT_QML_DEBUG
#include <QtQuick>
#endif
#if defined(Q_OS_SAILFISH)
#include <sailfishapp.h>
#endif
#else
#include <QtGui/QApplication>
#include <QtDeclarative/QDeclarativeContext>
@ -44,8 +47,8 @@
#include "qmlutils.hh"
#include "mynetworkmanager.hh"
#if defined(Q_OS_SAILFISH)
#else
#if defined(Q_OS_HARMATTAN)
#define USE_THEME
#include "theme.hh"
#endif
@ -53,6 +56,8 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
{
#if defined(Q_OS_SAILFISH)
QGuiApplication *app = SailfishApp::application(argc, argv);
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QScopedPointer<QGuiApplication> app(new QGuiApplication(argc, argv));
#else
QScopedPointer<QApplication> app(createApplication(argc, argv));
#endif
@ -90,6 +95,9 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
#if defined(Q_OS_SAILFISH)
QQuickView* viewer = SailfishApp::createView();
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QScopedPointer<QQuickView> viewer(new QQuickView);
viewer->setResizeMode(QQuickView::SizeRootObjectToView);
#else
QmlApplicationViewer *viewer = new QmlApplicationViewer();
viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
@ -104,8 +112,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
viewer->rootContext()->setContextProperty("QMLUtils", QMLUtils::instance());
viewer->rootContext()->setContextProperty("settings", Settings::instance());
#if defined(Q_OS_SAILFISH)
#else
#ifdef USE_THEME
viewer->rootContext()->setContextProperty("MyTheme", Theme::instance());
#endif
@ -115,7 +122,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
viewer->setMainQmlFile(QLatin1String("qml/harmattan/main.qml"));
#endif
#if defined(Q_OS_SAILFISH)
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
viewer->show();
#else
viewer->showExpanded();

View file

@ -21,7 +21,11 @@
#include "mynetworkmanager.hh"
#include <QtNetwork/QNetworkDiskCache>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#include <QStandardPaths>
#else
#include <QDesktopServices>
#endif
#include <QDebug>
#include "settings.hh"
@ -45,7 +49,12 @@ QNetworkAccessManager* MyNetworkManager::create(QObject *parent) {
#if !defined(Q_OS_SAILFISH)
QNetworkDiskCache* diskCache = new QNetworkDiskCache(parent);
diskCache->setCacheDirectory(QDesktopServices::storageLocation(QDesktopServices::CacheLocation));
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QString cachePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
#else
QString cachePath = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
#endif
diskCache->setCacheDirectory(cachePath);
diskCache->setMaximumCacheSize(5*1024*1024); // 5Mo
nam->setCache(diskCache);
#endif
@ -90,6 +99,7 @@ void MyNetworkManager::onStarted() {
}
void MyNetworkManager::onReplyFinished(QNetworkReply *reply) {
Q_UNUSED(reply);
this->decNumRequests();
}

View file

@ -22,7 +22,8 @@
#ifndef MYNETWORKMANAGER_HH
#define MYNETWORKMANAGER_HH
#if defined(Q_OS_SAILFISH)
#include <QtGlobal>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#include <QQmlNetworkAccessManagerFactory>
#else
#include <qdeclarativenetworkaccessmanagerfactory.h>
@ -33,7 +34,7 @@
#include <QMutex>
#include <QDebug>
#if defined(Q_OS_SAILFISH)
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
class MyNetworkManager : public QObject, public QQmlNetworkAccessManagerFactory
#else
class MyNetworkManager : public QObject, public QDeclarativeNetworkAccessManagerFactory