d/control: Recommend gdb
[gammaray-debian.git] / proxytoolfactory.cpp
blob88f7a578cbb4c6ddc60a6c468df09ed9c5cc504e
1 /*
2 proxytoolfactory.cpp
4 This file is part of GammaRay, the Qt application inspection and
5 manipulation tool.
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>
29 #include <qdir.h>
30 #include <QLabel>
32 #include <iostream>
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();
45 m_supportedTypes =
46 desktopFile.value(
47 QLatin1String("X-GammaRay-Types")).toString().split(QLatin1Char(';'),
48 QString::SkipEmptyParts);
49 m_pluginPath =
50 pluginInfo.dir().absoluteFilePath(desktopFile.value(QLatin1String("Exec")).toString());
52 const QString dllBaseName = desktopFile.value(QLatin1String("Exec")).toString();
53 if (dllBaseName.isEmpty()) {
54 return;
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)) {
61 m_pluginPath = path;
62 break;
67 bool ProxyToolFactory::isValid() const
69 return
70 !m_id.isEmpty() &&
71 !m_name.isEmpty() &&
72 !m_pluginPath.isEmpty() &&
73 !m_supportedTypes.isEmpty();
76 QString ProxyToolFactory::id() const
78 return m_id;
81 QString ProxyToolFactory::name() const
83 return m_name;
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());
95 if (!m_factory) {
96 std::cerr << "error loading plugin " << qPrintable(m_pluginPath)
97 << ": " << qPrintable(loader.errorString()) << std::endl;
98 return;
100 Q_ASSERT(m_factory);
101 m_factory->init(probe);
104 QWidget *ProxyToolFactory::createWidget(ProbeInterface *probe, QWidget *parentWidget)
106 if (!m_factory) {
107 return new QLabel(tr("Plugin '%1' could not be loaded.").arg(m_pluginPath), parentWidget);
109 Q_ASSERT(m_factory);
110 return m_factory->createWidget(probe, parentWidget);
113 #include "proxytoolfactory.moc"