Skip to content
Snippets Groups Projects
perforceplugin.cpp 62 KiB
Newer Older
/**************************************************************************
con's avatar
con committed
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
**
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
**
** 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
hjk's avatar
hjk committed
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
**
**************************************************************************/
hjk's avatar
hjk committed

con's avatar
con committed
#include "perforceplugin.h"
con's avatar
con committed
#include "changenumberdialog.h"
hjk's avatar
hjk committed
#include "pendingchangesdialog.h"
con's avatar
con committed
#include "perforceconstants.h"
#include "perforceeditor.h"
hjk's avatar
hjk committed
#include "perforcesubmiteditor.h"
#include "perforceversioncontrol.h"
#include "perforcechecker.h"
hjk's avatar
hjk committed
#include "settingspage.h"
con's avatar
con committed

#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
con's avatar
con committed
#include <coreplugin/coreconstants.h>
hjk's avatar
hjk committed
#include <coreplugin/editormanager/editormanager.h>
con's avatar
con committed
#include <coreplugin/filemanager.h>
hjk's avatar
hjk committed
#include <coreplugin/icore.h>
con's avatar
con committed
#include <coreplugin/messagemanager.h>
hjk's avatar
hjk committed
#include <coreplugin/mimedatabase.h>
Friedemann Kleint's avatar
Friedemann Kleint committed
#include <locator/commandlocator.h>
hjk's avatar
hjk committed
#include <utils/qtcassert.h>
con's avatar
con committed
#include <utils/synchronousprocess.h>
#include <utils/parameteraction.h>
con's avatar
con committed
#include <vcsbase/basevcseditorfactory.h>
#include <vcsbase/basevcssubmiteditorfactory.h>
#include <vcsbase/vcsbaseeditor.h>
#include <vcsbase/vcsbaseoutputwindow.h>
con's avatar
con committed

hjk's avatar
hjk committed
#include <QtCore/QtPlugin>
con's avatar
con committed
#include <QtCore/QDebug>
#include <QtCore/QDir>
hjk's avatar
hjk committed
#include <QtCore/QFileInfo>
con's avatar
con committed
#include <QtCore/QSettings>
hjk's avatar
hjk committed
#include <QtCore/QTemporaryFile>
con's avatar
con committed
#include <QtCore/QTextCodec>
con's avatar
con committed
#include <QtGui/QAction>
hjk's avatar
hjk committed
#include <QtGui/QFileDialog>
#include <QtGui/QMainWindow>
con's avatar
con committed
#include <QtGui/QMenu>
#include <QtGui/QMessageBox>

static const VCSBase::VCSBaseEditorParameters editorParameters[] = {
{
    VCSBase::RegularCommandOutput,
    Perforce::Constants::PERFORCE_COMMANDLOG_EDITOR_ID,
    Perforce::Constants::PERFORCE_COMMANDLOG_EDITOR_DISPLAY_NAME,
    Perforce::Constants::PERFORCE_COMMANDLOG_EDITOR_CONTEXT,
con's avatar
con committed
    "application/vnd.nokia.text.scs_commandlog",
    "scslog"},
{   VCSBase::LogOutput,
    Perforce::Constants::PERFORCE_LOG_EDITOR_ID,
    Perforce::Constants::PERFORCE_LOG_EDITOR_DISPLAY_NAME,
    Perforce::Constants::PERFORCE_LOG_EDITOR_CONTEXT,
con's avatar
con committed
    "application/vnd.nokia.text.scs_filelog",
    "scsfilelog"},
{    VCSBase::AnnotateOutput,
     Perforce::Constants::PERFORCE_ANNOTATION_EDITOR_ID,
     Perforce::Constants::PERFORCE_ANNOTATION_EDITOR_DISPLAY_NAME,
     Perforce::Constants::PERFORCE_ANNOTATION_EDITOR_CONTEXT,
con's avatar
con committed
    "application/vnd.nokia.text.scs_annotation",
    "scsannotate"},
{   VCSBase::DiffOutput,
    Perforce::Constants::PERFORCE_DIFF_EDITOR_ID,
    Perforce::Constants::PERFORCE_DIFF_EDITOR_DISPLAY_NAME,
    Perforce::Constants::PERFORCE_DIFF_EDITOR_CONTEXT,
con's avatar
con committed
    "text/x-patch","diff"}
};

// Utility to find a parameter set by type
static inline const VCSBase::VCSBaseEditorParameters *findType(int ie)
{
    const VCSBase::EditorContentType et = static_cast<VCSBase::EditorContentType>(ie);
    return  VCSBase::VCSBaseEditor::findType(editorParameters, sizeof(editorParameters)/sizeof(VCSBase::VCSBaseEditorParameters), et);
}

static inline QString debugCodec(const QTextCodec *c)
{
    return c ? QString::fromAscii(c->name()) : QString::fromAscii("Null codec");
}

// Ensure adding "..." to relative paths which is p4's convention
// for the current directory
static inline QStringList perforceRelativeFileArguments(const QStringList &args)
{
    if (args.isEmpty())
        return QStringList(QLatin1String("..."));
    QTC_ASSERT(args.size() == 1, return QStringList())
    QStringList p4Args = args;
    p4Args.front() += QLatin1String("/...");
    return p4Args;
}

static inline QStringList perforceRelativeProjectDirectory(const VCSBase::VCSBasePluginState &s)
{
    return perforceRelativeFileArguments(s.relativeCurrentProject());
}

// Clean user setting off diff-binary for 'p4 resolve' and 'p4 diff'.
static inline QProcessEnvironment overrideDiffEnvironmentVariable()
{
    QProcessEnvironment rc = QProcessEnvironment::systemEnvironment();
    rc.remove(QLatin1String("P4DIFF"));
    return rc;
static const char * const CMD_ID_PERFORCE_MENU = "Perforce.Menu";
static const char * const CMD_ID_EDIT = "Perforce.Edit";
static const char * const CMD_ID_ADD = "Perforce.Add";
static const char * const CMD_ID_DELETE_FILE = "Perforce.Delete";
static const char * const CMD_ID_OPENED = "Perforce.Opened";
static const char * const CMD_ID_PROJECTLOG = "Perforce.ProjectLog";
static const char * const CMD_ID_REPOSITORYLOG = "Perforce.RepositoryLog";
static const char * const CMD_ID_REVERT = "Perforce.Revert";
static const char * const CMD_ID_DIFF_CURRENT = "Perforce.DiffCurrent";
static const char * const CMD_ID_DIFF_PROJECT = "Perforce.DiffProject";
static const char * const CMD_ID_UPDATE_PROJECT = "Perforce.UpdateProject";
static const char * const CMD_ID_REVERT_PROJECT = "Perforce.RevertProject";
static const char * const CMD_ID_REVERT_UNCHANGED_PROJECT = "Perforce.RevertUnchangedProject";
static const char * const CMD_ID_DIFF_ALL = "Perforce.DiffAll";
static const char * const CMD_ID_RESOLVE = "Perforce.Resolve";
static const char * const CMD_ID_SUBMIT = "Perforce.Submit";
static const char * const CMD_ID_PENDING_CHANGES = "Perforce.PendingChanges";
static const char * const CMD_ID_DESCRIBE = "Perforce.Describe";
static const char * const CMD_ID_ANNOTATE_CURRENT = "Perforce.AnnotateCurrent";
static const char * const CMD_ID_ANNOTATE = "Perforce.Annotate";
static const char * const CMD_ID_FILELOG_CURRENT = "Perforce.FilelogCurrent";
static const char * const CMD_ID_FILELOG = "Perforce.Filelog";
static const char * const CMD_ID_UPDATEALL = "Perforce.UpdateAll";
static const char * const CMD_ID_SEPARATOR1 = "Perforce.Separator1";
static const char * const CMD_ID_SEPARATOR2 = "Perforce.Separator2";
static const char * const CMD_ID_SEPARATOR3 = "Perforce.Separator3";
con's avatar
con committed

////
// PerforcePlugin
////

namespace Perforce {
namespace Internal {

PerforceResponse::PerforceResponse() :
    error(true),
    exitCode(-1)
{
}

con's avatar
con committed
PerforcePlugin *PerforcePlugin::m_perforcePluginInstance = NULL;

PerforcePlugin::PerforcePlugin() :
    VCSBase::VCSBasePlugin(QLatin1String(Constants::PERFORCE_SUBMIT_EDITOR_ID)),
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator(0),
con's avatar
con committed
    m_editAction(0),
    m_addAction(0),
    m_deleteAction(0),
    m_openedAction(0),
    m_revertFileAction(0),
    m_diffFileAction(0),
con's avatar
con committed
    m_diffProjectAction(0),
    m_updateProjectAction(0),
    m_revertProjectAction(0),
    m_revertUnchangedAction(0),
con's avatar
con committed
    m_diffAllAction(0),
    m_submitProjectAction(0),
con's avatar
con committed
    m_pendingAction(0),
    m_describeAction(0),
    m_annotateCurrentAction(0),
    m_annotateAction(0),
    m_filelogCurrentAction(0),
    m_filelogAction(0),
    m_logProjectAction(0),
    m_logRepositoryAction(0),
    m_submitCurrentLogAction(0),
    m_submitActionTriggered(false),
    m_diffSelectedFiles(0),
    m_undoAction(0),
con's avatar
con committed
{
}

static const VCSBase::VCSBaseSubmitEditorParameters submitParameters = {
    Perforce::Constants::SUBMIT_MIMETYPE,
    Perforce::Constants::PERFORCE_SUBMIT_EDITOR_ID,
    Perforce::Constants::PERFORCE_SUBMIT_EDITOR_DISPLAY_NAME,
    Perforce::Constants::PERFORCESUBMITEDITOR_CONTEXT
con's avatar
con committed
};

static inline Core::Command *createSeparator(QObject *parent,
                                             Core::ActionManager *ami,
                                             const char *id,
                                             const Core::Context &globalcontext)
{
    QAction *tmpaction = new QAction(parent);
    tmpaction->setSeparator(true);
    return ami->registerAction(tmpaction, id, globalcontext);
}

bool PerforcePlugin::initialize(const QStringList & /* arguments */, QString *errorMessage)
con's avatar
con committed
{
    typedef VCSBase::VCSEditorFactory<PerforceEditor> PerforceEditorFactory;
    typedef VCSBase::VCSSubmitEditorFactory<PerforceSubmitEditor> PerforceSubmitEditorFactory;

    VCSBase::VCSBasePlugin::initialize(new PerforceVersionControl(this));

    Core::ICore *core = Core::ICore::instance();
    if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/trolltech.perforce/Perforce.mimetypes.xml"), errorMessage))
con's avatar
con committed
        return false;
    m_perforcePluginInstance = this;

    if (QSettings *settings = core->settings())
con's avatar
con committed
        m_settings.fromSettings(settings);

    addAutoReleasedObject(new SettingsPage);
con's avatar
con committed

    // Editor factories
    addAutoReleasedObject(new PerforceSubmitEditorFactory(&submitParameters));
con's avatar
con committed

    static const char *describeSlot = SLOT(describe(QString,QString));
    const int editorCount = sizeof(editorParameters)/sizeof(VCSBase::VCSBaseEditorParameters);
    for (int i = 0; i < editorCount; i++)
        addAutoReleasedObject(new PerforceEditorFactory(editorParameters + i, this, describeSlot));
con's avatar
con committed

Friedemann Kleint's avatar
Friedemann Kleint committed
    const QString prefix = QLatin1String("p4");
    m_commandLocator = new Locator::CommandLocator(QLatin1String("Perforce"), prefix, prefix);
    addAutoReleasedObject(m_commandLocator);

con's avatar
con committed
    //register actions
    Core::ActionManager *am = Core::ICore::instance()->actionManager();
con's avatar
con committed

    Core::ActionContainer *mtools =
con's avatar
con committed
        am->actionContainer(Core::Constants::M_TOOLS);

    Core::ActionContainer *mperforce =
        am->createMenu(Core::Id(CMD_ID_PERFORCE_MENU));
con's avatar
con committed
    mperforce->menu()->setTitle(tr("&Perforce"));
    mtools->addMenu(mperforce);
    m_menuAction = mperforce->menu()->menuAction();
con's avatar
con committed

    Core::Context globalcontext(Core::Constants::C_GLOBAL);
    Core::Context perforcesubmitcontext(Constants::PERFORCESUBMITEDITOR_CONTEXT);
con's avatar
con committed

con's avatar
con committed
    Core::Command *command;

    m_diffFileAction = new Utils::ParameterAction(tr("Diff Current File"), tr("Diff \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = am->registerAction(m_diffFileAction, CMD_ID_DIFF_CURRENT, globalcontext);
    command->setAttribute(Core::Command::CA_UpdateText);
    command->setDefaultText(tr("Diff Current File"));
    connect(m_diffFileAction, SIGNAL(triggered()), this, SLOT(diffCurrentFile()));
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);

    m_annotateCurrentAction = new Utils::ParameterAction(tr("Annotate Current File"), tr("Annotate \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = am->registerAction(m_annotateCurrentAction, CMD_ID_ANNOTATE_CURRENT, globalcontext);
    command->setAttribute(Core::Command::CA_UpdateText);
    command->setDefaultText(tr("Annotate Current File"));
    connect(m_annotateCurrentAction, SIGNAL(triggered()), this, SLOT(annotateCurrentFile()));
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);

    m_filelogCurrentAction = new Utils::ParameterAction(tr("Filelog Current File"), tr("Filelog \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = am->registerAction(m_filelogCurrentAction, CMD_ID_FILELOG_CURRENT, globalcontext);
    command->setAttribute(Core::Command::CA_UpdateText);
    command->setDefaultKeySequence(QKeySequence(tr("Alt+P,Alt+F")));
    command->setDefaultText(tr("Filelog Current File"));
    connect(m_filelogCurrentAction, SIGNAL(triggered()), this, SLOT(filelogCurrentFile()));
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);

    mperforce->addAction(createSeparator(this, am, "Perforce.Sep.Edit", globalcontext));
con's avatar
con committed

    m_editAction = new Utils::ParameterAction(tr("Edit"), tr("Edit \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = am->registerAction(m_editAction, CMD_ID_EDIT, globalcontext);
con's avatar
con committed
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
    command->setDefaultKeySequence(QKeySequence(tr("Alt+P,Alt+E")));
    command->setDefaultText(tr("Edit File"));
    connect(m_editAction, SIGNAL(triggered()), this, SLOT(openCurrentFile()));
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);
con's avatar
con committed

    m_addAction = new Utils::ParameterAction(tr("Add"), tr("Add \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = am->registerAction(m_addAction, CMD_ID_ADD, globalcontext);
con's avatar
con committed
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
    command->setDefaultKeySequence(QKeySequence(tr("Alt+P,Alt+A")));
    command->setDefaultText(tr("Add File"));
    connect(m_addAction, SIGNAL(triggered()), this, SLOT(addCurrentFile()));
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);
con's avatar
con committed

    m_deleteAction = new Utils::ParameterAction(tr("Delete..."), tr("Delete \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
    command = am->registerAction(m_deleteAction, CMD_ID_DELETE_FILE, globalcontext);
con's avatar
con committed
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
    command->setDefaultText(tr("Delete File"));
    connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(promptToDeleteCurrentFile()));
con's avatar
con committed
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);
con's avatar
con committed

    m_revertFileAction = new Utils::ParameterAction(tr("Revert"), tr("Revert \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = am->registerAction(m_revertFileAction, CMD_ID_REVERT, globalcontext);
con's avatar
con committed
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
    command->setDefaultKeySequence(QKeySequence(tr("Alt+P,Alt+R")));
    command->setDefaultText(tr("Revert File"));
    connect(m_revertFileAction, SIGNAL(triggered()), this, SLOT(revertCurrentFile()));
con's avatar
con committed
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);
con's avatar
con committed

    mperforce->addAction(createSeparator(this, am, "Perforce.Sep.Project", globalcontext));
con's avatar
con committed

    const QString diffProjectDefaultText = tr("Diff Current Project/Session");
    m_diffProjectAction = new Utils::ParameterAction(diffProjectDefaultText, tr("Diff Project \"%1\""), Utils::ParameterAction::AlwaysEnabled, this);
    command = am->registerAction(m_diffProjectAction, CMD_ID_DIFF_PROJECT, globalcontext);
con's avatar
con committed
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
    command->setDefaultKeySequence(QKeySequence(tr("Alt+P,Alt+D")));
    command->setDefaultText(diffProjectDefaultText);
con's avatar
con committed
    connect(m_diffProjectAction, SIGNAL(triggered()), this, SLOT(diffCurrentProject()));
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);
con's avatar
con committed

Friedemann Kleint's avatar
Friedemann Kleint committed
    m_logProjectAction = new Utils::ParameterAction(tr("Log Project"), tr("Log Project \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = am->registerAction(m_logProjectAction, CMD_ID_PROJECTLOG, globalcontext);
    command->setAttribute(Core::Command::CA_UpdateText);
    connect(m_logProjectAction, SIGNAL(triggered()), this, SLOT(logProject()));
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);
    m_submitProjectAction = new Utils::ParameterAction(tr("Submit Project"), tr("Submit Project \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = am->registerAction(m_submitProjectAction, CMD_ID_SUBMIT, globalcontext);
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
    command->setDefaultKeySequence(QKeySequence(tr("Alt+P,Alt+S")));
    connect(m_submitProjectAction, SIGNAL(triggered()), this, SLOT(startSubmitProject()));
con's avatar
con committed
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);
con's avatar
con committed

    const QString updateProjectDefaultText = tr("Update Current Project");
    m_updateProjectAction = new Utils::ParameterAction(updateProjectDefaultText, tr("Update Project \"%1\""), Utils::ParameterAction::AlwaysEnabled, this);
    command = am->registerAction(m_updateProjectAction, CMD_ID_UPDATE_PROJECT, globalcontext);
    command->setDefaultText(updateProjectDefaultText);
    command->setAttribute(Core::Command::CA_UpdateText);
    connect(m_updateProjectAction, SIGNAL(triggered()), this, SLOT(updateCurrentProject()));
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);
    m_revertUnchangedAction = new Utils::ParameterAction(tr("Revert Unchanged"), tr("Revert Unchanged Files of Project \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = am->registerAction(m_revertUnchangedAction, CMD_ID_REVERT_UNCHANGED_PROJECT, globalcontext);
    command->setAttribute(Core::Command::CA_UpdateText);
    connect(m_revertUnchangedAction, SIGNAL(triggered()), this, SLOT(revertUnchangedCurrentProject()));
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);
    m_revertProjectAction = new Utils::ParameterAction(tr("Revert Project"), tr("Revert Project \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = am->registerAction(m_revertProjectAction, CMD_ID_REVERT_PROJECT, globalcontext);
    command->setAttribute(Core::Command::CA_UpdateText);
    connect(m_revertProjectAction, SIGNAL(triggered()), this, SLOT(revertCurrentProject()));
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);
    mperforce->addAction(createSeparator(this, am, "Perforce.Sep.Repository", globalcontext));

    m_diffAllAction = new QAction(tr("Diff Opened Files"), this);
    command = am->registerAction(m_diffAllAction, CMD_ID_DIFF_ALL, globalcontext);
    connect(m_diffAllAction, SIGNAL(triggered()), this, SLOT(diffAllOpened()));
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);
    m_openedAction = new QAction(tr("Opened"), this);
    command = am->registerAction(m_openedAction, CMD_ID_OPENED, globalcontext);
    command->setDefaultKeySequence(QKeySequence(tr("Alt+P,Alt+O")));
    connect(m_openedAction, SIGNAL(triggered()), this, SLOT(printOpenedFileList()));
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);

    m_logRepositoryAction = new QAction(tr("Repository Log"), this);
    command = am->registerAction(m_logRepositoryAction, CMD_ID_REPOSITORYLOG, globalcontext);
    connect(m_logRepositoryAction, SIGNAL(triggered()), this, SLOT(logRepository()));
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);

    m_pendingAction = new QAction(tr("Pending Changes..."), this);
    command = am->registerAction(m_pendingAction, CMD_ID_PENDING_CHANGES, globalcontext);
    connect(m_pendingAction, SIGNAL(triggered()), this, SLOT(printPendingChanges()));
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);

    m_updateAllAction = new QAction(tr("Update All"), this);
    command = am->registerAction(m_updateAllAction, CMD_ID_UPDATEALL, globalcontext);
    connect(m_updateAllAction, SIGNAL(triggered()), this, SLOT(updateAll()));
con's avatar
con committed
    mperforce->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
    m_commandLocator->appendCommand(command);
con's avatar
con committed

    mperforce->addAction(createSeparator(this, am, "Perforce.Sep.Dialogs", globalcontext));

con's avatar
con committed
    m_describeAction = new QAction(tr("Describe..."), this);
    command = am->registerAction(m_describeAction, CMD_ID_DESCRIBE, globalcontext);
con's avatar
con committed
    connect(m_describeAction, SIGNAL(triggered()), this, SLOT(describeChange()));
    mperforce->addAction(command);

    m_annotateAction = new QAction(tr("Annotate..."), this);
    command = am->registerAction(m_annotateAction, CMD_ID_ANNOTATE, globalcontext);
con's avatar
con committed
    connect(m_annotateAction, SIGNAL(triggered()), this, SLOT(annotate()));
    mperforce->addAction(command);

    m_filelogAction = new QAction(tr("Filelog..."), this);
    command = am->registerAction(m_filelogAction, CMD_ID_FILELOG, globalcontext);
con's avatar
con committed
    connect(m_filelogAction, SIGNAL(triggered()), this, SLOT(filelog()));
    mperforce->addAction(command);

    m_submitCurrentLogAction = new QAction(VCSBase::VCSBaseSubmitEditor::submitIcon(), tr("Submit"), this);
con's avatar
con committed
    command = am->registerAction(m_submitCurrentLogAction, Constants::SUBMIT_CURRENT, perforcesubmitcontext);
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
    connect(m_submitCurrentLogAction, SIGNAL(triggered()), this, SLOT(submitCurrentLog()));

    m_diffSelectedFiles = new QAction(VCSBase::VCSBaseSubmitEditor::diffIcon(), tr("Diff Selected Files"), this);
con's avatar
con committed
    command = am->registerAction(m_diffSelectedFiles, Constants::DIFF_SELECTED, perforcesubmitcontext);

    m_undoAction = new QAction(tr("&Undo"), this);
    command = am->registerAction(m_undoAction, Core::Constants::UNDO, perforcesubmitcontext);

    m_redoAction = new QAction(tr("&Redo"), this);
    command = am->registerAction(m_redoAction, Core::Constants::REDO, perforcesubmitcontext);

    return true;
}

void PerforcePlugin::extensionsInitialized()
{
    VCSBase::VCSBasePlugin::extensionsInitialized();
con's avatar
con committed
}

void PerforcePlugin::openCurrentFile()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
    vcsOpen(state.currentFileTopLevel(), state.relativeCurrentFile());
con's avatar
con committed
}

void PerforcePlugin::addCurrentFile()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
    vcsAdd(state.currentFileTopLevel(), state.relativeCurrentFile());
con's avatar
con committed
}

void PerforcePlugin::revertCurrentFile()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)

    QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(state.currentFile());
con's avatar
con committed
    QStringList args;
    args << QLatin1String("diff") << QLatin1String("-sa") << state.relativeCurrentFile();
    PerforceResponse result = runP4Cmd(state.currentFileTopLevel(), args,
                                       RunFullySynchronous|CommandToWindow|StdErrToWindow|ErrorToWindow,
                                       QStringList(), QByteArray(), codec);
con's avatar
con committed
    if (result.error)
        return;
    // "foo.cpp - file(s) not opened on this client."
    if (result.stdOut.isEmpty() || result.stdOut.contains(QLatin1String(" - ")))
        return;
con's avatar
con committed

    const bool doNotRevert = QMessageBox::warning(0, tr("p4 revert"),
                             tr("The file has been changed. Do you want to revert it?"),
                             QMessageBox::Yes, QMessageBox::No) == QMessageBox::No;
    if (doNotRevert)
        return;
con's avatar
con committed

    Core::FileChangeBlocker fcb(state.currentFile());
    args.clear();
    args << QLatin1String("revert") << state.relativeCurrentFile();
    PerforceResponse result2 = runP4Cmd(state.currentFileTopLevel(), args,
                                        CommandToWindow|StdOutToWindow|StdErrToWindow|ErrorToWindow);
        perforceVersionControl()->emitFilesChanged(QStringList(state.currentFile()));
con's avatar
con committed
}

void PerforcePlugin::diffCurrentFile()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
    p4Diff(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
con's avatar
con committed
}

void PerforcePlugin::diffCurrentProject()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return)
    p4Diff(state.currentProjectTopLevel(), perforceRelativeProjectDirectory(state));
con's avatar
con committed
}

void PerforcePlugin::diffAllOpened()
{
    p4Diff(m_settings.topLevel(), QStringList());
con's avatar
con committed
}

void PerforcePlugin::updateCurrentProject()
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return)
    updateCheckout(state.currentProjectTopLevel(), perforceRelativeProjectDirectory(state));
void PerforcePlugin::updateAll()
{
    updateCheckout(m_settings.topLevel());
}

void PerforcePlugin::revertCurrentProject()
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return)

    const QString msg = tr("Do you want to revert all changes to the project \"%1\"?").arg(state.currentProjectName());
    if (QMessageBox::warning(0, tr("p4 revert"), msg, QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
    revertProject(state.currentProjectTopLevel(), perforceRelativeProjectDirectory(state), false);
void PerforcePlugin::revertUnchangedCurrentProject()
    // revert -a.
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return)
    revertProject(state.currentProjectTopLevel(), perforceRelativeProjectDirectory(state), true);
bool PerforcePlugin::revertProject(const QString &workingDir, const QStringList &pathArgs, bool unchangedOnly)
{
    QStringList args(QLatin1String("revert"));
    if (unchangedOnly)
        args.push_back(QLatin1String("-a"));
    args.append(pathArgs);
    const PerforceResponse resp = runP4Cmd(workingDir, args,
                                           RunFullySynchronous|CommandToWindow|StdOutToWindow|StdErrToWindow|ErrorToWindow);
    return !resp.error;
}

void PerforcePlugin::updateCheckout(const QString &workingDir, const QStringList &dirs)
{
    QStringList args(QLatin1String("sync"));
    args.append(dirs);
    const PerforceResponse resp = runP4Cmd(workingDir, args,
                                           CommandToWindow|StdOutToWindow|StdErrToWindow|ErrorToWindow);
    if (dirs.empty()) {
        if (!workingDir.isEmpty())
            perforceVersionControl()->emitRepositoryChanged(workingDir);
    } else {
        const QChar slash = QLatin1Char('/');
        foreach(const QString &dir, dirs)
            perforceVersionControl()->emitRepositoryChanged(workingDir + slash + dir);
    }
con's avatar
con committed
void PerforcePlugin::printOpenedFileList()
{
    const PerforceResponse perforceResponse
            = runP4Cmd(m_settings.topLevel(), QStringList(QLatin1String("opened")),
                       CommandToWindow|StdErrToWindow|ErrorToWindow);
    if (perforceResponse.error || perforceResponse.stdOut.isEmpty())
        return;
    // reformat "//depot/file.cpp#1 - description" into "file.cpp # - description"
    // for context menu opening to work. This produces absolute paths, then.
    VCSBase::VCSBaseOutputWindow *outWin = VCSBase::VCSBaseOutputWindow::instance();
    QString errorMessage;
    QString mapped;
    const QChar delimiter = QLatin1Char('#');
    foreach (const QString &line, perforceResponse.stdOut.split(QLatin1Char('\n'))) {
        mapped.clear();
        const int delimiterPos = line.indexOf(delimiter);
        if (delimiterPos > 0)
            mapped = fileNameFromPerforceName(line.left(delimiterPos), true, &errorMessage);
        if (mapped.isEmpty()) {
            outWin->appendSilently(line);
        } else {
            outWin->appendSilently(mapped + QLatin1Char(' ') + line.mid(delimiterPos));
        }
    }
    outWin->popup();
con's avatar
con committed
}

void PerforcePlugin::startSubmitProject()
con's avatar
con committed
{
    if (VCSBase::VCSBaseSubmitEditor::raiseSubmitEditor())
con's avatar
con committed
        return;

        VCSBase::VCSBaseOutputWindow::instance()->appendWarning(tr("Another submit is currently executed."));
con's avatar
con committed
        return;
    }

    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return)

    QTemporaryFile changeTmpFile;
    changeTmpFile.setAutoRemove(false);
    if (!changeTmpFile.open()) {
        VCSBase::VCSBaseOutputWindow::instance()->appendError(tr("Cannot create temporary file."));
con's avatar
con committed
        return;
    }
    // Revert all unchanged files.
    if (!revertProject(state.currentProjectTopLevel(), perforceRelativeProjectDirectory(state), true))
        return;
    // Start a change
    QStringList args;
con's avatar
con committed

    args << QLatin1String("change") << QLatin1String("-o");
    PerforceResponse result = runP4Cmd(state.currentProjectTopLevel(), args,
                                       RunFullySynchronous|CommandToWindow|StdErrToWindow|ErrorToWindow);
con's avatar
con committed
    if (result.error) {
con's avatar
con committed
        return;
    }

    m_commitMessageFileName = changeTmpFile.fileName();
    changeTmpFile.write(result.stdOut.toAscii());
    changeTmpFile.close();
con's avatar
con committed

    args.clear();
    args << QLatin1String("fstat");
    args.append(perforceRelativeProjectDirectory(state));
    PerforceResponse fstatResult = runP4Cmd(state.currentProjectTopLevel(), args,
                                            RunFullySynchronous|CommandToWindow|StdErrToWindow|ErrorToWindow);
    if (fstatResult.error) {
con's avatar
con committed
        return;
    }

    QStringList fstatLines = fstatResult.stdOut.split(QLatin1Char('\n'));
con's avatar
con committed
    QStringList depotFileNames;
    foreach (const QString &line, fstatLines) {
        if (line.startsWith(QLatin1String("... depotFile")))
con's avatar
con committed
            depotFileNames.append(line.mid(14));
    }
    if (depotFileNames.isEmpty()) {
        VCSBase::VCSBaseOutputWindow::instance()->appendWarning(tr("Project has no files"));
con's avatar
con committed
        return;
    }

    openPerforceSubmitEditor(m_commitMessageFileName, depotFileNames);
con's avatar
con committed
}

Core::IEditor *PerforcePlugin::openPerforceSubmitEditor(const QString &fileName, const QStringList &depotFileNames)
{
    Core::EditorManager *editorManager = Core::EditorManager::instance();
    Core::IEditor *editor = editorManager->openEditor(fileName, Constants::PERFORCE_SUBMIT_EDITOR_ID,
                                                      Core::EditorManager::ModeSwitch);
dt's avatar
dt committed
    PerforceSubmitEditor *submitEditor = static_cast<PerforceSubmitEditor*>(editor);
con's avatar
con committed
    submitEditor->restrictToProjectFiles(depotFileNames);
    submitEditor->registerActions(m_undoAction, m_redoAction, m_submitCurrentLogAction, m_diffSelectedFiles);
    connect(submitEditor, SIGNAL(diffSelectedFiles(QStringList)), this, SLOT(slotSubmitDiff(QStringList)));
    submitEditor->setCheckScriptWorkingDirectory(m_commitWorkingDirectory);
con's avatar
con committed
    return editor;
}

void PerforcePlugin::printPendingChanges()
{
    qApp->setOverrideCursor(Qt::WaitCursor);
    PendingChangesDialog dia(pendingChangesData(), Core::ICore::instance()->mainWindow());
con's avatar
con committed
    qApp->restoreOverrideCursor();
    if (dia.exec() == QDialog::Accepted) {
        const int i = dia.changeNumber();
        QStringList args(QLatin1String("submit"));
        args << QLatin1String("-c") << QString::number(i);
        runP4Cmd(m_settings.topLevel(), args,
                 CommandToWindow|StdOutToWindow|StdErrToWindow|ErrorToWindow);
con's avatar
con committed
    }
}

void PerforcePlugin::describeChange()
{
    ChangeNumberDialog dia;
    if (dia.exec() == QDialog::Accepted && dia.number() > 0)
        describe(QString(), QString::number(dia.number()));
}

void PerforcePlugin::annotateCurrentFile()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
    annotate(state.currentFileTopLevel(), state.relativeCurrentFile());
con's avatar
con committed
}

void PerforcePlugin::annotate()
{
    const QString file = QFileDialog::getOpenFileName(0, tr("p4 annotate"));
    if (!file.isEmpty()) {
        const QFileInfo fi(file);
        annotate(fi.absolutePath(), fi.fileName());
    }
con's avatar
con committed
}

void PerforcePlugin::vcsAnnotate(const QString &file, const QString &revision, int lineNumber)
{
    const QFileInfo fi(file);
    annotate(fi.absolutePath(), fi.fileName(), revision, lineNumber);
}

void PerforcePlugin::annotate(const QString &workingDir,
                              const QString &fileName,
                              const QString &changeList /* = QString() */,
                              int lineNumber /* = -1 */)
con's avatar
con committed
{
    const QStringList files = QStringList(fileName);
    QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(workingDir, files);
    const QString id = VCSBase::VCSBaseEditor::getTitleId(workingDir, files, changeList);
    const QString source = VCSBase::VCSBaseEditor::getSource(workingDir, files);
con's avatar
con committed
    QStringList args;
    args << QLatin1String("annotate") << QLatin1String("-cqi");
    if (changeList.isEmpty()) {
        args << fileName;
    } else {
        args << (fileName + QLatin1Char('@') + changeList);
    }
    const PerforceResponse result = runP4Cmd(workingDir, args,
                                             CommandToWindow|StdErrToWindow|ErrorToWindow,
                                             QStringList(), QByteArray(), codec);
con's avatar
con committed
    if (!result.error) {
        if (lineNumber < 1)
            lineNumber = VCSBase::VCSBaseEditor::lineNumberOfCurrentEditor();
con's avatar
con committed
        const QFileInfo fi(fileName);
        Core::IEditor *ed = showOutputInEditor(tr("p4 annotate %1").arg(id),
                                               result.stdOut, VCSBase::AnnotateOutput,
                                               source, codec);
        VCSBase::VCSBaseEditor::gotoLineOfEditor(ed, lineNumber);
con's avatar
con committed
    }
}

void PerforcePlugin::filelogCurrentFile()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
    filelog(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()), true);
con's avatar
con committed
}

void PerforcePlugin::filelog()
{
    const QString file = QFileDialog::getOpenFileName(0, tr("p4 filelog"));
    if (!file.isEmpty()) {
        const QFileInfo fi(file);
        filelog(fi.absolutePath(), QStringList(fi.fileName()));
    }
con's avatar
con committed
}

void PerforcePlugin::logProject()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return)
    filelog(state.currentProjectTopLevel(), perforceRelativeFileArguments(state.relativeCurrentProject()));
}

void PerforcePlugin::logRepository()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasTopLevel(), return)
    filelog(state.topLevel(), perforceRelativeFileArguments(QStringList()));
}

void PerforcePlugin::filelog(const QString &workingDir, const QStringList &fileNames,
                             bool enableAnnotationContextMenu)
con's avatar
con committed
{
    const QString id = VCSBase::VCSBaseEditor::getTitleId(workingDir, fileNames);
    QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(workingDir, fileNames);
con's avatar
con committed
    QStringList args;
    args << QLatin1String("filelog") << QLatin1String("-li");
    if (m_settings.logCount() > 0)
        args << QLatin1String("-m") << QString::number(m_settings.logCount());
    args.append(fileNames);
    const PerforceResponse result = runP4Cmd(workingDir, args,
                                             CommandToWindow|StdErrToWindow|ErrorToWindow,
                                             QStringList(), QByteArray(), codec);
    if (!result.error) {
        const QString source = VCSBase::VCSBaseEditor::getSource(workingDir, fileNames);
        Core::IEditor *editor = showOutputInEditor(tr("p4 filelog %1").arg(id), result.stdOut,
                                VCSBase::LogOutput, source, codec);
        if (enableAnnotationContextMenu)
            VCSBase::VCSBaseEditor::getVcsBaseEditor(editor)->setFileLogAnnotateEnabled(true);
    }
con's avatar
con committed
}

void PerforcePlugin::updateActions(VCSBase::VCSBasePlugin::ActionState as)
con's avatar
con committed
{
Friedemann Kleint's avatar
Friedemann Kleint committed
    if (!enableMenuAction(as, m_menuAction)) {
        m_commandLocator->setEnabled(false);
        return;        
    }
    const bool hasTopLevel = currentState().hasTopLevel();
    m_commandLocator->setEnabled(hasTopLevel);
    m_logRepositoryAction->setEnabled(hasTopLevel);
    const QString fileName = currentState().currentFileName();
    m_editAction->setParameter(fileName);
    m_addAction->setParameter(fileName);
    m_deleteAction->setParameter(fileName);
    m_revertFileAction->setParameter(fileName);
    m_diffFileAction->setParameter(fileName);
    m_annotateCurrentAction->setParameter(fileName);
    m_filelogCurrentAction->setParameter(fileName);

    const QString projectName = currentState().currentProjectName();
    m_logProjectAction->setParameter(projectName);
    m_updateProjectAction->setParameter(projectName);
    m_diffProjectAction->setParameter(projectName);
    m_submitProjectAction->setParameter(projectName);
    m_revertProjectAction->setParameter(projectName);
    m_revertUnchangedAction->setParameter(projectName);
con's avatar
con committed
    m_diffAllAction->setEnabled(true);
    m_openedAction->setEnabled(true);
    m_describeAction->setEnabled(true);
    m_annotateAction->setEnabled(true);
    m_filelogAction->setEnabled(true);
    m_pendingAction->setEnabled(true);
    m_updateAllAction->setEnabled(true);
con's avatar
con committed
}

bool PerforcePlugin::managesDirectory(const QString &directory, QString *topLevel /* = 0 */)
{
    const bool rc = managesDirectoryFstat(directory);
    if (topLevel) {
        if (rc) {
            *topLevel = m_settings.topLevelSymLinkTarget();
        } else {
            topLevel->clear();
        }
    }
    return rc;
}

bool PerforcePlugin::managesDirectoryFstat(const QString &directory)
con's avatar
con committed
{
    if (!m_settings.isValid())
    // Cached?
    const ManagedDirectoryCache::const_iterator cit = m_managedDirectoryCache.constFind(directory);
    if (cit != m_managedDirectoryCache.constEnd())
        return cit.value();
    // Determine value and insert into cache
    bool managed = false;
    do {
        // Quick check: Must be at or below top level and not "../../other_path"
        const QStringList relativeDirArgs = m_settings.relativeToTopLevelArguments(directory);
        if (!relativeDirArgs.empty() && relativeDirArgs.front().startsWith(QLatin1String("..")))
            break;
        // Is it actually managed by perforce?
        QStringList args;
        args << QLatin1String("fstat") << QLatin1String("-m1") << perforceRelativeFileArguments(relativeDirArgs);
        const PerforceResponse result = runP4Cmd(m_settings.topLevel(), args,
                                                 RunFullySynchronous);
        managed = result.stdOut.contains("depotFile") || result.stdErr.contains("... - no such file(s)");
    } while(false);

    m_managedDirectoryCache.insert(directory, managed);
    return managed;
con's avatar
con committed
}

bool PerforcePlugin::vcsOpen(const QString &workingDir, const QString &fileName)
con's avatar
con committed
{
    if (Perforce::Constants::debug)
        qDebug() << "PerforcePlugin::vcsOpen" << workingDir << fileName;
    QStringList args;
    args << QLatin1String("edit") << QDir::toNativeSeparators(fileName);
    const PerforceResponse result = runP4Cmd(workingDir, args,
                                       CommandToWindow|StdOutToWindow|StdErrToWindow|ErrorToWindow);
con's avatar
con committed
    return !result.error;
}

bool PerforcePlugin::vcsAdd(const QString &workingDir, const QString &fileName)
con's avatar
con committed
{
    QStringList args;
    args << QLatin1String("add") << fileName;
    const PerforceResponse result = runP4Cmd(workingDir, args,
                                       CommandToWindow|StdOutToWindow|StdErrToWindow|ErrorToWindow);
con's avatar
con committed
    return !result.error;
}

bool PerforcePlugin::vcsDelete(const QString &workingDir, const QString &fileName)
con's avatar
con committed
{

    QStringList args;
    args << QLatin1String("revert") << fileName;
    const PerforceResponse revertResult = runP4Cmd(workingDir, args,
                                       CommandToWindow|StdOutToWindow|StdErrToWindow|ErrorToWindow);
    if (revertResult.error)
        return false;
    args.clear();
    args << QLatin1String("delete") << fileName;
    const PerforceResponse deleteResult = runP4Cmd(workingDir, args,
                                             CommandToWindow|StdOutToWindow|StdErrToWindow|ErrorToWindow);
con's avatar
con committed
    // TODO need to carefully parse the actual messages from perforce
    // or do a fstat before to decide what to do

    // Different states are:
    // File is in depot and unopened => p4 delete %
    // File is in depot and opened => p4 revert %, p4 delete %
    // File is not in depot => p4 revert %
    return !deleteResult.error;
con's avatar
con committed
}

dt's avatar
dt committed
bool PerforcePlugin::vcsMove(const QString &workingDir, const QString &from, const QString &to)
{
    // TODO verify this works
    QStringList args;
    args << QLatin1String("edit") << from;
    const PerforceResponse editResult = runP4Cmd(workingDir, args,
                                                 CommandToWindow|StdOutToWindow|StdErrToWindow|ErrorToWindow);
    if (editResult.error)
        return false;
    args.clear();
    args << QLatin1String("move") << from << to;
    const PerforceResponse moveResult = runP4Cmd(workingDir, args,
                                                 CommandToWindow|StdOutToWindow|StdErrToWindow|ErrorToWindow);
    return !moveResult.error;
}

// Write extra args to temporary file
QSharedPointer<QTemporaryFile>
        PerforcePlugin::createTemporaryArgumentFile(const QStringList &extraArgs) const
con's avatar
con committed
{
    if (extraArgs.isEmpty())
        return QSharedPointer<QTemporaryFile>();
    // create pattern
    if (m_tempFilePattern.isEmpty()) {
        m_tempFilePattern = QDir::tempPath();
        if (!m_tempFilePattern.endsWith(QDir::separator()))
            m_tempFilePattern += QDir::separator();
        m_tempFilePattern += QLatin1String("qtc_p4_XXXXXX.args");
con's avatar
con committed
    }
    QSharedPointer<QTemporaryFile> rc(new QTemporaryFile(m_tempFilePattern));
    rc->setAutoRemove(true);
    if (!rc->open()) {
        qWarning("Could not create temporary file: %s. Appending all file names to command line.",
                 qPrintable(rc->errorString()));
        return QSharedPointer<QTemporaryFile>();
con's avatar
con committed
    }
    const int last = extraArgs.size() - 1;
    for (int i = 0; i <= last; i++) {
        rc->write(extraArgs.at(i).toLocal8Bit());
        if (i != last)
            rc->write("\n");
    }
    rc->close();
    return rc;
}
con's avatar
con committed

// Run messages

static inline QString msgNotStarted(const QString &cmd)
{
    return PerforcePlugin::tr("Could not start perforce '%1'. Please check your settings in the preferences.").arg(cmd);
}

static inline QString msgTimeout(int timeOut)
    return PerforcePlugin::tr("Perforce did not respond within timeout limit (%1 ms).").arg(timeOut );
}

static inline QString msgCrash()
{
    return PerforcePlugin::tr("The process terminated abnormally.");
}

static inline QString msgExitCode(int ex)
{
    return PerforcePlugin::tr("The process terminated with exit code %1.").arg(ex);
}

// Run using a SynchronousProcess, emitting signals to the message window
PerforceResponse PerforcePlugin::synchronousProcess(const QString &workingDir,
                                                    const QStringList &args,