| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the Qt Designer of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 | #include "plugindialog_p.h"
|
|---|
| 44 | #include "pluginmanager_p.h"
|
|---|
| 45 | #include "qdesigner_integration_p.h"
|
|---|
| 46 |
|
|---|
| 47 | #include <QtDesigner/QDesignerFormEditorInterface>
|
|---|
| 48 | #include <QtDesigner/QDesignerCustomWidgetCollectionInterface>
|
|---|
| 49 | #include <QtDesigner/QDesignerWidgetDataBaseInterface>
|
|---|
| 50 |
|
|---|
| 51 | #include <QtGui/QStyle>
|
|---|
| 52 | #include <QtGui/QHeaderView>
|
|---|
| 53 | #include <QtGui/QPushButton>
|
|---|
| 54 | #include <QtCore/QFileInfo>
|
|---|
| 55 | #include <QtCore/QPluginLoader>
|
|---|
| 56 |
|
|---|
| 57 | QT_BEGIN_NAMESPACE
|
|---|
| 58 |
|
|---|
| 59 | namespace qdesigner_internal {
|
|---|
| 60 |
|
|---|
| 61 | PluginDialog::PluginDialog(QDesignerFormEditorInterface *core, QWidget *parent)
|
|---|
| 62 | : QDialog(parent
|
|---|
| 63 | #ifdef Q_WS_MAC
|
|---|
| 64 | , Qt::Tool
|
|---|
| 65 | #endif
|
|---|
| 66 | ), m_core(core)
|
|---|
| 67 | {
|
|---|
| 68 | ui.setupUi(this);
|
|---|
| 69 |
|
|---|
| 70 | ui.message->hide();
|
|---|
| 71 |
|
|---|
| 72 | const QStringList headerLabels(tr("Components"));
|
|---|
| 73 |
|
|---|
| 74 | ui.treeWidget->setAlternatingRowColors(false);
|
|---|
| 75 | ui.treeWidget->setSelectionMode(QAbstractItemView::NoSelection);
|
|---|
| 76 | ui.treeWidget->setHeaderLabels(headerLabels);
|
|---|
| 77 | ui.treeWidget->header()->hide();
|
|---|
| 78 |
|
|---|
| 79 | interfaceIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirOpenIcon),
|
|---|
| 80 | QIcon::Normal, QIcon::On);
|
|---|
| 81 | interfaceIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirClosedIcon),
|
|---|
| 82 | QIcon::Normal, QIcon::Off);
|
|---|
| 83 | featureIcon.addPixmap(style()->standardPixmap(QStyle::SP_FileIcon));
|
|---|
| 84 |
|
|---|
| 85 | setWindowTitle(tr("Plugin Information"));
|
|---|
| 86 | populateTreeWidget();
|
|---|
| 87 |
|
|---|
| 88 | if (qobject_cast<qdesigner_internal::QDesignerIntegration *>(m_core->integration())) {
|
|---|
| 89 | QPushButton *updateButton = new QPushButton(tr("Refresh"));
|
|---|
| 90 | const QString tooltip = tr("Scan for newly installed custom widget plugins.");
|
|---|
| 91 | updateButton->setToolTip(tooltip);
|
|---|
| 92 | updateButton->setWhatsThis(tooltip);
|
|---|
| 93 | connect(updateButton, SIGNAL(clicked()), this, SLOT(updateCustomWidgetPlugins()));
|
|---|
| 94 | ui.buttonBox->addButton(updateButton, QDialogButtonBox::ActionRole);
|
|---|
| 95 | }
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | void PluginDialog::populateTreeWidget()
|
|---|
| 99 | {
|
|---|
| 100 | ui.treeWidget->clear();
|
|---|
| 101 | QDesignerPluginManager *pluginManager = m_core->pluginManager();
|
|---|
| 102 | const QStringList fileNames = pluginManager->registeredPlugins();
|
|---|
| 103 |
|
|---|
| 104 | if (!fileNames.isEmpty()) {
|
|---|
| 105 | QTreeWidgetItem *topLevelItem = setTopLevelItem(tr("Loaded Plugins"));
|
|---|
| 106 | QFont boldFont = topLevelItem->font(0);
|
|---|
| 107 |
|
|---|
| 108 | foreach (const QString &fileName, fileNames) {
|
|---|
| 109 | QPluginLoader loader(fileName);
|
|---|
| 110 | const QFileInfo fileInfo(fileName);
|
|---|
| 111 |
|
|---|
| 112 | QTreeWidgetItem *pluginItem = setPluginItem(topLevelItem, fileInfo.fileName(), boldFont);
|
|---|
| 113 |
|
|---|
| 114 | if (QObject *plugin = loader.instance()) {
|
|---|
| 115 | if (const QDesignerCustomWidgetCollectionInterface *c = qobject_cast<QDesignerCustomWidgetCollectionInterface*>(plugin)) {
|
|---|
| 116 | foreach (const QDesignerCustomWidgetInterface *p, c->customWidgets())
|
|---|
| 117 | setItem(pluginItem, p->name(), p->toolTip(), p->whatsThis(), p->icon());
|
|---|
| 118 | } else {
|
|---|
| 119 | if (const QDesignerCustomWidgetInterface *p = qobject_cast<QDesignerCustomWidgetInterface*>(plugin))
|
|---|
| 120 | setItem(pluginItem, p->name(), p->toolTip(), p->whatsThis(), p->icon());
|
|---|
| 121 | }
|
|---|
| 122 | }
|
|---|
| 123 | }
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | const QStringList notLoadedPlugins = pluginManager->failedPlugins();
|
|---|
| 127 | if (!notLoadedPlugins.isEmpty()) {
|
|---|
| 128 | QTreeWidgetItem *topLevelItem = setTopLevelItem(tr("Failed Plugins"));
|
|---|
| 129 | const QFont boldFont = topLevelItem->font(0);
|
|---|
| 130 | foreach (const QString &plugin, notLoadedPlugins) {
|
|---|
| 131 | const QString failureReason = pluginManager->failureReason(plugin);
|
|---|
| 132 | QTreeWidgetItem *pluginItem = setPluginItem(topLevelItem, plugin, boldFont);
|
|---|
| 133 | setItem(pluginItem, failureReason, failureReason, QString(), QIcon());
|
|---|
| 134 | }
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | if (ui.treeWidget->topLevelItemCount() == 0) {
|
|---|
| 138 | ui.label->setText(tr("Qt Designer couldn't find any plugins"));
|
|---|
| 139 | ui.treeWidget->hide();
|
|---|
| 140 | } else {
|
|---|
| 141 | ui.label->setText(tr("Qt Designer found the following plugins"));
|
|---|
| 142 | }
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | QIcon PluginDialog::pluginIcon(const QIcon &icon)
|
|---|
| 146 | {
|
|---|
| 147 | if (icon.isNull())
|
|---|
| 148 | return QIcon(QLatin1String(":/trolltech/formeditor/images/qtlogo.png"));
|
|---|
| 149 |
|
|---|
| 150 | return icon;
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | QTreeWidgetItem* PluginDialog::setTopLevelItem(const QString &itemName)
|
|---|
| 154 | {
|
|---|
| 155 | QTreeWidgetItem *topLevelItem = new QTreeWidgetItem(ui.treeWidget);
|
|---|
| 156 | topLevelItem->setText(0, itemName);
|
|---|
| 157 | ui.treeWidget->setItemExpanded(topLevelItem, true);
|
|---|
| 158 | topLevelItem->setIcon(0, style()->standardPixmap(QStyle::SP_DirOpenIcon));
|
|---|
| 159 |
|
|---|
| 160 | QFont boldFont = topLevelItem->font(0);
|
|---|
| 161 | boldFont.setBold(true);
|
|---|
| 162 | topLevelItem->setFont(0, boldFont);
|
|---|
| 163 |
|
|---|
| 164 | return topLevelItem;
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | QTreeWidgetItem* PluginDialog::setPluginItem(QTreeWidgetItem *topLevelItem,
|
|---|
| 168 | const QString &itemName, const QFont &font)
|
|---|
| 169 | {
|
|---|
| 170 | QTreeWidgetItem *pluginItem = new QTreeWidgetItem(topLevelItem);
|
|---|
| 171 | pluginItem->setFont(0, font);
|
|---|
| 172 | pluginItem->setText(0, itemName);
|
|---|
| 173 | ui.treeWidget->setItemExpanded(pluginItem, true);
|
|---|
| 174 | pluginItem->setIcon(0, style()->standardPixmap(QStyle::SP_DirOpenIcon));
|
|---|
| 175 |
|
|---|
| 176 | return pluginItem;
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | void PluginDialog::setItem(QTreeWidgetItem *pluginItem, const QString &name,
|
|---|
| 180 | const QString &toolTip, const QString &whatsThis, const QIcon &icon)
|
|---|
| 181 | {
|
|---|
| 182 | QTreeWidgetItem *item = new QTreeWidgetItem(pluginItem);
|
|---|
| 183 | item->setText(0, name);
|
|---|
| 184 | item->setToolTip(0, toolTip);
|
|---|
| 185 | item->setWhatsThis(0, whatsThis);
|
|---|
| 186 | item->setIcon(0, pluginIcon(icon));
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | void PluginDialog::updateCustomWidgetPlugins()
|
|---|
| 190 | {
|
|---|
| 191 | if (qdesigner_internal::QDesignerIntegration *integration = qobject_cast<qdesigner_internal::QDesignerIntegration *>(m_core->integration())) {
|
|---|
| 192 | const int before = m_core->widgetDataBase()->count();
|
|---|
| 193 | integration->updateCustomWidgetPlugins();
|
|---|
| 194 | const int after = m_core->widgetDataBase()->count();
|
|---|
| 195 | if (after > before) {
|
|---|
| 196 | ui.message->setText(tr("New custom widget plugins have been found."));
|
|---|
| 197 | ui.message->show();
|
|---|
| 198 | } else {
|
|---|
| 199 | ui.message->setText(QString());
|
|---|
| 200 | }
|
|---|
| 201 | populateTreeWidget();
|
|---|
| 202 | }
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | QT_END_NAMESPACE
|
|---|