Commit 5f00b16f authored by Tim Jenssen's avatar Tim Jenssen

QmlDesigner: removed not used PluginManager

Change-Id: I549d2ec768fffb49922e8deab1a5e1a7f97e3c56
Reviewed-by: default avatarAlessandro Portale <alessandro.portale@theqtcompany.com>
parent 2845d758
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "iplugin.h"
// Put docs in here
namespace QmlDesigner {
} // namespace QmlDesigner
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <QObject>
#define QMLDESIGNER_PLUGIN_INTERFACE "com.Digia.QmlDesigner.IPlugin.v10"
namespace QmlDesigner {
// QmlDesigner "base" plugin with initialization function in which
// it can retriece the core via its static accessor and do magic.
class IPlugin
{
public:
virtual ~IPlugin() {}
virtual bool isInitialized() const = 0;
virtual bool initialize(QString *errorMessage) = 0;
};
} // namespace QmlDesigner
QT_BEGIN_NAMESPACE
Q_DECLARE_INTERFACE(QmlDesigner::IPlugin, QMLDESIGNER_PLUGIN_INTERFACE)
QT_END_NAMESPACE
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "pluginmanager.h"
#include "iplugin.h"
#include <metainfo.h>
#include <QCoreApplication>
#include <QObject>
#include <QDir>
#include <QStringList>
#include <QDebug>
#include <QStandardItemModel>
#include <QTreeView>
#include <QVBoxLayout>
#include <QDialog>
#include <QDialogButtonBox>
enum { debug = 0 };
namespace QmlDesigner {
PluginManager::IPluginList PluginManager::instances()
{
IPluginList rc;
const auto end = m_paths.end();
for (auto it = m_paths.begin(); it != end; ++it)
it->getInstances(&rc);
if (debug)
qDebug() << '<' << Q_FUNC_INFO << rc.size();
return rc;
}
PluginManager::PluginManager()
{
}
void PluginManager::setPluginPaths(const QStringList &paths)
{
foreach (const QString &path, paths) {
const QDir dir(path);
if (!dir.exists())
continue;
m_paths.push_back(PluginPath(dir));
}
// also register path in widgetpluginmanager
MetaInfo::setPluginPaths(paths);
}
QAbstractItemModel *PluginManager::createModel(QObject *parent)
{
QStandardItemModel *model = new QStandardItemModel(parent);
const auto end = m_paths.end();
for (auto it = m_paths.begin(); it != end; ++it)
model->appendRow(it->createModelItem());
return model;
}
QDialog *PluginManager::createAboutPluginDialog(QWidget *parent)
{
QDialog *rc = new QDialog(parent);
rc->setWindowFlags(rc->windowFlags() & ~Qt::WindowContextHelpButtonHint & Qt::Sheet);
rc->setWindowTitle(QCoreApplication::translate("QmlDesigner::PluginManager", "About Plugins"));
QTreeView *treeView = new QTreeView;
treeView->setModel(createModel(treeView));
treeView->expandAll();
QVBoxLayout *layout = new QVBoxLayout(rc);
layout->addWidget(treeView);
QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
layout->addWidget(bb);
QObject::connect(bb, SIGNAL(rejected()), rc, SLOT(reject()));
return rc;
}
} // namespace QmlDesigner
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "pluginpath.h"
#include <QObject>
#include <QList>
QT_BEGIN_NAMESPACE
class QString;
class QAbstractItemModel;
class QDialog;
QT_END_NAMESPACE
namespace QmlDesigner {
class IPlugin;
// PluginManager: Loads the plugin libraries on demand "as lazy as
// possible", that is, directories are scanned and
// instances are created only when instances() is called.
class PluginManager
{
Q_DISABLE_COPY(PluginManager)
typedef QList<PluginPath> PluginPathList;
public:
typedef QList<IPlugin *> IPluginList;
PluginManager();
void setPluginPaths(const QStringList &paths);
IPluginList instances();
QDialog *createAboutPluginDialog(QWidget *parent);
private: // functions
// Convenience to create a model for an "About Plugins"
// dialog. Forces plugin initialization.
QAbstractItemModel *createModel(QObject *parent = 0);
private: // variables
PluginPathList m_paths;
};
} // namespace QmlDesigner
VPATH += $$PWD
INCLUDEPATH += $$PWD
SOURCES += pluginmanager.cpp \
pluginpath.cpp \
iplugin.cpp
HEADERS += pluginmanager.h \
pluginpath.h \
iplugin.h
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "pluginpath.h"
#include "pluginmanager.h"
#include <utils/fileutils.h>
#include <iplugin.h>
#include <QLibrary>
#include <QPluginLoader>
#include <QFileInfo>
#include <QCoreApplication>
#include <QStandardItem>
#include <QObject>
#include <QDebug>
enum { debug = 0 };
namespace QmlDesigner {
// Initialize and create instance of a plugin from scratch,
// that is, make sure the library is loaded and has an instance
// of the IPlugin type. Once something fails, mark it as failed
// ignore it from then on.
static IPlugin *instance(PluginData &p)
{
// Go stale once something fails
if (p.failed)
return 0;
// Pull up the plugin, retrieve IPlugin instance.
if (!p.instanceGuard) {
p.instance = 0;
QPluginLoader loader(p.path);
if (!(loader.isLoaded() || loader.load())) {
p.failed = true;
p.errorMessage = loader.errorString();
return 0;
}
QObject *object = loader.instance();
if (!object) {
p.failed = true;
p.errorMessage = QCoreApplication::translate("WidgetPluginManager", "Failed to create instance.");
return 0;
}
IPlugin *iplugin = qobject_cast<IPlugin *>(object);
if (!iplugin) {
p.failed = true;
p.errorMessage = QCoreApplication::translate("WidgetPluginManager", "Not a QmlDesigner plugin.");
delete object;
return 0;
}
p.instanceGuard = object;
p.instance = iplugin;
}
// Ensure it is initialized
/*if (!p.instance->isInitialized()) {
if (!p.instance->initialize(&p.errorMessage)) {
p.failed = true;
delete p.instance;
p.instance = 0;
return 0;
}
}*/
return p.instance;
}
PluginData::PluginData(const QString &p) :
path(p),
failed(false),
instance(0)
{
}
PluginPath::PluginPath(const QDir &path) :
m_path(path),
m_loaded(false)
{
}
// Determine a unique list of library files in that directory
QStringList PluginPath::libraryFilePaths(const QDir &dir)
{
const QFileInfoList infoList = dir.entryInfoList(QDir::Files|QDir::Readable|QDir::NoDotAndDotDot);
if (infoList.empty())
return QStringList();
// Load symbolic links but make sure all file names are unique as not
// to fall for something like 'libplugin.so.1 -> libplugin.so'
QStringList result;
const auto icend = infoList.constEnd();
for (auto it = infoList.constBegin(); it != icend; ++it) {
QString fileName;
if (it->isSymLink()) {
const QFileInfo linkTarget = QFileInfo(it->symLinkTarget());
if (linkTarget.exists() && linkTarget.isFile())
fileName = linkTarget.absoluteFilePath();
} else {
fileName = it->absoluteFilePath();
}
if (!fileName.isEmpty() && QLibrary::isLibrary(fileName) && !result.contains(fileName))
result += fileName;
}
qDebug() << "Library file paths: " << result;
return result;
}
void PluginPath::clear()
{
m_loaded = false;
m_plugins.clear();
}
void PluginPath::ensureLoaded()
{
if (!m_loaded) {
const QStringList libraryFiles = libraryFilePaths(m_path);
if (debug)
qDebug() << "Checking " << libraryFiles.size() << " plugins " << m_path.absolutePath();
foreach (const QString &libFile, libraryFiles)
m_plugins.push_back(PluginData(libFile));
m_loaded = true;
}
}
void PluginPath::getInstances(PluginManager::IPluginList *list)
{
ensureLoaded();
// Compile list of instances
if (m_plugins.empty())
return;
const auto end = m_plugins.end();
for (auto it = m_plugins.begin(); it != end; ++it)
if (IPlugin *i = instance(*it))
list->push_back(i);
}
QStandardItem *PluginPath::createModelItem()
{
ensureLoaded();
// Create a list of plugin lib files with classes.
// If there are failed ones, create a separate "Failed"
// category at the end
QStandardItem *pathItem = new QStandardItem(m_path.absolutePath());
QStandardItem *failedCategory = 0;
const auto end = m_plugins.end();
for (auto it = m_plugins.begin(); it != end; ++it) {
QStandardItem *pluginItem = new QStandardItem(Utils::FileName::fromString(it->path).fileName());
if (instance(*it)) {
pluginItem->appendRow(new QStandardItem(QString::fromUtf8(it->instanceGuard->metaObject()->className())));
pathItem->appendRow(pluginItem);
} else {
pluginItem->setToolTip(it->errorMessage);
if (!failedCategory) {
const QString failed = QCoreApplication::translate("PluginManager", "Failed Plugins");
failedCategory = new QStandardItem(failed);
}
failedCategory->appendRow(pluginItem);
}
}
if (failedCategory)
pathItem->appendRow(failedCategory);
return pathItem;
}
} // namespace QmlDesigner
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <QObject>
#include <QPointer>
#include <QList>
#include <QDir>
QT_BEGIN_NAMESPACE
class QString;
class QAbstractItemModel;
class QStandardItem;
QT_END_NAMESPACE
namespace QmlDesigner {
class IPlugin;
// Dumb plugin data structure. Note that whereas QObjects can
// casted to an interface, QPointer does not work with the
// interface class, so, we need a separate QPointer as a guard
// to detect the deletion of a plugin instance which can happen
// in theory.
struct PluginData {
PluginData(const QString &p = QString());
QString path;
bool failed;
QString errorMessage;
QPointer<QObject> instanceGuard;
IPlugin *instance;
};
// PluginPath: Manages a plugin directory. It does nothing
// on construction following the "as lazy as possible" principle.
// In the "loaded" stage, it scans the directories and creates
// a list of PluginData for the libraries found.
// getInstances() will return the fully initialized list of
// IPlugins.
class PluginPath {
typedef QList<IPlugin *> IPluginList;
public:
explicit PluginPath(const QDir &path);
void getInstances(IPluginList *list);
QDir path() const { return m_path; }
// Convenience to populate a "About Plugin" dialog with
// plugins from that path. Forces initialization.
QStandardItem *createModelItem();
private:
typedef QList<PluginData> PluginDataList;
static QStringList libraryFilePaths(const QDir &dir);
void clear();
void ensureLoaded();
QDir m_path;
bool m_loaded;
PluginDataList m_plugins;
};
} // namespace QmlDesigner
......@@ -74,7 +74,6 @@ public:
Internal::DesignModeWidget *mainWidget;
QmlDesigner::PluginManager pluginManager;
DesignerSettings settings;
Internal::DesignModeContext *context;
};
......@@ -188,12 +187,6 @@ bool QmlDesignerPlugin::initialize(const QStringList & /*arguments*/, QString *e
switchTextDesignAction, QmlDesigner::Constants::SWITCH_TEXT_DESIGN, switchContext);
command->setDefaultKeySequence(QKeySequence(Qt::Key_F4));
const QString pluginPath = Utils::HostOsInfo::isMacHost()
? QString(QCoreApplication::applicationDirPath() + "/../PlugIns/QmlDesigner")
: QString(QCoreApplication::applicationDirPath() + "/../"
+ QLatin1String(IDE_LIBRARY_BASENAME) + "/qtcreator/plugins/qmldesigner");
d->pluginManager.setPluginPaths(QStringList() << pluginPath);
createDesignModeWidget();
connect(switchTextDesignAction, &QAction::triggered, this, &switchTextDesign);
......
......@@ -26,7 +26,6 @@
#pragma once
#include <qmldesigner/designersettings.h>
#include <qmldesigner/components/pluginmanager/pluginmanager.h>
#include <qmldesignercorelib_global.h>
#include <extensionsystem/iplugin.h>
......
......@@ -15,7 +15,6 @@ include(components/propertyeditor/propertyeditor.pri)
include(components/formeditor/formeditor.pri)
include(components/itemlibrary/itemlibrary.pri)
include(components/navigator/navigator.pri)
include(components/pluginmanager/pluginmanager.pri)
include(components/stateseditor/stateseditor.pri)
include(components/resources/resources.pri)
include(components/debugview/debugview.pri)
......
......@@ -514,12 +514,6 @@ QtcPlugin {
"navigator/navigatorview.h",
"navigator/navigatorwidget.cpp",
"navigator/navigatorwidget.h",
"pluginmanager/iplugin.cpp",
"pluginmanager/iplugin.h",
"pluginmanager/pluginmanager.cpp",
"pluginmanager/pluginmanager.h",
"pluginmanager/pluginpath.cpp",
"pluginmanager/pluginpath.h",
"propertyeditor/designerpropertymap.cpp",
"propertyeditor/designerpropertymap.h",
"propertyeditor/fileresourcesmodel.cpp",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment