2010-11-10 08:49:19 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** Commercial Usage
|
|
|
|
|
**
|
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef EXTERNALTOOL_H
|
|
|
|
|
#define EXTERNALTOOL_H
|
|
|
|
|
|
2010-11-11 15:47:23 +01:00
|
|
|
#include "icore.h"
|
2010-12-09 15:53:43 +01:00
|
|
|
#include "core_global.h"
|
2010-11-11 15:47:23 +01:00
|
|
|
|
2010-12-15 16:48:11 +01:00
|
|
|
#include <utils/qtcprocess.h>
|
|
|
|
|
|
2010-11-11 15:47:23 +01:00
|
|
|
#include <QtCore/QObject>
|
2010-11-10 08:49:19 +01:00
|
|
|
#include <QtCore/QString>
|
|
|
|
|
#include <QtCore/QStringList>
|
2010-12-08 12:08:21 +01:00
|
|
|
#include <QtCore/QProcess>
|
|
|
|
|
#include <QtCore/QTextCodec>
|
2010-11-10 08:49:19 +01:00
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-12-08 12:08:21 +01:00
|
|
|
class ExternalTool : public QObject
|
2010-11-10 08:49:19 +01:00
|
|
|
{
|
2010-12-08 12:08:21 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
2010-11-10 08:49:19 +01:00
|
|
|
public:
|
|
|
|
|
enum OutputHandling {
|
2010-12-08 14:52:53 +01:00
|
|
|
Ignore,
|
2010-11-10 08:49:19 +01:00
|
|
|
ShowInPane,
|
|
|
|
|
ReplaceSelection,
|
|
|
|
|
ReloadDocument
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ExternalTool();
|
2010-12-08 12:08:21 +01:00
|
|
|
~ExternalTool();
|
2010-11-10 08:49:19 +01:00
|
|
|
|
2010-11-11 14:57:29 +01:00
|
|
|
QString id() const;
|
2010-11-10 08:49:19 +01:00
|
|
|
QString description() const;
|
|
|
|
|
QString displayName() const;
|
|
|
|
|
QString displayCategory() const;
|
|
|
|
|
int order() const;
|
|
|
|
|
OutputHandling outputHandling() const;
|
2010-12-08 14:52:53 +01:00
|
|
|
OutputHandling errorHandling() const;
|
2010-11-10 08:49:19 +01:00
|
|
|
|
|
|
|
|
QStringList executables() const;
|
|
|
|
|
QString arguments() const;
|
2010-12-09 14:57:22 +01:00
|
|
|
QString input() const;
|
2010-11-10 08:49:19 +01:00
|
|
|
QString workingDirectory() const;
|
|
|
|
|
|
2010-11-11 15:47:23 +01:00
|
|
|
static ExternalTool *createFromXml(const QByteArray &xml, QString *errorMessage = 0, const QString &locale = QString());
|
2010-11-10 08:49:19 +01:00
|
|
|
|
|
|
|
|
private:
|
2010-11-11 14:57:29 +01:00
|
|
|
QString m_id;
|
2010-11-10 08:49:19 +01:00
|
|
|
QString m_description;
|
|
|
|
|
QString m_displayName;
|
|
|
|
|
QString m_displayCategory;
|
|
|
|
|
int m_order;
|
|
|
|
|
QStringList m_executables;
|
|
|
|
|
QString m_arguments;
|
2010-12-09 14:57:22 +01:00
|
|
|
QString m_input;
|
2010-11-10 08:49:19 +01:00
|
|
|
QString m_workingDirectory;
|
|
|
|
|
OutputHandling m_outputHandling;
|
2010-12-08 14:52:53 +01:00
|
|
|
OutputHandling m_errorHandling;
|
2010-11-10 08:49:19 +01:00
|
|
|
};
|
|
|
|
|
|
2010-12-08 12:08:21 +01:00
|
|
|
class ExternalToolRunner : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
ExternalToolRunner(const ExternalTool *tool);
|
|
|
|
|
|
|
|
|
|
private slots:
|
2010-12-09 14:57:22 +01:00
|
|
|
void started();
|
2010-12-13 17:35:40 +01:00
|
|
|
void finished(int exitCode, QProcess::ExitStatus status);
|
2010-12-08 12:08:21 +01:00
|
|
|
void error(QProcess::ProcessError error);
|
|
|
|
|
void readStandardOutput();
|
|
|
|
|
void readStandardError();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void run();
|
|
|
|
|
bool resolve();
|
|
|
|
|
|
|
|
|
|
const ExternalTool *m_tool;
|
|
|
|
|
QString m_resolvedExecutable;
|
2010-12-15 16:48:11 +01:00
|
|
|
QString m_resolvedArguments;
|
2010-12-09 14:57:22 +01:00
|
|
|
QString m_resolvedInput;
|
2010-12-08 12:08:21 +01:00
|
|
|
QString m_resolvedWorkingDirectory;
|
2010-12-15 16:48:11 +01:00
|
|
|
Utils::QtcProcess *m_process;
|
2010-12-08 12:08:21 +01:00
|
|
|
QTextCodec *m_outputCodec;
|
|
|
|
|
QTextCodec::ConverterState m_outputCodecState;
|
|
|
|
|
QTextCodec::ConverterState m_errorCodecState;
|
2010-12-09 15:53:43 +01:00
|
|
|
QString m_processOutput;
|
2010-12-13 17:35:40 +01:00
|
|
|
QString m_expectedFileName;
|
2010-12-08 12:08:21 +01:00
|
|
|
};
|
|
|
|
|
|
2010-12-09 15:53:43 +01:00
|
|
|
} // Internal
|
|
|
|
|
|
|
|
|
|
class CORE_EXPORT ExternalToolManager : public QObject
|
2010-11-11 15:47:23 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2010-12-09 15:53:43 +01:00
|
|
|
static ExternalToolManager *instance() { return m_instance; }
|
|
|
|
|
|
2010-11-11 15:47:23 +01:00
|
|
|
ExternalToolManager(Core::ICore *core);
|
|
|
|
|
~ExternalToolManager();
|
|
|
|
|
|
2010-12-09 15:53:43 +01:00
|
|
|
signals:
|
|
|
|
|
void replaceSelectionRequested(const QString &text);
|
2010-11-11 15:47:23 +01:00
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void menuActivated();
|
|
|
|
|
|
|
|
|
|
private:
|
2010-12-09 15:53:43 +01:00
|
|
|
void initialize();
|
|
|
|
|
|
|
|
|
|
static ExternalToolManager *m_instance;
|
2010-11-11 15:47:23 +01:00
|
|
|
Core::ICore *m_core;
|
2010-12-09 15:53:43 +01:00
|
|
|
QMap<QString, Internal::ExternalTool *> m_tools;
|
|
|
|
|
|
|
|
|
|
// for sending the replaceSelectionRequested signal
|
|
|
|
|
friend class Core::Internal::ExternalToolRunner;
|
2010-11-11 15:47:23 +01:00
|
|
|
};
|
|
|
|
|
|
2010-11-10 08:49:19 +01:00
|
|
|
} // Core
|
|
|
|
|
|
|
|
|
|
#endif // EXTERNALTOOL_H
|