[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the examples of the Qt Toolkit.
|
---|
| 8 | **
|
---|
[846] | 9 | ** $QT_BEGIN_LICENSE:BSD$
|
---|
| 10 | ** You may use this file under the terms of the BSD license as follows:
|
---|
[2] | 11 | **
|
---|
[846] | 12 | ** "Redistribution and use in source and binary forms, with or without
|
---|
| 13 | ** modification, are permitted provided that the following conditions are
|
---|
| 14 | ** met:
|
---|
| 15 | ** * Redistributions of source code must retain the above copyright
|
---|
| 16 | ** notice, this list of conditions and the following disclaimer.
|
---|
| 17 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
| 18 | ** notice, this list of conditions and the following disclaimer in
|
---|
| 19 | ** the documentation and/or other materials provided with the
|
---|
| 20 | ** distribution.
|
---|
| 21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
---|
| 22 | ** the names of its contributors may be used to endorse or promote
|
---|
| 23 | ** products derived from this software without specific prior written
|
---|
| 24 | ** permission.
|
---|
[2] | 25 | **
|
---|
[846] | 26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
| 27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
| 28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
| 29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
---|
| 30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
| 31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
| 32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
| 36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
---|
[2] | 37 | ** $QT_END_LICENSE$
|
---|
| 38 | **
|
---|
| 39 | ****************************************************************************/
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | #include "interfaces.h"
|
---|
| 43 | #include "plugindialog.h"
|
---|
| 44 |
|
---|
| 45 | #include <QPluginLoader>
|
---|
| 46 | #include <QStringList>
|
---|
| 47 | #include <QDir>
|
---|
| 48 |
|
---|
| 49 | #include <QLabel>
|
---|
| 50 | #include <QGridLayout>
|
---|
| 51 | #include <QPushButton>
|
---|
| 52 | #include <QTreeWidget>
|
---|
| 53 | #include <QTreeWidgetItem>
|
---|
| 54 | #include <QHeaderView>
|
---|
| 55 |
|
---|
| 56 | PluginDialog::PluginDialog(const QString &path, const QStringList &fileNames,
|
---|
| 57 | QWidget *parent) :
|
---|
| 58 | QDialog(parent),
|
---|
| 59 | label(new QLabel),
|
---|
| 60 | treeWidget(new QTreeWidget),
|
---|
| 61 | okButton(new QPushButton(tr("OK")))
|
---|
| 62 | {
|
---|
| 63 | treeWidget->setAlternatingRowColors(false);
|
---|
| 64 | treeWidget->setSelectionMode(QAbstractItemView::NoSelection);
|
---|
| 65 | treeWidget->setColumnCount(1);
|
---|
| 66 | treeWidget->header()->hide();
|
---|
| 67 |
|
---|
| 68 | okButton->setDefault(true);
|
---|
| 69 |
|
---|
| 70 | connect(okButton, SIGNAL(clicked()), this, SLOT(close()));
|
---|
| 71 |
|
---|
| 72 | QGridLayout *mainLayout = new QGridLayout;
|
---|
| 73 | mainLayout->setColumnStretch(0, 1);
|
---|
| 74 | mainLayout->setColumnStretch(2, 1);
|
---|
| 75 | mainLayout->addWidget(label, 0, 0, 1, 3);
|
---|
| 76 | mainLayout->addWidget(treeWidget, 1, 0, 1, 3);
|
---|
| 77 | mainLayout->addWidget(okButton, 2, 1);
|
---|
| 78 | setLayout(mainLayout);
|
---|
| 79 |
|
---|
| 80 | interfaceIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirOpenIcon),
|
---|
| 81 | QIcon::Normal, QIcon::On);
|
---|
| 82 | interfaceIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirClosedIcon),
|
---|
| 83 | QIcon::Normal, QIcon::Off);
|
---|
| 84 | featureIcon.addPixmap(style()->standardPixmap(QStyle::SP_FileIcon));
|
---|
| 85 |
|
---|
| 86 | setWindowTitle(tr("Plugin Information"));
|
---|
| 87 | findPlugins(path, fileNames);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | //! [0]
|
---|
| 91 | void PluginDialog::findPlugins(const QString &path,
|
---|
| 92 | const QStringList &fileNames)
|
---|
| 93 | {
|
---|
| 94 | label->setText(tr("Plug & Paint found the following plugins\n"
|
---|
| 95 | "(looked in %1):")
|
---|
| 96 | .arg(QDir::toNativeSeparators(path)));
|
---|
| 97 |
|
---|
| 98 | const QDir dir(path);
|
---|
| 99 |
|
---|
| 100 | foreach (QObject *plugin, QPluginLoader::staticInstances())
|
---|
| 101 | populateTreeWidget(plugin, tr("%1 (Static Plugin)")
|
---|
| 102 | .arg(plugin->metaObject()->className()));
|
---|
| 103 |
|
---|
| 104 | foreach (QString fileName, fileNames) {
|
---|
| 105 | QPluginLoader loader(dir.absoluteFilePath(fileName));
|
---|
| 106 | QObject *plugin = loader.instance();
|
---|
| 107 | if (plugin)
|
---|
| 108 | populateTreeWidget(plugin, fileName);
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 | //! [0]
|
---|
| 112 |
|
---|
| 113 | //! [1]
|
---|
| 114 | void PluginDialog::populateTreeWidget(QObject *plugin, const QString &text)
|
---|
| 115 | {
|
---|
| 116 | QTreeWidgetItem *pluginItem = new QTreeWidgetItem(treeWidget);
|
---|
| 117 | pluginItem->setText(0, text);
|
---|
| 118 | treeWidget->setItemExpanded(pluginItem, true);
|
---|
| 119 |
|
---|
| 120 | QFont boldFont = pluginItem->font(0);
|
---|
| 121 | boldFont.setBold(true);
|
---|
| 122 | pluginItem->setFont(0, boldFont);
|
---|
| 123 |
|
---|
| 124 | if (plugin) {
|
---|
| 125 | BrushInterface *iBrush = qobject_cast<BrushInterface *>(plugin);
|
---|
| 126 | if (iBrush)
|
---|
| 127 | addItems(pluginItem, "BrushInterface", iBrush->brushes());
|
---|
| 128 |
|
---|
| 129 | ShapeInterface *iShape = qobject_cast<ShapeInterface *>(plugin);
|
---|
| 130 | if (iShape)
|
---|
| 131 | addItems(pluginItem, "ShapeInterface", iShape->shapes());
|
---|
| 132 |
|
---|
| 133 | FilterInterface *iFilter =
|
---|
| 134 | qobject_cast<FilterInterface *>(plugin);
|
---|
| 135 | if (iFilter)
|
---|
| 136 | addItems(pluginItem, "FilterInterface", iFilter->filters());
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
| 139 | //! [1]
|
---|
| 140 |
|
---|
| 141 | void PluginDialog::addItems(QTreeWidgetItem *pluginItem,
|
---|
| 142 | const char *interfaceName,
|
---|
| 143 | const QStringList &features)
|
---|
| 144 | {
|
---|
| 145 | QTreeWidgetItem *interfaceItem = new QTreeWidgetItem(pluginItem);
|
---|
| 146 | interfaceItem->setText(0, interfaceName);
|
---|
| 147 | interfaceItem->setIcon(0, interfaceIcon);
|
---|
| 148 |
|
---|
| 149 | foreach (QString feature, features) {
|
---|
| 150 | if (feature.endsWith("..."))
|
---|
| 151 | feature.chop(3);
|
---|
| 152 | QTreeWidgetItem *featureItem = new QTreeWidgetItem(interfaceItem);
|
---|
| 153 | featureItem->setText(0, feature);
|
---|
| 154 | featureItem->setIcon(0, featureIcon);
|
---|
| 155 | }
|
---|
| 156 | }
|
---|