4 This file is part of GammaRay, the Qt application inspection and
7 Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
8 Author: Volker Krause <volker.krause@kdab.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "proxytoolfactory.h"
26 #include <qpluginloader.h>
27 #include <qsettings.h>
28 #include <qfileinfo.h>
34 using namespace GammaRay
;
36 ProxyToolFactory::ProxyToolFactory(const QString
&path
, QObject
*parent
)
37 : QObject(parent
), m_factory(0)
39 const QFileInfo
pluginInfo(path
);
40 m_id
= pluginInfo
.baseName();
42 QSettings
desktopFile(path
, QSettings::IniFormat
);
43 desktopFile
.beginGroup(QLatin1String("Desktop Entry"));
44 m_name
= desktopFile
.value(QLatin1String("Name")).toString();
47 QLatin1String("X-GammaRay-Types")).toString().split(QLatin1Char(';'),
48 QString::SkipEmptyParts
);
50 pluginInfo
.dir().absoluteFilePath(desktopFile
.value(QLatin1String("Exec")).toString());
52 const QString dllBaseName
= desktopFile
.value(QLatin1String("Exec")).toString();
53 if (dllBaseName
.isEmpty()) {
57 foreach (const QString
&entry
,
58 pluginInfo
.dir().entryList(QStringList(dllBaseName
+ QLatin1Char('*')), QDir::Files
)) {
59 const QString path
= pluginInfo
.dir().absoluteFilePath(entry
);
60 if (QLibrary::isLibrary(path
)) {
67 bool ProxyToolFactory::isValid() const
72 !m_pluginPath
.isEmpty() &&
73 !m_supportedTypes
.isEmpty();
76 QString
ProxyToolFactory::id() const
81 QString
ProxyToolFactory::name() const
86 QStringList
ProxyToolFactory::supportedTypes() const
88 return m_supportedTypes
;
91 void ProxyToolFactory::init(ProbeInterface
*probe
)
93 QPluginLoader
loader(m_pluginPath
, this);
94 m_factory
= qobject_cast
<ToolFactory
*>(loader
.instance());
96 std::cerr
<< "error loading plugin " << qPrintable(m_pluginPath
)
97 << ": " << qPrintable(loader
.errorString()) << std::endl
;
101 m_factory
->init(probe
);
104 QWidget
*ProxyToolFactory::createWidget(ProbeInterface
*probe
, QWidget
*parentWidget
)
107 return new QLabel(tr("Plugin '%1' could not be loaded.").arg(m_pluginPath
), parentWidget
);
110 return m_factory
->createWidget(probe
, parentWidget
);
113 #include "proxytoolfactory.moc"