Commit f7cc04e2 authored by Friedemann Kleint's avatar Friedemann Kleint

Perforce: Use new VCSBasePlugin class.

Use relative paths with -d-option, check for symlinked depots.
Add revert-actions.
Use different context/kinds for editors, suppressing warnings.
Introduce common run-function.
parent 46e61276
......@@ -220,6 +220,16 @@ void SynchronousProcess::setEnvironment(const QStringList &e)
m_d->m_process.setEnvironment(e);
}
void SynchronousProcess::setProcessEnvironment(const QProcessEnvironment &environment)
{
m_d->m_process.setProcessEnvironment(environment);
}
QProcessEnvironment SynchronousProcess::processEnvironment() const
{
return m_d->m_process.processEnvironment();
}
void SynchronousProcess::setWorkingDirectory(const QString &workingDirectory)
{
m_d->m_process.setWorkingDirectory(workingDirectory);
......
......@@ -110,6 +110,9 @@ public:
QStringList environment() const;
void setEnvironment(const QStringList &);
void setProcessEnvironment(const QProcessEnvironment &environment);
QProcessEnvironment processEnvironment() const;
void setWorkingDirectory(const QString &workingDirectory);
QString workingDirectory() const;
......
......@@ -27,12 +27,17 @@
**
**************************************************************************/
#include "command_p.h"
#include "icore.h"
#include "uniqueidmanager.h"
#include <QtCore/QDebug>
#include <QtCore/QTextStream>
#include <QtGui/QAction>
#include <QtGui/QShortcut>
#include "command_p.h"
/*!
\class Core::Command
\mainclass
......@@ -467,6 +472,20 @@ bool OverrideableAction::setCurrentContext(const QList<int> &context)
return false;
}
static inline QString msgActionWarning(QAction *newAction, int k, QAction *oldAction)
{
QString msg;
QTextStream str(&msg);
str << "addOverrideAction " << newAction->objectName() << '/' << newAction->text()
<< ": Action ";
if (oldAction)
str << oldAction->objectName() << '/' << oldAction->text();
str << " is already registered for context " << k << ' '
<< Core::ICore::instance()->uniqueIDManager()->stringForUniqueIdentifier(k)
<< '.';
return msg;
}
void OverrideableAction::addOverrideAction(QAction *action, const QList<int> &context)
{
if (context.isEmpty()) {
......@@ -475,7 +494,7 @@ void OverrideableAction::addOverrideAction(QAction *action, const QList<int> &co
for (int i=0; i<context.size(); ++i) {
int k = context.at(i);
if (m_contextActionMap.contains(k))
qWarning() << QString("addOverrideAction: action already registered for context when registering '%1'").arg(action->text());
qWarning("%s", qPrintable(msgActionWarning(action, k, m_contextActionMap.value(k, 0))));
m_contextActionMap.insert(k, action);
}
}
......
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Perforce::Internal::PendingChangesDialog</class>
<widget class="QDialog" name="Perforce::Internal::PendingChangesDialog" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>333</width>
<height>126</height>
</rect>
</property>
<property name="windowTitle" >
<widget class="QDialog" name="Perforce::Internal::PendingChangesDialog">
<property name="windowTitle">
<string>P4 Pending Changes</string>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>9</number>
</property>
<item>
<widget class="QListWidget" name="listWidget" />
<widget class="QListWidget" name="listWidget"/>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<spacer>
<property name="orientation" >
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>131</width>
<height>31</height>
......@@ -44,15 +37,15 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="submitButton" >
<property name="text" >
<widget class="QPushButton" name="submitButton">
<property name="text">
<string>Submit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton" >
<property name="text" >
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
......@@ -69,11 +62,11 @@
<receiver>Perforce::Internal::PendingChangesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>278</x>
<y>253</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>96</x>
<y>254</y>
</hint>
......@@ -85,11 +78,11 @@
<receiver>Perforce::Internal::PendingChangesDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>369</x>
<y>253</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>179</x>
<y>282</y>
</hint>
......
......@@ -6,6 +6,7 @@ include(perforce_dependencies.pri)
HEADERS += \
perforceplugin.h \
perforcechecker.h \
settingspage.h \
perforceeditor.h \
changenumberdialog.h \
......@@ -18,6 +19,7 @@ HEADERS += \
perforcesubmiteditorwidget.h
SOURCES += perforceplugin.cpp \
perforcechecker.cpp \
settingspage.cpp \
perforceeditor.cpp \
changenumberdialog.cpp \
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "perforcechecker.h"
#include <utils/qtcassert.h>
#include <QtCore/QRegExp>
#include <QtCore/QTimer>
#include <QtCore/QFileInfo>
#include <QtGui/QApplication>
#include <QtGui/QCursor>
namespace Perforce {
namespace Internal {
PerforceChecker::PerforceChecker(QObject *parent) :
QObject(parent),
m_timeOutMS(-1),
m_timedOut(false),
m_useOverideCursor(false),
m_isOverrideCursor(false)
{
connect(&m_process, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(slotError(QProcess::ProcessError)));
connect(&m_process, SIGNAL(finished(int,QProcess::ExitStatus)),
this, SLOT(slotFinished(int,QProcess::ExitStatus)));
}
PerforceChecker::~PerforceChecker()
{
resetOverrideCursor();
}
bool PerforceChecker::isRunning() const
{
return m_process.state() == QProcess::Running;
}
void PerforceChecker::resetOverrideCursor()
{
if (m_isOverrideCursor) {
QApplication::restoreOverrideCursor();
m_isOverrideCursor = false;
}
}
void PerforceChecker::start(const QString &binary,
const QStringList &basicArgs,
int timeoutMS)
{
if (isRunning()) {
emitFailed(QLatin1String("Internal error: process still running"));
return;
}
if (binary.isEmpty()) {
emitFailed(tr("No executable specified"));
return;
}
m_binary = binary;
QStringList args = basicArgs;
args << QLatin1String("client") << QLatin1String("-o");
m_process.start(m_binary, args);
m_process.closeWriteChannel();
// Timeout handling
m_timeOutMS = timeoutMS;
m_timedOut = false;
if (timeoutMS > 0)
QTimer::singleShot(m_timeOutMS, this, SLOT(slotTimeOut()));
// Cursor
if (m_useOverideCursor) {
m_isOverrideCursor = true;
QApplication::setOverrideCursor(QCursor(Qt::BusyCursor));
}
}
bool PerforceChecker::ensureProcessStopped(QProcess &p)
{
if (p.state() != QProcess::Running)
return true;
p.terminate();
if (p.waitForFinished(300))
return true;
p.kill();
return p.waitForFinished(300);
}
void PerforceChecker::slotTimeOut()
{
if (!isRunning())
return;
m_timedOut = true;
ensureProcessStopped(m_process);
emitFailed(tr("\"%1\" timed out after %2ms.").arg(m_binary).arg(m_timeOutMS));
}
void PerforceChecker::slotError(QProcess::ProcessError error)
{
if (m_timedOut)
return;
switch (error) {
case QProcess::FailedToStart:
emitFailed(tr("Unable to launch \"%1\": %2").arg(m_binary, m_process.errorString()));
break;
case QProcess::Crashed: // Handled elsewhere
case QProcess::Timedout:
break;
case QProcess::ReadError:
case QProcess::WriteError:
case QProcess::UnknownError:
ensureProcessStopped(m_process);
break;
}
}
void PerforceChecker::slotFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
if (m_timedOut)
return;
switch (exitStatus) {
case QProcess::CrashExit:
emitFailed(tr("\"%1\" crashed.").arg(m_binary));
break;
case QProcess::NormalExit:
if (exitCode) {
const QString stdErr = QString::fromLocal8Bit(m_process.readAllStandardError());
emitFailed(tr("\"%1\" terminated with exit code %2: %3").arg(m_binary).arg(exitCode).arg(stdErr));
} else {
parseOutput(QString::fromLocal8Bit(m_process.readAllStandardOutput()));
}
break;
}
}
// Parse p4 client output for the top level
static inline QString clientRootFromOutput(const QString &in)
{
QRegExp regExp(QLatin1String("(\\n|\\r\\n|\\r)Root:\\s*(.*)(\\n|\\r\\n|\\r)"));
QTC_ASSERT(regExp.isValid(), return QString());
regExp.setMinimal(true);
if (regExp.indexIn(in) != -1)
return regExp.cap(2).trimmed();
return QString();
}
void PerforceChecker::parseOutput(const QString &response)
{
if (!response.contains(QLatin1String("View:")) && !response.contains(QLatin1String("//depot/"))) {
emitFailed(tr("The client does not seem to contain any mapped files."));
return;
}
const QString repositoryRoot = clientRootFromOutput(response);
if (repositoryRoot.isEmpty()) {
emitFailed(tr("Unable to determine the client root."));
return;
}
// Check existence. No precise check here, might be a symlink
const QFileInfo fi(repositoryRoot);
if (fi.exists()) {
emitSucceeded(repositoryRoot);
} else {
emitFailed(tr("The repository \"%1\" does not exist.").arg(repositoryRoot));
}
}
void PerforceChecker::emitFailed(const QString &m)
{
resetOverrideCursor();
emit failed(m);
}
void PerforceChecker::emitSucceeded(const QString &m)
{
resetOverrideCursor();
emit succeeded(m);
}
bool PerforceChecker::useOverideCursor() const
{
return m_useOverideCursor;
}
void PerforceChecker::setUseOverideCursor(bool v)
{
m_useOverideCursor = v;
}
}
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef PERFORCECHECKER_H
#define PERFORCECHECKER_H
#include <QtCore/QObject>
#include <QtCore/QProcess>
namespace Perforce {
namespace Internal {
// Perforce checker: Calls perforce asynchronously to do
// a check of the configuration and emits signals with the top level or
// an error message.
class PerforceChecker : public QObject
{
Q_OBJECT
public:
explicit PerforceChecker(QObject *parent = 0);
virtual ~PerforceChecker();
public slots:
void start(const QString &binary,
const QStringList &basicArgs = QStringList(),
int timeoutMS = -1);
bool isRunning() const;
bool useOverideCursor() const;
void setUseOverideCursor(bool v);
static bool ensureProcessStopped(QProcess &p);
signals:
void succeeded(const QString &repositoryRoot);
void failed(const QString &errorMessage);
private slots:
void slotError(QProcess::ProcessError error);
void slotFinished(int exitCode, QProcess::ExitStatus exitStatus);
void slotTimeOut();
private:
void emitFailed(const QString &);
void emitSucceeded(const QString &);
void parseOutput(const QString &);
inline void resetOverrideCursor();
QProcess m_process;
QString m_binary;
int m_timeOutMS;
bool m_timedOut;
bool m_useOverideCursor;
bool m_isOverrideCursor;
};
}
}
#endif // PERFORCECHECKER_H
......@@ -33,11 +33,24 @@
namespace Perforce {
namespace Constants {
const char * const C_PERFORCEEDITOR = "Perforce Editor";
const char * const PERFORCEEDITOR_CONTEXT = "Perforce Editor";
const char * const PERFORCE_SUBMIT_EDITOR_KIND = "Perforce Submit Editor";
const char * const PERFORCESUBMITEDITOR_CONTEXT = "Perforce Submit Editor";
const char * const PERFORCE_COMMANDLOG_EDITOR_KIND = "Perforce Command Log Editor";
const char * const PERFORCE_COMMANDLOG_EDITOR_CONTEXT = "Perforce Command Log Editor";
const char * const PERFORCE_LOG_EDITOR_KIND = "Perforce Log Editor";
const char * const PERFORCE_LOG_EDITOR_CONTEXT = "Perforce Log Editor";
const char * const PERFORCE_DIFF_EDITOR_KIND = "Perforce Diff Editor";
const char * const PERFORCE_DIFF_EDITOR_CONTEXT = "Perforce Diff Editor";
const char * const PERFORCE_ANNOTATION_EDITOR_KIND = "Perforce Annotation Editor";
const char * const PERFORCE_ANNOTATION_EDITOR_CONTEXT = "Perforce Annotation Editor";
const char * const PERFORCEEDITOR_KIND = "Perforce Editor";
const char * const C_PERFORCESUBMITEDITOR = "Perforce Submit Editor";
const char * const PERFORCESUBMITEDITOR_KIND = "Perforce Submit Editor";
const char * const SUBMIT_CURRENT = "Perforce.SubmitCurrentLog";
const char * const DIFF_SELECTED = "Perforce.DiffSelectedFilesInLog";
const char * const SUBMIT_MIMETYPE = "application/vnd.nokia.text.p4.submit";
......
This diff is collapsed.
......@@ -35,16 +35,18 @@
#include <coreplugin/editormanager/ieditorfactory.h>
#include <coreplugin/iversioncontrol.h>
#include <vcsbase/vcsbaseplugin.h>
#include <projectexplorer/projectexplorer.h>
#include <QtCore/QObject>
#include <QtCore/QProcess>
#include <QtCore/QStringList>
#include <QtCore/QSharedPointer>
#include <QtCore/QHash>
QT_BEGIN_NAMESPACE
class QFile;
class QAction;
class QTextCodec;
class QTemporaryFile;
QT_END_NAMESPACE
namespace Utils {
......@@ -58,7 +60,10 @@ class PerforceVersionControl;
struct PerforceResponse
{
PerforceResponse();
bool error;
int exitCode;
QString stdOut;
QString stdErr;
QString message;
......@@ -75,13 +80,13 @@ public:
bool initialize(const QStringList &arguments, QString *error_message);
void extensionsInitialized();
bool managesDirectory(const QString &directory) const;
QString findTopLevelForDirectory(const QString &directory) const;
bool vcsOpen(const QString &fileName);
bool vcsAdd(const QString &fileName);
bool vcsDelete(const QString &filename);
bool managesDirectory(const QString &directory);
QString findTopLevelForDirectory(const QString &directory);
bool vcsOpen(const QString &workingDir, const QString &fileName);
bool vcsAdd(const QString &workingDir, const QString &fileName);
bool vcsDelete(const QString &workingDir, const QString &filename);
void p4Diff(const QStringList &files, QString diffname = QString());
void p4Diff(const QString &workingDir, const QStringList &files);
Core::IEditor *openPerforceSubmitEditor(const QString &fileName, const QStringList &depotFileNames);
......@@ -105,9 +110,11 @@ private slots:
void diffCurrentFile();
void diffCurrentProject();
void updateCurrentProject();
void revertCurrentProject();
void revertUnchangedCurrentProject();
void updateAll();
void diffAllOpened();
void submit();
void startSubmitProject();
void describeChange();
void annotateCurrentFile();
void annotate();
......@@ -116,55 +123,80 @@ private slots:
void submitCurrentLog();
void printPendingChanges();
void slotDiff(const QStringList &files);
void slotSubmitDiff(const QStringList &files);
void slotTopLevelFound(const QString &);
void slotTopLevelFailed(const QString &);