vcsbaseclient.h 9.08 KB
Newer Older
cerf's avatar
cerf committed
1
2
/**************************************************************************
**
3
** Copyright (c) 2014 Brian McGillion and Hugues Delorme
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
cerf's avatar
cerf committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
cerf's avatar
cerf committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** 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
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
cerf's avatar
cerf committed
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
cerf's avatar
cerf committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
cerf's avatar
cerf committed
29
30
31
32
33

#ifndef VCSBASECLIENT_H
#define VCSBASECLIENT_H

#include "vcsbase_global.h"
hjk's avatar
hjk committed
34
#include <coreplugin/id.h>
cerf's avatar
cerf committed
35

36
37
#include <QObject>
#include <QStringList>
cerf's avatar
cerf committed
38
39
40

QT_BEGIN_NAMESPACE
class QFileInfo;
41
42
class QVariant;
class QProcessEnvironment;
cerf's avatar
cerf committed
43
44
45
46
QT_END_NAMESPACE

namespace Utils {
struct SynchronousProcessResponse;
47
class ExitCodeInterpreter;
cerf's avatar
cerf committed
48
49
}

hjk's avatar
hjk committed
50
namespace VcsBase {
cerf's avatar
cerf committed
51

52
class Command;
hjk's avatar
hjk committed
53
54
55
56
57
class VcsBaseEditorWidget;
class VcsBaseClientSettings;
class VcsJob;
class VcsBaseClientPrivate;
class VcsBaseEditorParameterWidget;
cerf's avatar
cerf committed
58

hjk's avatar
hjk committed
59
class VCSBASE_EXPORT VcsBaseClient : public QObject
cerf's avatar
cerf committed
60
61
{
    Q_OBJECT
hjk's avatar
hjk committed
62

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

hjk's avatar
hjk committed
73
74
    explicit VcsBaseClient(VcsBaseClientSettings *settings);
    ~VcsBaseClient();
75
76
    virtual bool synchronousCreateRepository(const QString &workingDir,
                                             const QStringList &extraOptions = QStringList());
cerf's avatar
cerf committed
77
78
79
    virtual bool synchronousClone(const QString &workingDir,
                                  const QString &srcLocation,
                                  const QString &dstLocation,
80
                                  const QStringList &extraOptions = QStringList());
81
82
83
84
    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
85
    virtual bool synchronousMove(const QString &workingDir,
86
87
                                 const QString &from, const QString &to,
                                 const QStringList &extraOptions = QStringList());
cerf's avatar
cerf committed
88
89
    virtual bool synchronousPull(const QString &workingDir,
                                 const QString &srcLocation,
90
                                 const QStringList &extraOptions = QStringList());
cerf's avatar
cerf committed
91
92
    virtual bool synchronousPush(const QString &workingDir,
                                 const QString &dstLocation,
93
                                 const QStringList &extraOptions = QStringList());
94
    virtual void annotate(const QString &workingDir, const QString &file,
95
                          const QString &revision = QString(), int lineNumber = -1,
96
97
98
99
100
101
102
103
                          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());
104
105
    virtual void emitParsedStatus(const QString &repository,
                                  const QStringList &extraOptions = QStringList());
106
107
108
109
110
111
112
113
114
115
116
117
    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
118
119
120

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

hjk's avatar
hjk committed
121
    virtual VcsBaseClientSettings *settings() const;
122
    virtual QProcessEnvironment processEnvironment() const;
123

cerf's avatar
cerf committed
124
signals:
hjk's avatar
hjk committed
125
126
    void parsedStatus(const QList<VcsBase::VcsBaseClient::StatusItem> &statusList);
    // Passes on changed signals from VcsJob to Control
cerf's avatar
cerf committed
127
128
129
    void changed(const QVariant &v);

public slots:
130
131
    virtual void view(const QString &source, const QString &id,
                      const QStringList &extraOptions = QStringList());
cerf's avatar
cerf committed
132
133

protected:
hjk's avatar
hjk committed
134
    enum VcsCommand
cerf's avatar
cerf committed
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
    {
        CreateRepositoryCommand,
        CloneCommand,
        AddCommand,
        RemoveCommand,
        MoveCommand,
        PullCommand,
        PushCommand,
        CommitCommand,
        ImportCommand,
        UpdateCommand,
        RevertCommand,
        AnnotateCommand,
        DiffCommand,
        LogCommand,
        StatusCommand
    };
hjk's avatar
hjk committed
152
    virtual QString vcsCommandString(VcsCommand cmd) const;
hjk's avatar
hjk committed
153
    virtual Core::Id vcsEditorKind(VcsCommand cmd) const = 0;
154
    virtual Utils::ExitCodeInterpreter *exitCodeInterpreter(VcsCommand cmd, QObject *parent) const;
cerf's avatar
cerf committed
155

156
    virtual QStringList revisionSpec(const QString &revision) const = 0;
hjk's avatar
hjk committed
157
    virtual VcsBaseEditorParameterWidget *createDiffEditor(const QString &workingDir,
158
159
                                                           const QStringList &files,
                                                           const QStringList &extraOptions);
hjk's avatar
hjk committed
160
    virtual VcsBaseEditorParameterWidget *createLogEditor(const QString &workingDir,
161
162
                                                          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
                                 const QStringList &args,
169
                                 QByteArray *output) const;
cerf's avatar
cerf committed
170
    // Synchronous VCS execution using Utils::SynchronousProcess, with
hjk's avatar
hjk committed
171
    // log windows updating (using VcsBasePlugin::runVcs with flags)
cerf's avatar
cerf committed
172
173
174
    Utils::SynchronousProcessResponse vcsSynchronousExec(const QString &workingDir,
                                                         const QStringList &args,
                                                         unsigned flags = 0,
175
                                                         QTextCodec *outputCodec = 0) const;
hjk's avatar
hjk committed
176
    VcsBase::VcsBaseEditorWidget *createVcsEditor(Core::Id kind, QString title,
cerf's avatar
cerf committed
177
178
179
180
                                                  const QString &source, bool setSourceCodec,
                                                  const char *registerDynamicProperty,
                                                  const QString &dynamicPropertyValue) const;

181
182
183
184
185
    enum JobOutputBindMode {
        NoOutputBind,
        VcsWindowOutputBind
    };
    Command *createCommand(const QString &workingDirectory,
hjk's avatar
hjk committed
186
                           VcsBase::VcsBaseEditorWidget *editor = 0,
187
                           JobOutputBindMode mode = NoOutputBind) const;
188
    void enqueueJob(Command *cmd, const QStringList &args, Utils::ExitCodeInterpreter *interpreter = 0);
189

190
191
    void resetCachedVcsInfo(const QString &workingDir);

cerf's avatar
cerf committed
192
private:
hjk's avatar
hjk committed
193
194
    friend class VcsBaseClientPrivate;
    VcsBaseClientPrivate *d;
195

Orgad Shaneh's avatar
Orgad Shaneh committed
196
    Q_PRIVATE_SLOT(d, void statusParser(QString))
Orgad Shaneh's avatar
Orgad Shaneh committed
197
    Q_PRIVATE_SLOT(d, void annotateRevision(QString,QString,QString,int))
198
    Q_PRIVATE_SLOT(d, void saveSettings())
Orgad Shaneh's avatar
Orgad Shaneh committed
199
    Q_PRIVATE_SLOT(d, void commandFinishedGotoLine(QWidget*))
cerf's avatar
cerf committed
200
201
};

hjk's avatar
hjk committed
202
} //namespace VcsBase
cerf's avatar
cerf committed
203
204

#endif // VCSBASECLIENT_H