2010-11-10 08:49:19 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-02-21 14:57:44 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-11-10 08:49:19 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2010-11-10 08:49:19 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2010-11-10 08:49:19 +01:00
|
|
|
**
|
2011-02-21 14:57:44 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-02-21 14:57:44 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2011-02-21 14:57:44 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-11-10 08:49:19 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#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"
|
2011-01-06 11:01:57 +01:00
|
|
|
#include "actionmanager/command.h"
|
2011-01-21 10:58:06 +01:00
|
|
|
#include "actionmanager/actioncontainer.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>
|
2011-02-01 15:55:40 +01:00
|
|
|
#include <QtCore/QSharedPointer>
|
2010-12-08 12:08:21 +01:00
|
|
|
#include <QtCore/QTextCodec>
|
2011-02-21 11:29:16 +01:00
|
|
|
#include <QtGui/QMenu>
|
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
|
2010-12-08 12:08:21 +01:00
|
|
|
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;
|
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
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
2011-01-21 10:58:06 +01:00
|
|
|
QMap<QString, QList<Internal::ExternalTool *> > toolsByCategory() const;
|
|
|
|
|
QMap<QString, Internal::ExternalTool *> toolsById() const;
|
|
|
|
|
|
|
|
|
|
void setToolsByCategory(const QMap<QString, QList<Internal::ExternalTool *> > &tools);
|
2011-01-06 18:26:09 +01:00
|
|
|
|
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();
|
2011-02-21 11:29:16 +01:00
|
|
|
void openPreferences();
|
2010-11-11 15:47:23 +01:00
|
|
|
|
|
|
|
|
private:
|
2010-12-09 15:53:43 +01:00
|
|
|
void initialize();
|
2011-01-21 10:58:06 +01:00
|
|
|
void parseDirectory(const QString &directory,
|
|
|
|
|
QMap<QString, QMultiMap<int, Internal::ExternalTool*> > *categoryMenus,
|
|
|
|
|
QMap<QString, Internal::ExternalTool *> *tools,
|
2011-01-24 18:14:30 +01:00
|
|
|
bool isPreset = false);
|
2011-01-21 10:58:06 +01:00
|
|
|
void readSettings(const QMap<QString, Internal::ExternalTool *> &tools,
|
2011-02-10 14:16:11 +01:00
|
|
|
QMap<QString, QList<Internal::ExternalTool*> > *categoryPriorityMap);
|
2011-01-21 10:58:06 +01:00
|
|
|
void writeSettings();
|
2010-12-09 15:53:43 +01:00
|
|
|
|
|
|
|
|
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;
|
2011-01-06 18:26:09 +01:00
|
|
|
QMap<QString, QList<Internal::ExternalTool *> > m_categoryMap;
|
2011-01-21 10:58:06 +01:00
|
|
|
QMap<QString, QAction *> m_actions;
|
|
|
|
|
QMap<QString, ActionContainer *> m_containers;
|
2011-02-21 11:29:16 +01:00
|
|
|
QAction *m_configureSeparator;
|
|
|
|
|
QAction *m_configureAction;
|
2010-12-09 15:53:43 +01:00
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
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
|