From 02d86ffa67af165e498879f03286fc7540576fb1 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Mon, 4 Dec 2017 01:37:33 +0300 Subject: [PATCH] [app] Use HarbourPluginLoader from HarbourLib --- app/app.pro | 2 - app/src/BooksMediaPlugin.cpp | 2 +- app/src/BooksMediaPlugin.h | 4 +- app/src/BooksPluginLoader.cpp | 218 ---------------------------------- app/src/BooksPluginLoader.h | 67 ----------- app/src/BooksPolicyPlugin.cpp | 2 +- app/src/BooksPolicyPlugin.h | 4 +- harbour-lib | 2 +- 8 files changed, 7 insertions(+), 294 deletions(-) delete mode 100644 app/src/BooksPluginLoader.cpp delete mode 100644 app/src/BooksPluginLoader.h diff --git a/app/app.pro b/app/app.pro index d57f158..a6343ca 100644 --- a/app/app.pro +++ b/app/app.pro @@ -115,7 +115,6 @@ SOURCES += \ src/BooksPageWidget.cpp \ src/BooksPaintContext.cpp \ src/BooksPathModel.cpp \ - src/BooksPluginLoader.cpp \ src/BooksPolicyPlugin.cpp \ src/BooksSaveTimer.cpp \ src/BooksSettings.cpp \ @@ -161,7 +160,6 @@ HEADERS += \ src/BooksPageWidget.h \ src/BooksPaintContext.h \ src/BooksPathModel.h \ - src/BooksPluginLoader.h \ src/BooksPolicyPlugin.h \ src/BooksPos.h \ src/BooksSaveTimer.h \ diff --git a/app/src/BooksMediaPlugin.cpp b/app/src/BooksMediaPlugin.cpp index 1a48bcb..26a4ff6 100644 --- a/app/src/BooksMediaPlugin.cpp +++ b/app/src/BooksMediaPlugin.cpp @@ -42,7 +42,7 @@ const char BooksMediaPlugin::MEDIAKEY_QML_TYPE[] = "MediaKey"; BooksMediaPlugin::BooksMediaPlugin( QQmlEngine* aEngine) : - BooksPluginLoader(aEngine, "Sailfish.Media", 1, 0) + HarbourPluginLoader(aEngine, "Sailfish.Media", 1, 0) { } diff --git a/app/src/BooksMediaPlugin.h b/app/src/BooksMediaPlugin.h index 8ee3e25..3847fdd 100644 --- a/app/src/BooksMediaPlugin.h +++ b/app/src/BooksMediaPlugin.h @@ -34,9 +34,9 @@ #ifndef BOOKS_MEDIA_PLUGIN_H #define BOOKS_MEDIA_PLUGIN_H -#include "BooksPluginLoader.h" +#include "HarbourPluginLoader.h" -class BooksMediaPlugin : public BooksPluginLoader +class BooksMediaPlugin : public HarbourPluginLoader { static BooksMediaPlugin* gInstance; static const char MEDIAKEY_QML_TYPE[]; diff --git a/app/src/BooksPluginLoader.cpp b/app/src/BooksPluginLoader.cpp deleted file mode 100644 index 3419181..0000000 --- a/app/src/BooksPluginLoader.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (C) 2017 Jolla Ltd. - * Contact: Slava Monich - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Jolla Ltd nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "BooksPluginLoader.h" - -#include "HarbourDebug.h" - -#include -#include -#include - -#include -#include -#include -#include - -// This hack allows to use prohibited QML imports by re-registering -// then under harbour.books - -// PRIVATE QT API! -class Q_QML_EXPORT QQmlType -{ -public: - int typeId() const; - int qListTypeId() const; - typedef void (*CreateFunc)(void *); - CreateFunc createFunction() const; - int createSize() const; - const QMetaObject *metaObject() const; - int parserStatusCast() const; - int propertyValueSourceCast() const; - int propertyValueInterceptorCast() const; -}; - -// PRIVATE QT API! -class Q_QML_EXPORT QQmlMetaType -{ -public: - static QQmlType* qmlType(const QString &qualifiedName, int, int); -}; - -BooksPluginLoader::BooksPluginLoader( - QQmlEngine* aEngine, - QString aModule, - int aMajor, - int aMinor) : - iTypesRegistered(false), - iPlugin(pluginLoader(aEngine, aModule)), - iModule(aModule), - iMajor(aMajor), - iMinor(aMinor) -{} - -BooksPluginLoader::~BooksPluginLoader() -{ - delete iPlugin; -} - -QPluginLoader* -BooksPluginLoader::pluginLoader( - QQmlEngine* aEngine, - QString aModule) -{ - QStringList pathList = aEngine->importPathList(); - aModule.replace('.', '/'); - const int n = pathList.count(); - for (int i=0; iload()) { - HDEBUG("loaded" << qPrintable(loader->fileName())); - return loader; - } else { - HWARN("Failed to load" << qPrintable(loader->fileName())); - delete loader; - } - } - } - return NULL; -} - -QPluginLoader* -BooksPluginLoader::pluginLoader( - QString aPluginDir) -{ - QString qmldir(QString(aPluginDir).append('/').append("qmldir")); - QFile f(qmldir); - if (f.open(QIODevice::ReadOnly)) { - QTextStream in(&f); - while (!in.atEnd()) { - static const QString plugin("plugin"); - QString line = in.readLine(); - if (line.indexOf(plugin) >= 0) { - QStringList parts = line.split(' ', QString::SkipEmptyParts); - if (parts.count() == 2 && parts.at(0) == plugin) { - QString path(QString(aPluginDir).append("/lib"). - append(parts.at(1)).append(".so")); - if (QFile::exists(path)) { - return new QPluginLoader(path); - } - } - } - } - } - return NULL; -} - -QQmlType* -BooksPluginLoader::qmlType( - QString aName) -{ - if (iPlugin) { - if (!iTypesRegistered) { - iTypesRegistered = true; - QObject* root = iPlugin->instance(); - if (root) { - QQmlTypesExtensionInterface* ext = - qobject_cast(root); - if (ext) { - QByteArray str = iModule.toLocal8Bit(); - ext->registerTypes(str.constData()); - } - } else { - HWARN("Could not load" << qPrintable(iPlugin->fileName())); - } - } - QString fullName(iModule + '/' + aName); - QQmlType* type = QQmlMetaType::qmlType(fullName, iMajor, iMinor); - if (!type) { - HWARN("Failed to load" << fullName); - } - return type; - } - return NULL; -} - -void -BooksPluginLoader::reRegisterType( - const char* aQmlName, - const char* aModule, - int aMajor, - int aMinor) -{ - // Re-register with the same type name (in different module) - reRegisterType(qmlType(aQmlName), aQmlName, aModule, aMajor, aMinor); -} - -// Re-registers the existing QML type under a different name/module -void -BooksPluginLoader::reRegisterType( - QQmlType* aType, - const char* aQmlName, - const char* aModule, - int aMajor, - int aMinor) -{ - if (aType) { - QQmlPrivate::RegisterType type = { - 0, // int version; - aType->typeId(), // int typeId; - aType->qListTypeId(), // int listId; - aType->createSize(), // int objectSize; - aType->createFunction(), // void (*create)(void *); - QString(), // QString noCreationReason; - aModule, // const char *uri; - aMajor, // int versionMajor; - aMinor, // int versionMinor; - aQmlName, // const char *elementName; - aType->metaObject(), // const QMetaObject *metaObject; -#if 0 // We don't need those, it seems - aType->attachedPropertiesFunction(), - aType->attachedPropertiesType(), -#else - Q_NULLPTR, // QQmlAttachedPropertiesFunc attachedPropertiesFunction; - Q_NULLPTR, // const QMetaObject *attachedPropertiesMetaObject; -#endif - aType->parserStatusCast(), // int parserStatusCast; - aType->propertyValueSourceCast(), // int valueSourceCast; - aType->propertyValueInterceptorCast(), // int valueInterceptorCast; - Q_NULLPTR, // QObject *(*extensionObjectCreate)(QObject *); - Q_NULLPTR, // const QMetaObject *extensionMetaObject; - Q_NULLPTR, // QQmlCustomParser *customParser; - 0 // int revision; - }; - QQmlPrivate::qmlregister(QQmlPrivate::TypeRegistration, &type); - } -} diff --git a/app/src/BooksPluginLoader.h b/app/src/BooksPluginLoader.h deleted file mode 100644 index 4c9528e..0000000 --- a/app/src/BooksPluginLoader.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2017 Jolla Ltd. - * Contact: Slava Monich - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Jolla Ltd nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef BOOKS_PLUGIN_LOADER_H -#define BOOKS_PLUGIN_LOADER_H - -#include - -class QQmlType; -class QQmlEngine; -class QPluginLoader; - -class BooksPluginLoader -{ -protected: - BooksPluginLoader(QQmlEngine* aEngine, QString aModule, int aMajor, int aMinor); - ~BooksPluginLoader(); - - QQmlType* qmlType(QString aName); - - void reRegisterType(QQmlType* aType, const char* aQmlName, - const char* aModule, int aMajor, int aMinor); - void reRegisterType(const char* aQmlName, - const char* aModule, int aMajor, int aMinor); - - static QPluginLoader* pluginLoader(QQmlEngine* aEngine, QString aModule); - static QPluginLoader* pluginLoader(QString aPluginDir); - -private: - bool iTypesRegistered; - QPluginLoader* iPlugin; - QString iModule; - int iMajor; - int iMinor; -}; - -#endif // BOOKS_PLUGIN_LOADER_H diff --git a/app/src/BooksPolicyPlugin.cpp b/app/src/BooksPolicyPlugin.cpp index 056fa05..ae168e6 100644 --- a/app/src/BooksPolicyPlugin.cpp +++ b/app/src/BooksPolicyPlugin.cpp @@ -43,7 +43,7 @@ const char BooksPolicyPlugin::PERMISSIONS_QML_TYPE[] = "Permissions"; BooksPolicyPlugin::BooksPolicyPlugin( QQmlEngine* aEngine) : - BooksPluginLoader(aEngine, "org.nemomobile.policy", 1, 0) + HarbourPluginLoader(aEngine, "org.nemomobile.policy", 1, 0) { } diff --git a/app/src/BooksPolicyPlugin.h b/app/src/BooksPolicyPlugin.h index a04bbee..ae4c0fd 100644 --- a/app/src/BooksPolicyPlugin.h +++ b/app/src/BooksPolicyPlugin.h @@ -34,11 +34,11 @@ #ifndef BOOKS_POLICY_PLUGIN_H #define BOOKS_POLICY_PLUGIN_H -#include "BooksPluginLoader.h" +#include "HarbourPluginLoader.h" class QQmlEngine; -class BooksPolicyPlugin : public BooksPluginLoader +class BooksPolicyPlugin : public HarbourPluginLoader { static BooksPolicyPlugin* gInstance; static const char RESOURCE_QML_TYPE[]; diff --git a/harbour-lib b/harbour-lib index 0624025..9f91b79 160000 --- a/harbour-lib +++ b/harbour-lib @@ -1 +1 @@ -Subproject commit 06240258bb0f0175215f1cf000298ccb90d228d7 +Subproject commit 9f91b79f34f75ca099c09819dc57d099b909c705