vcsbaseclient.h 8.07 KB
Newer Older
cerf's avatar
cerf committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Brian McGillion & Hugues Delorme
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/

#ifndef VCSBASECLIENT_H
#define VCSBASECLIENT_H

#include "vcsbase_global.h"

#include <QtCore/QObject>
#include <QtCore/QStringList>
#include <QtCore/QPair>
#include <QtCore/QSharedPointer>
Friedemann Kleint's avatar
Friedemann Kleint committed
43
#include <QtCore/QScopedPointer>
cerf's avatar
cerf committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <QtCore/QHash>
#include <QtCore/QVariant>

QT_BEGIN_NAMESPACE
class QFileInfo;
class QVariant;
QT_END_NAMESPACE

namespace Core {
class ICore;
}

namespace Utils {
struct SynchronousProcessResponse;
}

namespace VCSBase {

class VCSBaseEditorWidget;
class VCSBaseClientSettings;
class VCSJob;
Friedemann Kleint's avatar
Friedemann Kleint committed
65
class VCSBaseClientPrivate;
cerf's avatar
cerf committed
66
67
68
69
70
71
72

class VCSBASE_EXPORT VCSBaseClient : public QObject
{
    Q_OBJECT
public:
    typedef QHash<int, QVariant> ExtraCommandOptions;

Friedemann Kleint's avatar
Friedemann Kleint committed
73
    explicit VCSBaseClient(const VCSBaseClientSettings &settings);
cerf's avatar
cerf committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
    ~VCSBaseClient();
    virtual bool synchronousCreateRepository(const QString &workingDir);
    virtual bool synchronousClone(const QString &workingDir,
                                  const QString &srcLocation,
                                  const QString &dstLocation,
                                  const ExtraCommandOptions &extraOptions = ExtraCommandOptions());
    virtual bool synchronousAdd(const QString &workingDir, const QString &fileName);
    virtual bool synchronousRemove(const QString &workingDir, const QString &fileName);
    virtual bool synchronousMove(const QString &workingDir,
                                 const QString &from, const QString &to);
    virtual bool synchronousPull(const QString &workingDir,
                                 const QString &srcLocation,
                                 const ExtraCommandOptions &extraOptions = ExtraCommandOptions());
    virtual bool synchronousPush(const QString &workingDir,
                                 const QString &dstLocation,
                                 const ExtraCommandOptions &extraOptions = ExtraCommandOptions());
    void annotate(const QString &workingDir, const QString &file,
                  const QString revision = QString(), int lineNumber = -1);
    void diff(const QString &workingDir, const QStringList &files = QStringList());
    void log(const QString &workingDir, const QStringList &files = QStringList(),
             bool enableAnnotationContextMenu = false);
    void status(const QString &workingDir, const QString &file = QString());
    void statusWithSignal(const QString &repository);
    void revertFile(const QString &workingDir, const QString &file, const QString &revision = QString());
    void revertAll(const QString &workingDir, const QString &revision = QString());
    void import(const QString &repositoryRoot, const QStringList &files);
    void update(const QString &repositoryRoot, const QString &revision = QString());
    void commit(const QString &repositoryRoot,
                const QStringList &files,
                const QString &commitMessageFile,
                const ExtraCommandOptions &extraOptions = ExtraCommandOptions());

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

signals:
    void parsedStatus(const QList<QPair<QString, QString> > &statusList);
    // Passes on changed signals from VCSJob to Control
    void changed(const QVariant &v);

public slots:
    void view(const QString &source, const QString &id);
    void settingsChanged();

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;

    virtual QStringList cloneArguments(const QString &srcLocation,
                                       const QString &dstLocation,
                                       const ExtraCommandOptions &extraOptions) const = 0;
    virtual QStringList pullArguments(const QString &srcLocation,
                                      const ExtraCommandOptions &extraOptions) const = 0;
    virtual QStringList pushArguments(const QString &dstLocation,
                                      const ExtraCommandOptions &extraOptions) const = 0;
    virtual QStringList commitArguments(const QStringList &files,
                                        const QString &commitMessageFile,
                                        const ExtraCommandOptions &extraOptions) const = 0;
    virtual QStringList importArguments(const QStringList &files) const = 0;
    virtual QStringList updateArguments(const QString &revision) const = 0;
    virtual QStringList revertArguments(const QString &file, const QString &revision) const = 0;
    virtual QStringList revertAllArguments(const QString &revision) const = 0;
    virtual QStringList annotateArguments(const QString &file,
                                          const QString &revision, int lineNumber) const = 0;
    virtual QStringList diffArguments(const QStringList &files) const = 0;
    virtual QStringList logArguments(const QStringList &files) const = 0;
    virtual QStringList statusArguments(const QString &file) const = 0;
    virtual QStringList viewArguments(const QString &revision) const = 0;

    virtual QPair<QString, QString> parseStatusLine(const QString &line) const = 0;

    QString vcsEditorTitle(const QString &vcsCmd, const QString &sourceId) const;
    void enqueueJob(const QSharedPointer<VCSJob> &);
    // Fully synchronous VCS execution (QProcess-based)
cerf's avatar
cerf committed
165
    bool vcsFullySynchronousExec(const QString &workingDir,
cerf's avatar
cerf committed
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
                                 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;

private slots:
    void statusParser(const QByteArray &data);
    void slotAnnotateRevisionRequested(const QString &source, QString change, int lineNumber);

private:
Friedemann Kleint's avatar
Friedemann Kleint committed
184
    QScopedPointer<VCSBaseClientPrivate> d;
cerf's avatar
cerf committed
185
186
187
188
189
};

} //namespace VCSBase

#endif // VCSBASECLIENT_H