gitcommand.h 3.03 KB
Newer Older
1
/**************************************************************************
2 3 4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
8
**
9
** Commercial Usage
10
**
11 12 13 14
** 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.
15
**
16
** GNU Lesser General Public License Usage
17
**
18 19 20 21 22 23
** 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.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
27
**
28
**************************************************************************/
29 30 31 32 33

#ifndef GITCOMMAND_H
#define GITCOMMAND_H

#include <QtCore/QObject>
34
#include <QtCore/QStringList>
35
#include <QtCore/QVariant>
36 37 38 39

namespace Git {
namespace Internal {

40 41
// Asynchronous command with output signals and a finished
// signal with a magic cookie
42 43
class GitCommand : public QObject
{
44
    Q_DISABLE_COPY(GitCommand)
45 46
    Q_OBJECT
public:
47 48 49 50 51
    // Where to report command termination with exit code if desired
    enum TerminationReportMode { NoReport,
                                 ReportStdout,  // This assumes UTF8
                                 ReportStderr };

52
    explicit GitCommand(const QStringList &binary,
53
                        const QString &workingDirectory,
54 55
                        const QStringList &environment,
                        const QVariant &cookie = QVariant());
56 57


58
    void addJob(const QStringList &arguments, int timeout);
59 60
    void execute();

61 62 63 64
    // Clean output from carriage return and ANSI color codes.
    // Workaround until all relevant commands support "--no-color".
    static void removeColorCodes(QByteArray *data);

65 66 67 68
    // Report command termination with exit code
    TerminationReportMode reportTerminationMode() const;
    void setTerminationReportMode(TerminationReportMode m);

69 70 71 72 73 74
private:
    void run();

Q_SIGNALS:
    void outputData(const QByteArray&);
    void errorText(const QString&);
75
    void finished(bool ok, const QVariant &cookie);
76
    void success();
77 78 79

private:
    struct Job {
80
        explicit Job(const QStringList &a, int t);
81 82

        QStringList arguments;
83
        int timeout;
84 85
    };

86
    const QString m_binaryPath;
87
    QStringList m_basicArguments;
88 89
    const QString m_workingDirectory;
    const QStringList m_environment;
90
    const QVariant m_cookie;
91 92

    QList<Job> m_jobs;
93
    TerminationReportMode m_reportTerminationMode;
94 95 96 97 98
};

} // namespace Internal
} // namespace Git
#endif // GITCOMMAND_H