OSDN Git Service

e7558c04b23533a6200185d878365b5028a86a57
[qt-creator-jp/qt-creator-jp.git] / src / plugins / perforce / perforceplugin.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef PERFORCEPLUGIN_H
35 #define PERFORCEPLUGIN_H
36
37 #include "perforcesettings.h"
38
39 #include <coreplugin/editormanager/ieditorfactory.h>
40 #include <coreplugin/iversioncontrol.h>
41 #include <vcsbase/vcsbaseplugin.h>
42
43 #include <QtCore/QObject>
44 #include <QtCore/QProcess>
45 #include <QtCore/QStringList>
46 #include <QtCore/QSharedPointer>
47 #include <QtCore/QHash>
48
49 QT_BEGIN_NAMESPACE
50 class QFile;
51 class QAction;
52 class QTextCodec;
53 class QTemporaryFile;
54 QT_END_NAMESPACE
55
56 namespace Utils {
57     class ParameterAction;
58 }
59
60 namespace Locator {
61     class CommandLocator;
62 }
63
64 namespace Perforce {
65 namespace Internal {
66
67 class PerforceVersionControl;
68
69 struct PerforceResponse
70 {
71     PerforceResponse();
72
73     bool error;
74     int exitCode;
75     QString stdOut;
76     QString stdErr;
77     QString message;
78 };
79
80 class PerforcePlugin : public VCSBase::VCSBasePlugin
81 {
82     Q_OBJECT
83
84 public:
85     PerforcePlugin();
86     ~PerforcePlugin();
87
88     bool initialize(const QStringList &arguments, QString *error_message);
89     void extensionsInitialized();
90
91     bool managesDirectory(const QString &directory, QString *topLevel = 0);
92     bool vcsOpen(const QString &workingDir, const QString &fileName);
93     bool vcsAdd(const QString &workingDir, const QString &fileName);
94     bool vcsDelete(const QString &workingDir, const QString &filename);
95     bool vcsMove(const QString &workingDir, const QString &from, const QString &to);
96
97     void p4Diff(const QString &workingDir, const QStringList &files);
98
99     Core::IEditor *openPerforceSubmitEditor(const QString &fileName, const QStringList &depotFileNames);
100
101     static PerforcePlugin *perforcePluginInstance();
102
103     const PerforceSettings& settings() const;
104     void setSettings(const Settings &s);
105
106     // Map a perforce name "//xx" to its real name in the file system
107     QString fileNameFromPerforceName(const QString& perforceName,
108                                      bool quiet,
109                                      QString *errorMessage) const;
110
111 public slots:
112     void describe(const QString &source, const QString &n);
113     void vcsAnnotate(const QString &file, const QString &revision /* = QString() */, int lineNumber);
114
115 private slots:
116     void openCurrentFile();
117     void addCurrentFile();
118     void revertCurrentFile();
119     void printOpenedFileList();
120     void diffCurrentFile();
121     void diffCurrentProject();
122     void updateCurrentProject();
123     void revertCurrentProject();
124     void revertUnchangedCurrentProject();
125     void updateAll();
126     void diffAllOpened();
127     void startSubmitProject();
128     void describeChange();
129     void annotateCurrentFile();
130     void annotate();
131     void filelogCurrentFile();
132     void filelog();
133     void logProject();
134     void logRepository();
135
136     void submitCurrentLog();
137     void printPendingChanges();
138     void slotSubmitDiff(const QStringList &files);
139     void slotTopLevelFound(const QString &);
140     void slotTopLevelFailed(const QString &);
141
142 protected:
143     virtual void updateActions(VCSBase::VCSBasePlugin::ActionState);
144     virtual bool submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *submitEditor);
145
146
147 private:
148     typedef QHash<QString, bool> ManagedDirectoryCache;
149
150     Core::IEditor *showOutputInEditor(const QString& title, const QString output,
151                                       int editorType, const QString &source,
152                                       QTextCodec *codec = 0);
153
154     // Flags for runP4Cmd.
155     enum RunFlags { CommandToWindow = 0x1, StdOutToWindow = 0x2,
156                     StdErrToWindow = 0x4, ErrorToWindow = 0x8,
157                     OverrideDiffEnvironment = 0x10,
158                     // Run completely synchronously, no signals emitted
159                     RunFullySynchronous = 0x20,
160                     IgnoreExitCode = 0x40,
161                     ShowBusyCursor = 0x80,
162                     LongTimeOut = 0x100
163                    };
164
165     // args are passed as command line arguments
166     // extra args via a tempfile and the option -x "temp-filename"
167     PerforceResponse runP4Cmd(const QString &workingDir,
168                               const QStringList &args,
169                               unsigned flags = CommandToWindow|StdErrToWindow|ErrorToWindow,
170                               const QStringList &extraArgs = QStringList(),
171                               const QByteArray &stdInput = QByteArray(),
172                               QTextCodec *outputCodec = 0) const;
173
174     inline PerforceResponse synchronousProcess(const QString &workingDir,
175                                                const QStringList &args,
176                                                unsigned flags,
177                                                const QByteArray &stdInput,
178                                                QTextCodec *outputCodec) const;
179
180     inline PerforceResponse fullySynchronousProcess(const QString &workingDir,
181                                                     const QStringList &args,
182                                                     unsigned flags,
183                                                     const QByteArray &stdInput,
184                                                     QTextCodec *outputCodec) const;
185
186     QString clientFilePath(const QString &serverFilePath);
187     void annotate(const QString &workingDir, const QString &fileName,
188                   const QString &changeList = QString(), int lineNumber = -1);
189     void filelog(const QString &workingDir, const QStringList &fileNames = QStringList(),
190                  bool enableAnnotationContextMenu = false);
191     void cleanCommitMessageFile();
192     bool isCommitEditorOpen() const;
193     QSharedPointer<QTemporaryFile> createTemporaryArgumentFile(const QStringList &extraArgs) const;
194     void getTopLevel();
195     QString pendingChangesData();
196
197     void updateCheckout(const QString &workingDir = QString(),
198                         const QStringList &dirs = QStringList());
199     bool revertProject(const QString &workingDir, const QStringList &args, bool unchangedOnly);
200     bool managesDirectoryFstat(const QString &directory);
201
202     inline PerforceVersionControl *perforceVersionControl() const;
203
204     Locator::CommandLocator *m_commandLocator;
205     Utils::ParameterAction *m_editAction;
206     Utils::ParameterAction *m_addAction;
207     Utils::ParameterAction *m_deleteAction;
208     QAction *m_openedAction;
209     Utils::ParameterAction *m_revertFileAction;
210     Utils::ParameterAction *m_diffFileAction;
211     Utils::ParameterAction *m_diffProjectAction;
212     Utils::ParameterAction *m_updateProjectAction;
213     Utils::ParameterAction *m_revertProjectAction;
214     Utils::ParameterAction *m_revertUnchangedAction;
215     QAction *m_diffAllAction;
216     Utils::ParameterAction *m_submitProjectAction;
217     QAction *m_pendingAction;
218     QAction *m_describeAction;
219     Utils::ParameterAction *m_annotateCurrentAction;
220     QAction *m_annotateAction;
221     Utils::ParameterAction *m_filelogCurrentAction;
222     QAction *m_filelogAction;
223     Utils::ParameterAction *m_logProjectAction;
224     QAction *m_logRepositoryAction;
225     QAction *m_submitCurrentLogAction;
226     QAction *m_updateAllAction;
227     bool m_submitActionTriggered;
228     QAction *m_diffSelectedFiles;
229     QString m_commitMessageFileName;
230     QString m_commitWorkingDirectory;
231     mutable QString m_tempFilePattern;
232     QAction *m_undoAction;
233     QAction *m_redoAction;
234     QAction *m_menuAction;
235
236     static PerforcePlugin *m_perforcePluginInstance;
237
238     PerforceSettings m_settings;
239     ManagedDirectoryCache m_managedDirectoryCache;
240 };
241
242 } // namespace Perforce
243 } // namespace Internal
244
245 #endif // PERFORCEPLUGIN_H