vcsbaseclient.h 8.77 KB
Newer Older
cerf's avatar
cerf committed
1 2 3 4 5 6
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Brian McGillion & Hugues Delorme
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
cerf's avatar
cerf committed
8 9 10 11
**
**
** GNU Lesser General Public License Usage
**
hjk's avatar
hjk committed
12 13 14 15 16 17
** 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.
cerf's avatar
cerf committed
18 19
**
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
cerf's avatar
cerf committed
21 22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23 24 25 26 27
** 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.
**
cerf's avatar
cerf committed
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
cerf's avatar
cerf committed
30 31 32 33 34 35 36 37 38 39 40
**
**************************************************************************/

#ifndef VCSBASECLIENT_H
#define VCSBASECLIENT_H

#include "vcsbase_global.h"

#include <QtCore/QObject>
#include <QtCore/QStringList>
#include <QtCore/QSharedPointer>
41 42
#include <QtCore/QVariant>
#include <QtCore/QProcessEnvironment>
cerf's avatar
cerf committed
43 44 45 46 47 48 49 50 51 52 53

QT_BEGIN_NAMESPACE
class QFileInfo;
QT_END_NAMESPACE

namespace Utils {
struct SynchronousProcessResponse;
}

namespace VCSBase {

54
class Command;
cerf's avatar
cerf committed
55 56 57
class VCSBaseEditorWidget;
class VCSBaseClientSettings;
class VCSJob;
Friedemann Kleint's avatar
Friedemann Kleint committed
58
class VCSBaseClientPrivate;
59
class VCSBaseEditorParameterWidget;
cerf's avatar
cerf committed
60 61 62 63

class VCSBASE_EXPORT VCSBaseClient : public QObject
{
    Q_OBJECT
hjk's avatar
hjk committed
64

cerf's avatar
cerf committed
65
public:
66
    class VCSBASE_EXPORT StatusItem
67
    {
68
    public:
hjk's avatar
hjk committed
69
        StatusItem() {}
70 71 72 73 74
        StatusItem(const QString &s, const QString &f);
        QString flags;
        QString file;
    };

75
    explicit VCSBaseClient(VCSBaseClientSettings *settings);
cerf's avatar
cerf committed
76
    ~VCSBaseClient();
77 78
    virtual bool synchronousCreateRepository(const QString &workingDir,
                                             const QStringList &extraOptions = QStringList());
cerf's avatar
cerf committed
79 80 81
    virtual bool synchronousClone(const QString &workingDir,
                                  const QString &srcLocation,
                                  const QString &dstLocation,
82
                                  const QStringList &extraOptions = QStringList());
83 84 85 86
    virtual bool synchronousAdd(const QString &workingDir, const QString &fileName,
                                const QStringList &extraOptions = QStringList());
    virtual bool synchronousRemove(const QString &workingDir, const QString &fileName,
                                   const QStringList &extraOptions = QStringList());
cerf's avatar
cerf committed
87
    virtual bool synchronousMove(const QString &workingDir,
88 89
                                 const QString &from, const QString &to,
                                 const QStringList &extraOptions = QStringList());
cerf's avatar
cerf committed
90 91
    virtual bool synchronousPull(const QString &workingDir,
                                 const QString &srcLocation,
92
                                 const QStringList &extraOptions = QStringList());
cerf's avatar
cerf committed
93 94
    virtual bool synchronousPush(const QString &workingDir,
                                 const QString &dstLocation,
95
                                 const QStringList &extraOptions = QStringList());
96 97 98 99 100 101 102 103 104 105
    virtual void annotate(const QString &workingDir, const QString &file,
                          const QString revision = QString(), int lineNumber = -1,
                          const QStringList &extraOptions = QStringList());
    virtual void diff(const QString &workingDir, const QStringList &files = QStringList(),
                      const QStringList &extraOptions = QStringList());
    virtual void log(const QString &workingDir, const QStringList &files = QStringList(),
                     const QStringList &extraOptions = QStringList(),
                     bool enableAnnotationContextMenu = false);
    virtual void status(const QString &workingDir, const QString &file = QString(),
                        const QStringList &extraOptions = QStringList());
106 107
    virtual void emitParsedStatus(const QString &repository,
                                  const QStringList &extraOptions = QStringList());
108 109 110 111 112 113 114 115 116 117 118 119
    virtual void revertFile(const QString &workingDir, const QString &file,
                            const QString &revision = QString(),
                            const QStringList &extraOptions = QStringList());
    virtual void revertAll(const QString &workingDir, const QString &revision = QString(),
                           const QStringList &extraOptions = QStringList());
    virtual void import(const QString &repositoryRoot, const QStringList &files,
                        const QStringList &extraOptions = QStringList());
    virtual void update(const QString &repositoryRoot, const QString &revision = QString(),
                        const QStringList &extraOptions = QStringList());
    virtual void commit(const QString &repositoryRoot, const QStringList &files,
                        const QString &commitMessageFile,
                        const QStringList &extraOptions = QStringList());
cerf's avatar
cerf committed
120 121 122

    virtual QString findTopLevelForFile(const QFileInfo &file) const = 0;

123
    virtual VCSBaseClientSettings *settings() const;
124

cerf's avatar
cerf committed
125
signals:
126
    void parsedStatus(const QList<VCSBase::VCSBaseClient::StatusItem> &statusList);
cerf's avatar
cerf committed
127 128 129 130
    // Passes on changed signals from VCSJob to Control
    void changed(const QVariant &v);

public slots:
131 132
    virtual void view(const QString &source, const QString &id,
                      const QStringList &extraOptions = QStringList());
cerf's avatar
cerf committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155

protected:
    enum VCSCommand
    {
        CreateRepositoryCommand,
        CloneCommand,
        AddCommand,
        RemoveCommand,
        MoveCommand,
        PullCommand,
        PushCommand,
        CommitCommand,
        ImportCommand,
        UpdateCommand,
        RevertCommand,
        AnnotateCommand,
        DiffCommand,
        LogCommand,
        StatusCommand
    };
    virtual QString vcsCommandString(VCSCommand cmd) const;
    virtual QString vcsEditorKind(VCSCommand cmd) const = 0;

156
    virtual QStringList revisionSpec(const QString &revision) const = 0;
157 158 159
    virtual VCSBaseEditorParameterWidget *createDiffEditor(const QString &workingDir,
                                                           const QStringList &files,
                                                           const QStringList &extraOptions);
160 161 162
    virtual VCSBaseEditorParameterWidget *createLogEditor(const QString &workingDir,
                                                          const QStringList &files,
                                                          const QStringList &extraOptions);
163
    virtual StatusItem parseStatusLine(const QString &line) const = 0;
cerf's avatar
cerf committed
164 165 166

    QString vcsEditorTitle(const QString &vcsCmd, const QString &sourceId) const;
    // Fully synchronous VCS execution (QProcess-based)
167
    bool vcsFullySynchronousExec(const QString &workingDir,
cerf's avatar
cerf committed
168 169 170 171 172 173 174 175 176 177 178 179 180
                                 const QStringList &args,
                                 QByteArray *output);
    // Synchronous VCS execution using Utils::SynchronousProcess, with
    // log windows updating (using VCSBasePlugin::runVCS with flags)
    Utils::SynchronousProcessResponse vcsSynchronousExec(const QString &workingDir,
                                                         const QStringList &args,
                                                         unsigned flags = 0,
                                                         QTextCodec *outputCodec = 0);
    VCSBase::VCSBaseEditorWidget *createVCSEditor(const QString &kind, QString title,
                                                  const QString &source, bool setSourceCodec,
                                                  const char *registerDynamicProperty,
                                                  const QString &dynamicPropertyValue) const;

181 182 183 184 185 186 187 188 189 190 191
    virtual QProcessEnvironment processEnvironment() const;

    enum JobOutputBindMode {
        NoOutputBind,
        VcsWindowOutputBind
    };
    Command *createCommand(const QString &workingDirectory,
                           VCSBase::VCSBaseEditorWidget *editor = 0,
                           JobOutputBindMode mode = NoOutputBind);
    void enqueueJob(Command *cmd, const QStringList &args);

192 193
    void resetCachedVcsInfo(const QString &workingDir);

cerf's avatar
cerf committed
194
private:
195
    friend class VCSBaseClientPrivate;
hjk's avatar
hjk committed
196
    VCSBaseClientPrivate *d;
197 198 199 200

    Q_PRIVATE_SLOT(d, void statusParser(QByteArray))
    Q_PRIVATE_SLOT(d, void annotateRevision(QString, QString, int))
    Q_PRIVATE_SLOT(d, void saveSettings())
201
    Q_PRIVATE_SLOT(d, void commandFinishedGotoLine(QObject *))
cerf's avatar
cerf committed
202 203 204 205 206
};

} //namespace VCSBase

#endif // VCSBASECLIENT_H