4 This file is part of GammaRay, the Qt application inspection and
7 Copyright (C) 2010-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 <config-gammaray.h>
26 #include "styleinjector.h"
27 #include "interactiveprocess.h"
33 using namespace GammaRay
;
35 StyleInjector::StyleInjector() :
37 mProcessError(QProcess::UnknownError
),
38 mExitStatus(QProcess::NormalExit
)
42 bool StyleInjector::launch(const QStringList
&programAndArgs
,
43 const QString
&probeDll
, const QString
&probeFunc
)
45 QProcessEnvironment env
= QProcessEnvironment::systemEnvironment();
46 env
.insert("GAMMARAY_STYLEINJECTOR_PROBEDLL", probeDll
);
47 env
.insert("GAMMARAY_STYLEINJECTOR_PROBEFUNC", probeFunc
);
49 QString qtPluginPath
= env
.value("QT_PLUGIN_PATH");
50 if (!qtPluginPath
.isEmpty()) {
51 qtPluginPath
.append(":");
53 qtPluginPath
.append(GAMMARAY_LIB_INSTALL_DIR
"/qt4/plugins");
54 env
.insert("QT_PLUGIN_PATH", qtPluginPath
);
56 InteractiveProcess proc
;
57 proc
.setProcessEnvironment(env
);
58 proc
.setProcessChannelMode(QProcess::ForwardedChannels
);
60 QStringList args
= programAndArgs
;
62 if (env
.value("GAMMARAY_GDB").toInt()) {
64 newArgs
<< "gdb" << "--eval-command" << "run" << "--args";
67 } else if (env
.value("GAMMARAY_MEMCHECK").toInt()) {
69 newArgs
<< "valgrind" << "--tool=memcheck" << "--track-origins=yes" << "--num-callers=25";
72 } else if (env
.value("GAMMARAY_HELGRIND").toInt()) {
74 newArgs
<< "valgrind" << "--tool=helgrind";
79 const QString program
= args
.takeFirst();
80 args
<< QLatin1String("-style") << QLatin1String("gammaray-injector");
81 proc
.start(program
, args
);
82 proc
.waitForFinished(-1);
84 mExitCode
= proc
.exitCode();
85 mProcessError
= proc
.error();
86 mExitStatus
= proc
.exitStatus();
87 mErrorString
= proc
.errorString();
89 return mExitCode
== EXIT_SUCCESS
&& mExitStatus
== QProcess::NormalExit
;
92 bool StyleInjector::selfTest()
94 // TODO: be a bit more clever in finding the plugin location (also when actually using it above)
96 const QString stylePath
=
97 QLatin1String(GAMMARAY_LIB_INSTALL_DIR
"/qt4/plugins/styles/gammaray_injector_style.so");
99 const QString stylePath
=
100 QLatin1String(GAMMARAY_LIB_INSTALL_DIR
"/qt4/plugins/styles/gammaray_injector_style.dll");
103 QFileInfo
fi(stylePath
);
104 if (!fi
.exists() || !fi
.isFile() || !fi
.isReadable()) {
106 QObject::tr("Injector style plugin does not exists or is not readable at %1.").arg(stylePath
);
113 int StyleInjector::exitCode()
118 QProcess::ProcessError
StyleInjector::processError()
120 return mProcessError
;
123 QProcess::ExitStatus
StyleInjector::exitStatus()
128 QString
StyleInjector::errorString()