2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#ifndef VCSBASEPLUGIN_H
|
|
|
|
#define VCSBASEPLUGIN_H
|
|
|
|
|
2009-12-08 14:26:41 +01:00
|
|
|
#include "vcsbase_global.h"
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <extensionsystem/iplugin.h>
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSharedDataPointer>
|
|
|
|
#include <QList>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-03-20 14:20:28 +01:00
|
|
|
QT_BEGIN_NAMESPACE
|
2009-12-08 14:26:41 +01:00
|
|
|
class QAction;
|
2010-05-21 17:46:00 +02:00
|
|
|
class QProcessEnvironment;
|
|
|
|
class QTextCodec;
|
2009-03-20 14:20:28 +01:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2012-01-07 03:35:54 +01:00
|
|
|
namespace Utils { struct SynchronousProcessResponse; }
|
2010-05-21 17:46:00 +02:00
|
|
|
|
2013-03-25 11:36:51 +01:00
|
|
|
namespace Core {
|
|
|
|
class IVersionControl;
|
|
|
|
class Id;
|
|
|
|
}
|
2009-12-08 14:26:41 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
namespace VcsBase {
|
2012-01-07 03:35:54 +01:00
|
|
|
|
|
|
|
namespace Internal { struct State; }
|
2009-12-08 14:26:41 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
class VcsBaseSubmitEditor;
|
|
|
|
struct VcsBasePluginPrivate;
|
|
|
|
class VcsBasePluginStateData;
|
|
|
|
class VcsBasePlugin;
|
2009-12-08 14:26:41 +01:00
|
|
|
|
2011-03-28 14:19:17 +02:00
|
|
|
// Documentation inside.
|
2012-01-07 12:31:48 +01:00
|
|
|
class VCSBASE_EXPORT VcsBasePluginState
|
2009-12-08 14:26:41 +01:00
|
|
|
{
|
|
|
|
public:
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBasePluginState();
|
|
|
|
VcsBasePluginState(const VcsBasePluginState &);
|
|
|
|
VcsBasePluginState &operator=(const VcsBasePluginState &);
|
|
|
|
~VcsBasePluginState();
|
2009-12-08 14:26:41 +01:00
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
bool isEmpty() const;
|
|
|
|
bool hasFile() const;
|
2010-03-25 16:23:37 +01:00
|
|
|
bool hasPatchFile() const;
|
2009-12-08 14:26:41 +01:00
|
|
|
bool hasProject() const;
|
|
|
|
bool hasTopLevel() const;
|
|
|
|
|
|
|
|
// Current file.
|
|
|
|
QString currentFile() const;
|
|
|
|
QString currentFileName() const;
|
|
|
|
QString currentFileDirectory() const;
|
|
|
|
QString currentFileTopLevel() const;
|
|
|
|
// Convenience: Returns file relative to top level.
|
|
|
|
QString relativeCurrentFile() const;
|
|
|
|
|
2010-03-25 16:23:37 +01:00
|
|
|
// If the current file looks like a patch and there is a top level,
|
|
|
|
// it will end up here (for VCS that offer patch functionality).
|
|
|
|
QString currentPatchFile() const;
|
|
|
|
QString currentPatchFileDisplayName() const;
|
|
|
|
|
2009-12-08 14:26:41 +01:00
|
|
|
// Current project.
|
|
|
|
QString currentProjectPath() const;
|
|
|
|
QString currentProjectName() const;
|
|
|
|
QString currentProjectTopLevel() const;
|
|
|
|
/* Convenience: Returns project path relative to top level if it
|
|
|
|
* differs from top level (else empty()) as an argument list to do
|
|
|
|
* eg a 'vcs diff <args>' */
|
|
|
|
QStringList relativeCurrentProject() const;
|
|
|
|
|
|
|
|
// Top level directory for actions on the top level. Preferably
|
|
|
|
// the file one.
|
|
|
|
QString topLevel() const;
|
|
|
|
|
2013-01-24 12:11:01 +02:00
|
|
|
QString currentDirectoryOrTopLevel() const;
|
2012-01-07 12:31:48 +01:00
|
|
|
bool equals(const VcsBasePluginState &rhs) const;
|
2009-12-08 14:26:41 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
friend VCSBASE_EXPORT QDebug operator<<(QDebug in, const VcsBasePluginState &state);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-12-08 14:26:41 +01:00
|
|
|
private:
|
2012-01-07 12:31:48 +01:00
|
|
|
friend class VcsBasePlugin;
|
2009-12-08 14:26:41 +01:00
|
|
|
bool equals(const Internal::State &s) const;
|
|
|
|
void setState(const Internal::State &s);
|
2009-03-19 17:40:01 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
QSharedDataPointer<VcsBasePluginStateData> data;
|
2009-12-08 14:26:41 +01:00
|
|
|
};
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
VCSBASE_EXPORT QDebug operator<<(QDebug in, const VcsBasePluginState &state);
|
2009-12-08 14:26:41 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
inline bool operator==(const VcsBasePluginState &s1, const VcsBasePluginState &s2)
|
2009-12-08 14:26:41 +01:00
|
|
|
{ return s1.equals(s2); }
|
2012-01-07 12:31:48 +01:00
|
|
|
inline bool operator!=(const VcsBasePluginState &s1, const VcsBasePluginState &s2)
|
2009-12-08 14:26:41 +01:00
|
|
|
{ return !s1.equals(s2); }
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
class VCSBASE_EXPORT VcsBasePlugin : public ExtensionSystem::IPlugin
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2009-12-08 14:26:41 +01:00
|
|
|
protected:
|
2013-03-19 18:35:31 +01:00
|
|
|
explicit VcsBasePlugin(const Core::Id submitEditorId);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-06-04 21:07:34 +02:00
|
|
|
void initializeVcs(Core::IVersionControl *vc);
|
2010-04-26 09:12:58 +02:00
|
|
|
virtual void extensionsInitialized();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
public:
|
2012-01-07 12:31:48 +01:00
|
|
|
virtual ~VcsBasePlugin();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
const VcsBasePluginState ¤tState() const;
|
2009-12-08 16:50:27 +01:00
|
|
|
Core::IVersionControl *versionControl() const;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-15 12:24:06 +01:00
|
|
|
// For internal tests: Create actions driving IVersionControl's snapshot interface.
|
|
|
|
QList<QAction*> createSnapShotTestActions();
|
|
|
|
|
2010-05-19 17:41:14 +02:00
|
|
|
// Convenience that searches for the repository specifically for version control
|
|
|
|
// systems that do not have directories like "CVS" in each managed subdirectory
|
|
|
|
// but have a directory at the top of the repository like ".git" containing
|
|
|
|
// a well known file. See implementation for gory details.
|
|
|
|
static QString findRepositoryForDirectory(const QString &dir, const QString &checkFile);
|
|
|
|
|
2010-05-21 17:46:00 +02:00
|
|
|
// Set up the environment for a version control command line call.
|
2010-06-15 12:17:09 +02:00
|
|
|
// Sets up SSH graphical password prompting (note that the latter
|
|
|
|
// requires a terminal-less process) and sets LANG to 'C' to force English
|
|
|
|
// (suppress LOCALE warnings/parse commands output) if desired.
|
|
|
|
static void setProcessEnvironment(QProcessEnvironment *e, bool forceCLocale);
|
2010-05-21 17:46:00 +02:00
|
|
|
// Returns whether an SSH prompt is configured.
|
|
|
|
static bool isSshPromptConfigured();
|
|
|
|
|
|
|
|
// Convenience to synchronously run VCS commands
|
2012-01-07 12:31:48 +01:00
|
|
|
enum RunVcsFlags {
|
2010-05-21 17:46:00 +02:00
|
|
|
ShowStdOutInLogWindow = 0x1, // Append standard output to VCS output window.
|
|
|
|
MergeOutputChannels = 0x2, // see QProcess: Merge stderr/stdout.
|
2010-06-10 08:38:23 +02:00
|
|
|
SshPasswordPrompt = 0x4, // Disable terminal on UNIX to force graphical prompt.
|
2010-05-21 17:46:00 +02:00
|
|
|
SuppressStdErrInLogWindow = 0x8, // No standard error output to VCS output window.
|
|
|
|
SuppressFailMessageInLogWindow = 0x10, // No message VCS about failure in VCS output window.
|
2010-05-25 11:48:53 +02:00
|
|
|
SuppressCommandLogging = 0x20, // No command log entry in VCS output window.
|
2010-06-15 12:17:09 +02:00
|
|
|
ShowSuccessMessage = 0x40, // Show message about successful completion in VCS output window.
|
2010-11-22 14:53:20 +01:00
|
|
|
ForceCLocale = 0x80, // Force C-locale for commands whose output is parsed.
|
|
|
|
FullySynchronously = 0x100 // Suppress local event loop (in case UI actions are
|
|
|
|
// triggered by file watchers).
|
2010-05-21 17:46:00 +02:00
|
|
|
};
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
static Utils::SynchronousProcessResponse runVcs(const QString &workingDir,
|
2011-10-05 10:35:24 +00:00
|
|
|
const QString &binary,
|
|
|
|
const QStringList &arguments,
|
|
|
|
int timeOutMS,
|
|
|
|
QProcessEnvironment env,
|
|
|
|
unsigned flags = 0,
|
|
|
|
QTextCodec *outputCodec = 0);
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
static Utils::SynchronousProcessResponse runVcs(const QString &workingDir,
|
2011-10-05 10:35:24 +00:00
|
|
|
const QString &binary,
|
|
|
|
const QStringList &arguments,
|
|
|
|
int timeOutMS,
|
|
|
|
unsigned flags = 0,
|
|
|
|
QTextCodec *outputCodec = 0);
|
|
|
|
|
|
|
|
// Make sure to not pass through the event loop at all:
|
|
|
|
static bool runFullySynchronous(const QString &workingDirectory,
|
|
|
|
const QString &binary,
|
|
|
|
const QStringList &arguments,
|
|
|
|
const QProcessEnvironment &env,
|
|
|
|
QByteArray* outputText,
|
|
|
|
QByteArray *errorText, int timeoutMS, bool logCommandToWindow);
|
2010-05-21 17:46:00 +02:00
|
|
|
|
2011-03-24 15:44:39 +01:00
|
|
|
// Utility to run the 'patch' command
|
|
|
|
static bool runPatch(const QByteArray &input, const QString &workingDirectory = QString(),
|
|
|
|
int strip = 0, bool reverse = false);
|
|
|
|
|
2010-01-11 15:22:17 +01:00
|
|
|
public slots:
|
|
|
|
// Convenience slot for "Delete current file" action. Prompts to
|
2012-01-07 12:31:48 +01:00
|
|
|
// delete the file via VcsManager.
|
2010-01-11 15:22:17 +01:00
|
|
|
void promptToDeleteCurrentFile();
|
2010-02-01 12:43:56 +01:00
|
|
|
// Prompt to initialize version control in a directory, initially
|
2010-01-12 16:45:21 +01:00
|
|
|
// pointing to the current project.
|
|
|
|
void createRepository();
|
2010-01-11 15:22:17 +01:00
|
|
|
|
2009-12-08 14:26:41 +01:00
|
|
|
protected:
|
2012-01-07 12:31:48 +01:00
|
|
|
enum ActionState { NoVcsEnabled, OtherVcsEnabled, VcsEnabled };
|
2009-03-19 17:40:01 +01:00
|
|
|
|
2009-12-08 14:26:41 +01:00
|
|
|
// Implement to enable the plugin menu actions according to state.
|
|
|
|
virtual void updateActions(ActionState as) = 0;
|
2010-01-29 22:49:55 +01:00
|
|
|
// Implement to start the submit process.
|
2012-01-07 12:31:48 +01:00
|
|
|
virtual bool submitEditorAboutToClose(VcsBaseSubmitEditor *submitEditor) = 0;
|
2009-03-20 14:20:28 +01:00
|
|
|
|
2009-12-08 14:26:41 +01:00
|
|
|
// A helper to enable the VCS menu action according to state:
|
2012-01-07 12:31:48 +01:00
|
|
|
// NoVcsEnabled -> visible, enabled if repository creation is supported
|
|
|
|
// OtherVcsEnabled -> invisible
|
2010-01-12 16:45:21 +01:00
|
|
|
// Else: -> fully enabled.
|
|
|
|
// Returns whether actions should be set up further.
|
|
|
|
bool enableMenuAction(ActionState as, QAction *in) const;
|
2009-03-20 14:20:28 +01:00
|
|
|
|
|
|
|
private slots:
|
2012-01-07 12:31:48 +01:00
|
|
|
void slotSubmitEditorAboutToClose(VcsBaseSubmitEditor *submitEditor, bool *result);
|
|
|
|
void slotStateChanged(const VcsBase::Internal::State &s, Core::IVersionControl *vc);
|
2010-01-15 12:24:06 +01:00
|
|
|
void slotTestSnapshot();
|
|
|
|
void slotTestListSnapshots();
|
|
|
|
void slotTestRestoreSnapshot();
|
|
|
|
void slotTestRemoveSnapshot();
|
2009-03-20 14:20:28 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
private:
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBasePluginPrivate *d;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
} // namespace VcsBase
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
#endif // VCSBASEPLUGIN_H
|