2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-11-10 08:49:19 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-11-10 08:49:19 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-11-10 08:49:19 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2010-11-10 08:49:19 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2010-11-10 08:49:19 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-02-21 14:57:44 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-11-10 08:49:19 +01:00
|
|
|
|
|
|
|
|
#ifndef EXTERNALTOOL_H
|
|
|
|
|
#define EXTERNALTOOL_H
|
|
|
|
|
|
2014-07-15 23:32:11 +03:00
|
|
|
#include <utils/fileutils.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QObject>
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
#include <QProcess>
|
|
|
|
|
#include <QSharedPointer>
|
|
|
|
|
#include <QTextCodec>
|
|
|
|
|
#include <QMetaType>
|
2010-11-10 08:49:19 +01:00
|
|
|
|
2014-02-11 21:55:42 +02:00
|
|
|
namespace Utils { class QtcProcess; }
|
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,
|
2011-01-24 12:21:42 +01:00
|
|
|
ReplaceSelection
|
2010-11-10 08:49:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ExternalTool();
|
2011-01-21 10:58:06 +01:00
|
|
|
explicit ExternalTool(const ExternalTool *other);
|
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;
|
2011-01-24 12:21:42 +01:00
|
|
|
bool modifiesCurrentDocument() 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;
|
|
|
|
|
|
2011-01-24 18:14:30 +01:00
|
|
|
void setFileName(const QString &fileName);
|
2011-02-01 15:55:40 +01:00
|
|
|
void setPreset(QSharedPointer<ExternalTool> preset);
|
2011-01-24 18:14:30 +01:00
|
|
|
QString fileName() const;
|
2011-02-01 15:55:40 +01:00
|
|
|
// all tools that are preset (changed or unchanged) have the original value here:
|
|
|
|
|
QSharedPointer<ExternalTool> preset() const;
|
2011-01-24 18:14:30 +01:00
|
|
|
|
2010-11-11 15:47:23 +01:00
|
|
|
static ExternalTool *createFromXml(const QByteArray &xml, QString *errorMessage = 0, const QString &locale = QString());
|
2011-01-24 18:14:30 +01:00
|
|
|
static ExternalTool *createFromFile(const QString &fileName, QString *errorMessage = 0,
|
2011-02-01 15:55:40 +01:00
|
|
|
const QString &locale = QString());
|
2011-01-24 18:14:30 +01:00
|
|
|
|
|
|
|
|
bool save(QString *errorMessage = 0) const;
|
2010-11-10 08:49:19 +01:00
|
|
|
|
2011-02-25 15:27:13 +01:00
|
|
|
bool operator==(const ExternalTool &other) const;
|
|
|
|
|
bool operator!=(const ExternalTool &other) const { return !((*this) == other); }
|
2011-02-08 12:28:35 +01:00
|
|
|
ExternalTool &operator=(const ExternalTool &other);
|
2011-01-24 15:01:48 +01:00
|
|
|
|
2011-02-02 12:35:32 +01:00
|
|
|
void setId(const QString &id);
|
2011-02-10 10:03:46 +01:00
|
|
|
void setDisplayCategory(const QString &category);
|
2011-01-24 15:01:48 +01:00
|
|
|
void setDisplayName(const QString &name);
|
|
|
|
|
void setDescription(const QString &description);
|
|
|
|
|
void setOutputHandling(OutputHandling handling);
|
|
|
|
|
void setErrorHandling(OutputHandling handling);
|
|
|
|
|
void setModifiesCurrentDocument(bool modifies);
|
|
|
|
|
void setExecutables(const QStringList &executables);
|
|
|
|
|
void setArguments(const QString &arguments);
|
|
|
|
|
void setInput(const QString &input);
|
|
|
|
|
void setWorkingDirectory(const QString &workingDirectory);
|
2011-01-24 18:14:30 +01:00
|
|
|
|
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;
|
2011-01-24 12:21:42 +01:00
|
|
|
bool m_modifiesCurrentDocument;
|
|
|
|
|
|
2011-01-24 18:14:30 +01:00
|
|
|
QString m_fileName;
|
|
|
|
|
QString m_presetFileName;
|
2011-02-01 15:55:40 +01:00
|
|
|
QSharedPointer<ExternalTool> m_presetTool;
|
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);
|
2011-01-21 10:58:06 +01:00
|
|
|
~ExternalToolRunner();
|
2010-12-08 12:08:21 +01:00
|
|
|
|
2011-03-22 13:37:19 +01:00
|
|
|
bool hasError() const;
|
|
|
|
|
QString errorString() const;
|
|
|
|
|
|
2010-12-08 12:08:21 +01:00
|
|
|
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();
|
|
|
|
|
|
2011-01-21 10:58:06 +01:00
|
|
|
const ExternalTool *m_tool; // is a copy of the tool that was passed in
|
2014-07-15 23:32:11 +03:00
|
|
|
Utils::FileName 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;
|
2011-03-22 13:37:19 +01:00
|
|
|
bool m_hasError;
|
|
|
|
|
QString m_errorString;
|
2010-12-08 12:08:21 +01:00
|
|
|
};
|
|
|
|
|
|
2010-12-09 15:53:43 +01:00
|
|
|
} // Internal
|
2010-11-10 08:49:19 +01:00
|
|
|
} // Core
|
|
|
|
|
|
2011-01-06 18:26:09 +01:00
|
|
|
Q_DECLARE_METATYPE(Core::Internal::ExternalTool *)
|
|
|
|
|
|
2010-11-10 08:49:19 +01:00
|
|
|
#endif // EXTERNALTOOL_H
|