1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef PERFORCEPLUGIN_H
35 #define PERFORCEPLUGIN_H
37 #include "perforcesettings.h"
39 #include <coreplugin/editormanager/ieditorfactory.h>
40 #include <coreplugin/iversioncontrol.h>
41 #include <vcsbase/vcsbaseplugin.h>
43 #include <QtCore/QObject>
44 #include <QtCore/QProcess>
45 #include <QtCore/QStringList>
46 #include <QtCore/QSharedPointer>
47 #include <QtCore/QHash>
57 class ParameterAction;
67 class PerforceVersionControl;
69 struct PerforceResponse
80 class PerforcePlugin : public VCSBase::VCSBasePlugin
88 bool initialize(const QStringList &arguments, QString *error_message);
89 void extensionsInitialized();
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);
97 void p4Diff(const QString &workingDir, const QStringList &files);
99 Core::IEditor *openPerforceSubmitEditor(const QString &fileName, const QStringList &depotFileNames);
101 static PerforcePlugin *perforcePluginInstance();
103 const PerforceSettings& settings() const;
104 void setSettings(const Settings &s);
106 // Map a perforce name "//xx" to its real name in the file system
107 QString fileNameFromPerforceName(const QString& perforceName,
109 QString *errorMessage) const;
112 void describe(const QString &source, const QString &n);
113 void vcsAnnotate(const QString &file, const QString &revision /* = QString() */, int lineNumber);
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();
126 void diffAllOpened();
127 void startSubmitProject();
128 void describeChange();
129 void annotateCurrentFile();
131 void filelogCurrentFile();
134 void logRepository();
136 void submitCurrentLog();
137 void printPendingChanges();
138 void slotSubmitDiff(const QStringList &files);
139 void slotTopLevelFound(const QString &);
140 void slotTopLevelFailed(const QString &);
143 virtual void updateActions(VCSBase::VCSBasePlugin::ActionState);
144 virtual bool submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *submitEditor);
148 typedef QHash<QString, bool> ManagedDirectoryCache;
150 Core::IEditor *showOutputInEditor(const QString& title, const QString output,
151 int editorType, const QString &source,
152 QTextCodec *codec = 0);
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,
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;
174 inline PerforceResponse synchronousProcess(const QString &workingDir,
175 const QStringList &args,
177 const QByteArray &stdInput,
178 QTextCodec *outputCodec) const;
180 inline PerforceResponse fullySynchronousProcess(const QString &workingDir,
181 const QStringList &args,
183 const QByteArray &stdInput,
184 QTextCodec *outputCodec) const;
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;
195 QString pendingChangesData();
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);
202 inline PerforceVersionControl *perforceVersionControl() const;
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;
236 static PerforcePlugin *m_perforcePluginInstance;
238 PerforceSettings m_settings;
239 ManagedDirectoryCache m_managedDirectoryCache;
242 } // namespace Perforce
243 } // namespace Internal
245 #endif // PERFORCEPLUGIN_H