2009-02-25 09:15:00 +01:00
/**************************************************************************
2008-12-02 12:01:29 +01:00
* *
* * This file is part of Qt Creator
* *
2009-02-25 09:15:00 +01:00
* * Copyright ( c ) 2009 Nokia Corporation and / or its subsidiary ( - ies ) .
2008-12-02 12:01:29 +01:00
* *
2009-06-17 00:01:27 +10:00
* * Contact : Nokia Corporation ( qt - info @ nokia . com )
2008-12-02 12:01:29 +01:00
* *
2009-02-25 09:15:00 +01:00
* * Commercial Usage
2008-12-02 14:17:16 +01:00
* *
2009-02-25 09:15:00 +01:00
* * 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 .
2008-12-02 14:17:16 +01:00
* *
2009-02-25 09:15:00 +01:00
* * GNU Lesser General Public License Usage
2008-12-02 14:17:16 +01:00
* *
2009-02-25 09:15:00 +01: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
* *
2009-02-25 09:15:00 +01:00
* * If you are unsure which license is appropriate for your use , please
2009-08-14 09:30:56 +02:00
* * contact the sales department at http : //qt.nokia.com/contact.
2008-12-02 12:01:29 +01:00
* *
2009-02-25 09:15:00 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-12-02 16:19:05 +01:00
2008-12-02 12:01:29 +01:00
# include "perforceplugin.h"
2008-12-09 15:25:01 +01:00
2008-12-02 12:01:29 +01:00
# include "changenumberdialog.h"
2008-12-09 15:25:01 +01:00
# include "pendingchangesdialog.h"
2008-12-02 12:01:29 +01:00
# include "perforceconstants.h"
# include "perforceeditor.h"
2008-12-09 15:25:01 +01:00
# include "perforcesubmiteditor.h"
# include "perforceversioncontrol.h"
# include "settingspage.h"
2008-12-02 12:01:29 +01:00
2009-01-13 13:39:31 +01:00
# include <coreplugin/actionmanager/actionmanager.h>
2008-12-02 12:01:29 +01:00
# include <coreplugin/coreconstants.h>
2008-12-09 15:25:01 +01:00
# include <coreplugin/editormanager/editormanager.h>
2008-12-02 12:01:29 +01:00
# include <coreplugin/filemanager.h>
2008-12-09 15:25:01 +01:00
# include <coreplugin/icore.h>
2008-12-02 12:01:29 +01:00
# include <coreplugin/messagemanager.h>
2008-12-09 15:25:01 +01:00
# include <coreplugin/mimedatabase.h>
2008-12-02 12:01:29 +01:00
# include <coreplugin/uniqueidmanager.h>
2008-12-09 15:25:01 +01:00
# include <utils/qtcassert.h>
2008-12-02 12:01:29 +01:00
# include <utils/synchronousprocess.h>
2009-05-15 15:41:00 +02:00
# include <utils/parameteraction.h>
2008-12-02 12:01:29 +01:00
# include <vcsbase/basevcseditorfactory.h>
# include <vcsbase/basevcssubmiteditorfactory.h>
# include <vcsbase/vcsbaseeditor.h>
2009-08-10 15:46:45 +02:00
# include <vcsbase/vcsbaseoutputwindow.h>
2009-09-25 11:35:44 +02:00
# include <projectexplorer/project.h>
# include <projectexplorer/session.h>
2008-12-02 12:01:29 +01:00
2009-01-20 17:14:00 +01:00
# include <QtCore/QtPlugin>
2008-12-02 12:01:29 +01:00
# include <QtCore/QDebug>
# include <QtCore/QDir>
2008-12-09 15:25:01 +01:00
# include <QtCore/QFileInfo>
2008-12-02 12:01:29 +01:00
# include <QtCore/QSettings>
2008-12-09 15:25:01 +01:00
# include <QtCore/QTemporaryFile>
2008-12-02 12:01:29 +01:00
# include <QtCore/QTextCodec>
2008-12-09 15:25:01 +01:00
2008-12-02 12:01:29 +01:00
# include <QtGui/QAction>
2008-12-09 15:25:01 +01:00
# include <QtGui/QFileDialog>
# include <QtGui/QMainWindow>
2008-12-02 12:01:29 +01:00
# include <QtGui/QMenu>
# include <QtGui/QMessageBox>
using namespace Perforce : : Internal ;
enum { p4Timeout = 20000 } ;
static const VCSBase : : VCSBaseEditorParameters editorParameters [ ] = {
{
VCSBase : : RegularCommandOutput ,
" Perforce Command Log Editor " ,
Perforce : : Constants : : C_PERFORCEEDITOR ,
" application/vnd.nokia.text.scs_commandlog " ,
" scslog " } ,
{ VCSBase : : LogOutput ,
" Perforce File Log Editor " ,
Perforce : : Constants : : C_PERFORCEEDITOR ,
" application/vnd.nokia.text.scs_filelog " ,
" scsfilelog " } ,
{ VCSBase : : AnnotateOutput ,
" Perforce Annotation Editor " ,
Perforce : : Constants : : C_PERFORCEEDITOR ,
" application/vnd.nokia.text.scs_annotation " ,
" scsannotate " } ,
{ VCSBase : : DiffOutput ,
" Perforce Diff Editor " ,
Perforce : : Constants : : C_PERFORCEEDITOR ,
" 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 " ) ;
}
2009-03-10 11:02:12 +01:00
// Return the project files relevant for VCS
static const QStringList currentProjectFiles ( QString * name )
{
QStringList files = VCSBase : : VCSBaseSubmitEditor : : currentProjectFiles ( true , name ) ;
if ( ! files . empty ( ) ) {
// Filter out mkspecs/qconfig.pri
QString exclusion = QLatin1String ( " mkspecs " ) ;
exclusion + = QDir : : separator ( ) ;
exclusion + = QLatin1String ( " qconfig.pri " ) ;
for ( QStringList : : iterator it = files . begin ( ) ; it ! = files . end ( ) ; ) {
if ( it - > endsWith ( exclusion ) ) {
it = files . erase ( it ) ;
break ;
} else {
+ + it ;
}
}
}
return files ;
}
2009-07-13 14:48:44 +02:00
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_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_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 " ;
2008-12-02 12:01:29 +01:00
////
// CoreListener
////
bool CoreListener : : editorAboutToClose ( Core : : IEditor * editor )
{
return m_plugin - > editorAboutToClose ( editor ) ;
}
////
// PerforcePlugin
////
PerforcePlugin * PerforcePlugin : : m_perforcePluginInstance = NULL ;
PerforcePlugin : : PerforcePlugin ( ) :
m_editAction ( 0 ) ,
m_addAction ( 0 ) ,
m_deleteAction ( 0 ) ,
m_openedAction ( 0 ) ,
m_revertAction ( 0 ) ,
m_diffCurrentAction ( 0 ) ,
m_diffProjectAction ( 0 ) ,
2009-07-13 14:48:44 +02:00
m_updateProjectAction ( 0 ) ,
2008-12-02 12:01:29 +01:00
m_diffAllAction ( 0 ) ,
m_resolveAction ( 0 ) ,
2009-07-13 14:48:44 +02:00
m_submitAction ( 0 ) ,
2008-12-02 12:01:29 +01:00
m_pendingAction ( 0 ) ,
m_describeAction ( 0 ) ,
m_annotateCurrentAction ( 0 ) ,
m_annotateAction ( 0 ) ,
m_filelogCurrentAction ( 0 ) ,
m_filelogAction ( 0 ) ,
2009-03-20 10:16:18 +01:00
m_submitCurrentLogAction ( 0 ) ,
2009-07-13 14:48:44 +02:00
m_updateAllAction ( 0 ) ,
2009-03-20 10:16:18 +01:00
m_submitActionTriggered ( false ) ,
m_diffSelectedFiles ( 0 ) ,
m_undoAction ( 0 ) ,
m_redoAction ( 0 ) ,
2008-12-02 12:01:29 +01:00
m_versionControl ( 0 )
{
}
static const VCSBase : : VCSBaseSubmitEditorParameters submitParameters = {
Perforce : : Constants : : SUBMIT_MIMETYPE ,
Perforce : : Constants : : PERFORCESUBMITEDITOR_KIND ,
2009-01-13 14:06:42 +01:00
Perforce : : Constants : : C_PERFORCESUBMITEDITOR
2008-12-02 12:01:29 +01:00
} ;
2009-01-20 11:52:04 +01:00
bool PerforcePlugin : : initialize ( const QStringList & arguments , QString * errorMessage )
2008-12-02 12:01:29 +01:00
{
2009-07-13 17:35:17 +02:00
Q_UNUSED ( arguments )
Q_UNUSED ( errorMessage )
2009-01-20 11:52:04 +01:00
2008-12-02 12:01:29 +01:00
typedef VCSBase : : VCSEditorFactory < PerforceEditor > PerforceEditorFactory ;
typedef VCSBase : : VCSSubmitEditorFactory < PerforceSubmitEditor > PerforceSubmitEditorFactory ;
2009-01-20 11:52:04 +01:00
Core : : ICore * core = Core : : ICore : : instance ( ) ;
if ( ! core - > mimeDatabase ( ) - > addMimeTypes ( QLatin1String ( " :/trolltech.perforce/Perforce.mimetypes.xml " ) , errorMessage ) )
2008-12-02 12:01:29 +01:00
return false ;
m_perforcePluginInstance = this ;
2009-01-20 11:52:04 +01:00
if ( QSettings * settings = core - > settings ( ) )
2008-12-02 12:01:29 +01:00
m_settings . fromSettings ( settings ) ;
2009-08-10 15:46:45 +02:00
addAutoReleasedObject ( new SettingsPage ) ;
2008-12-02 12:01:29 +01:00
// Editor factories
2009-08-10 15:46:45 +02:00
addAutoReleasedObject ( new PerforceSubmitEditorFactory ( & submitParameters ) ) ;
2008-12-02 12:01:29 +01:00
static const char * describeSlot = SLOT ( describe ( QString , QString ) ) ;
const int editorCount = sizeof ( editorParameters ) / sizeof ( VCSBase : : VCSBaseEditorParameters ) ;
2009-08-10 15:46:45 +02:00
for ( int i = 0 ; i < editorCount ; i + + )
addAutoReleasedObject ( new PerforceEditorFactory ( editorParameters + i , this , describeSlot ) ) ;
2008-12-02 12:01:29 +01:00
m_versionControl = new PerforceVersionControl ( this ) ;
2009-08-10 15:46:45 +02:00
addAutoReleasedObject ( m_versionControl ) ;
2008-12-02 12:01:29 +01:00
2009-08-10 15:46:45 +02:00
addAutoReleasedObject ( new CoreListener ( this ) ) ;
2008-12-02 12:01:29 +01:00
//register actions
2009-01-20 11:52:04 +01:00
Core : : ActionManager * am = Core : : ICore : : instance ( ) - > actionManager ( ) ;
2008-12-02 12:01:29 +01:00
2009-01-14 12:39:59 +01:00
Core : : ActionContainer * mtools =
2008-12-02 12:01:29 +01:00
am - > actionContainer ( Core : : Constants : : M_TOOLS ) ;
2009-01-14 12:39:59 +01:00
Core : : ActionContainer * mperforce =
2009-07-13 14:48:44 +02:00
am - > createMenu ( QLatin1String ( CMD_ID_PERFORCE_MENU ) ) ;
2008-12-02 12:01:29 +01:00
mperforce - > menu ( ) - > setTitle ( tr ( " &Perforce " ) ) ;
mtools - > addMenu ( mperforce ) ;
2008-12-03 15:04:51 +01:00
if ( QAction * ma = mperforce - > menu ( ) - > menuAction ( ) ) {
ma - > setEnabled ( m_versionControl - > isEnabled ( ) ) ;
connect ( m_versionControl , SIGNAL ( enabledChanged ( bool ) ) , ma , SLOT ( setVisible ( bool ) ) ) ;
}
2008-12-02 12:01:29 +01:00
QList < int > globalcontext ;
globalcontext < < Core : : Constants : : C_GLOBAL_ID ;
QList < int > perforcesubmitcontext ;
2009-01-21 15:52:34 +01:00
perforcesubmitcontext < < Core : : UniqueIDManager : : instance ( ) - >
uniqueIdentifier ( Constants : : C_PERFORCESUBMITEDITOR ) ;
2008-12-02 12:01:29 +01:00
2009-01-14 13:17:53 +01:00
Core : : Command * command ;
2008-12-02 12:01:29 +01:00
QAction * tmpaction ;
2009-05-15 15:41:00 +02:00
m_editAction = new Core : : Utils : : ParameterAction ( tr ( " Edit " ) , tr ( " Edit \" %1 \" " ) , Core : : Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2009-07-13 14:48:44 +02:00
command = am - > registerAction ( m_editAction , CMD_ID_EDIT , globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2009-07-13 14:48:44 +02:00
# ifndef Q_WS_MAC
2008-12-02 12:01:29 +01:00
command - > setDefaultKeySequence ( QKeySequence ( tr ( " Alt+P,Alt+E " ) ) ) ;
2009-07-13 14:48:44 +02:00
# endif
2008-12-02 12:01:29 +01:00
command - > setDefaultText ( tr ( " Edit File " ) ) ;
connect ( m_editAction , SIGNAL ( triggered ( ) ) , this , SLOT ( openCurrentFile ( ) ) ) ;
mperforce - > addAction ( command ) ;
2009-05-15 15:41:00 +02:00
m_addAction = new Core : : Utils : : ParameterAction ( tr ( " Add " ) , tr ( " Add \" %1 \" " ) , Core : : Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2009-07-13 14:48:44 +02:00
command = am - > registerAction ( m_addAction , CMD_ID_ADD , globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2009-07-13 14:48:44 +02:00
# ifndef Q_WS_MAC
2008-12-02 12:01:29 +01:00
command - > setDefaultKeySequence ( QKeySequence ( tr ( " Alt+P,Alt+A " ) ) ) ;
2009-07-13 14:48:44 +02:00
# endif
2008-12-02 12:01:29 +01:00
command - > setDefaultText ( tr ( " Add File " ) ) ;
connect ( m_addAction , SIGNAL ( triggered ( ) ) , this , SLOT ( addCurrentFile ( ) ) ) ;
mperforce - > addAction ( command ) ;
2009-05-15 15:41:00 +02:00
m_deleteAction = new Core : : Utils : : ParameterAction ( tr ( " Delete " ) , tr ( " Delete \" %1 \" " ) , Core : : Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2009-07-13 14:48:44 +02:00
command = am - > registerAction ( m_deleteAction , CMD_ID_DELETE_FILE , globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2008-12-02 12:01:29 +01:00
command - > setDefaultText ( tr ( " Delete File " ) ) ;
connect ( m_deleteAction , SIGNAL ( triggered ( ) ) , this , SLOT ( deleteCurrentFile ( ) ) ) ;
mperforce - > addAction ( command ) ;
2009-05-15 15:41:00 +02:00
m_revertAction = new Core : : Utils : : ParameterAction ( tr ( " Revert " ) , tr ( " Revert \" %1 \" " ) , Core : : Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2009-07-13 14:48:44 +02:00
command = am - > registerAction ( m_revertAction , CMD_ID_REVERT , globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2009-07-13 14:48:44 +02:00
# ifndef Q_WS_MAC
2008-12-02 12:01:29 +01:00
command - > setDefaultKeySequence ( QKeySequence ( tr ( " Alt+P,Alt+R " ) ) ) ;
2009-07-13 14:48:44 +02:00
# endif
2008-12-02 12:01:29 +01:00
command - > setDefaultText ( tr ( " Revert File " ) ) ;
connect ( m_revertAction , SIGNAL ( triggered ( ) ) , this , SLOT ( revertCurrentFile ( ) ) ) ;
mperforce - > addAction ( command ) ;
tmpaction = new QAction ( this ) ;
tmpaction - > setSeparator ( true ) ;
command = am - > registerAction ( tmpaction , QLatin1String ( " Perforce.Sep.Edit " ) , globalcontext ) ;
mperforce - > addAction ( command ) ;
2009-05-15 15:41:00 +02:00
m_diffCurrentAction = new Core : : Utils : : ParameterAction ( tr ( " Diff Current File " ) , tr ( " Diff \" %1 \" " ) , Core : : Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2009-07-13 14:48:44 +02:00
command = am - > registerAction ( m_diffCurrentAction , CMD_ID_DIFF_CURRENT , globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2008-12-02 12:01:29 +01:00
command - > setDefaultText ( tr ( " Diff Current File " ) ) ;
connect ( m_diffCurrentAction , SIGNAL ( triggered ( ) ) , this , SLOT ( diffCurrentFile ( ) ) ) ;
mperforce - > addAction ( command ) ;
2009-07-13 14:48:44 +02:00
const QString diffProjectDefaultText = tr ( " Diff Current Project/Session " ) ;
m_diffProjectAction = new Core : : Utils : : ParameterAction ( diffProjectDefaultText , tr ( " Diff Project \" %1 \" " ) , Core : : Utils : : ParameterAction : : AlwaysEnabled , this ) ;
command = am - > registerAction ( m_diffProjectAction , CMD_ID_DIFF_PROJECT , globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2009-07-13 14:48:44 +02:00
# ifndef Q_WS_MAC
2008-12-02 12:01:29 +01:00
command - > setDefaultKeySequence ( QKeySequence ( tr ( " Alt+P,Alt+D " ) ) ) ;
2009-07-13 14:48:44 +02:00
# endif
command - > setDefaultText ( diffProjectDefaultText ) ;
2008-12-02 12:01:29 +01:00
connect ( m_diffProjectAction , SIGNAL ( triggered ( ) ) , this , SLOT ( diffCurrentProject ( ) ) ) ;
mperforce - > addAction ( command ) ;
m_diffAllAction = new QAction ( tr ( " Diff Opened Files " ) , this ) ;
2009-07-13 14:48:44 +02:00
command = am - > registerAction ( m_diffAllAction , CMD_ID_DIFF_ALL , globalcontext ) ;
2008-12-02 12:01:29 +01:00
connect ( m_diffAllAction , SIGNAL ( triggered ( ) ) , this , SLOT ( diffAllOpened ( ) ) ) ;
mperforce - > addAction ( command ) ;
tmpaction = new QAction ( this ) ;
tmpaction - > setSeparator ( true ) ;
command = am - > registerAction ( tmpaction , QLatin1String ( " Perforce.Sep.Diff " ) , globalcontext ) ;
mperforce - > addAction ( command ) ;
m_openedAction = new QAction ( tr ( " Opened " ) , this ) ;
2009-07-13 14:48:44 +02:00
command = am - > registerAction ( m_openedAction , CMD_ID_OPENED , globalcontext ) ;
# ifndef Q_WS_MAC
2008-12-02 12:01:29 +01:00
command - > setDefaultKeySequence ( QKeySequence ( tr ( " Alt+P,Alt+O " ) ) ) ;
2009-07-13 14:48:44 +02:00
# endif
2008-12-02 12:01:29 +01:00
connect ( m_openedAction , SIGNAL ( triggered ( ) ) , this , SLOT ( printOpenedFileList ( ) ) ) ;
mperforce - > addAction ( command ) ;
m_submitAction = new QAction ( tr ( " Submit Project " ) , this ) ;
2009-07-13 14:48:44 +02:00
command = am - > registerAction ( m_submitAction , CMD_ID_SUBMIT , globalcontext ) ;
2008-12-02 12:01:29 +01:00
command - > setDefaultKeySequence ( QKeySequence ( tr ( " Alt+P,Alt+S " ) ) ) ;
connect ( m_submitAction , SIGNAL ( triggered ( ) ) , this , SLOT ( submit ( ) ) ) ;
mperforce - > addAction ( command ) ;
m_pendingAction = new QAction ( tr ( " Pending Changes... " ) , this ) ;
2009-07-13 14:48:44 +02:00
command = am - > registerAction ( m_pendingAction , CMD_ID_PENDING_CHANGES , globalcontext ) ;
2008-12-02 12:01:29 +01:00
connect ( m_pendingAction , SIGNAL ( triggered ( ) ) , this , SLOT ( printPendingChanges ( ) ) ) ;
mperforce - > addAction ( command ) ;
2009-07-13 14:48:44 +02:00
const QString updateProjectDefaultText = tr ( " Update Current Project/Session " ) ;
m_updateProjectAction = new Core : : Utils : : ParameterAction ( updateProjectDefaultText , tr ( " Update Project \" %1 \" " ) , Core : : 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 ) ;
2008-12-02 12:01:29 +01:00
tmpaction = new QAction ( this ) ;
tmpaction - > setSeparator ( true ) ;
command = am - > registerAction ( tmpaction , QLatin1String ( " Perforce.Sep.Changes " ) , globalcontext ) ;
mperforce - > addAction ( command ) ;
m_describeAction = new QAction ( tr ( " Describe... " ) , this ) ;
2009-07-13 14:48:44 +02:00
command = am - > registerAction ( m_describeAction , CMD_ID_DESCRIBE , globalcontext ) ;
2008-12-02 12:01:29 +01:00
connect ( m_describeAction , SIGNAL ( triggered ( ) ) , this , SLOT ( describeChange ( ) ) ) ;
mperforce - > addAction ( command ) ;
2009-05-15 15:41:00 +02:00
m_annotateCurrentAction = new Core : : Utils : : ParameterAction ( tr ( " Annotate Current File " ) , tr ( " Annotate \" %1 \" " ) , Core : : Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2009-07-13 14:48:44 +02:00
command = am - > registerAction ( m_annotateCurrentAction , CMD_ID_ANNOTATE_CURRENT , globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2008-12-02 12:01:29 +01:00
command - > setDefaultText ( tr ( " Annotate Current File " ) ) ;
connect ( m_annotateCurrentAction , SIGNAL ( triggered ( ) ) , this , SLOT ( annotateCurrentFile ( ) ) ) ;
mperforce - > addAction ( command ) ;
m_annotateAction = new QAction ( tr ( " Annotate... " ) , this ) ;
2009-07-13 14:48:44 +02:00
command = am - > registerAction ( m_annotateAction , CMD_ID_ANNOTATE , globalcontext ) ;
2008-12-02 12:01:29 +01:00
connect ( m_annotateAction , SIGNAL ( triggered ( ) ) , this , SLOT ( annotate ( ) ) ) ;
mperforce - > addAction ( command ) ;
2009-05-15 15:41:00 +02:00
m_filelogCurrentAction = new Core : : Utils : : ParameterAction ( tr ( " Filelog Current File " ) , tr ( " Filelog \" %1 \" " ) , Core : : Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2009-07-13 14:48:44 +02:00
command = am - > registerAction ( m_filelogCurrentAction , CMD_ID_FILELOG_CURRENT , globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2009-07-13 14:48:44 +02:00
# ifndef Q_WS_MAC
2008-12-02 12:01:29 +01:00
command - > setDefaultKeySequence ( QKeySequence ( tr ( " Alt+P,Alt+F " ) ) ) ;
2009-07-13 14:48:44 +02:00
# endif
2008-12-02 12:01:29 +01:00
command - > setDefaultText ( tr ( " Filelog Current File " ) ) ;
connect ( m_filelogCurrentAction , SIGNAL ( triggered ( ) ) , this , SLOT ( filelogCurrentFile ( ) ) ) ;
mperforce - > addAction ( command ) ;
m_filelogAction = new QAction ( tr ( " Filelog... " ) , this ) ;
2009-07-13 14:48:44 +02:00
command = am - > registerAction ( m_filelogAction , CMD_ID_FILELOG , globalcontext ) ;
2008-12-02 12:01:29 +01:00
connect ( m_filelogAction , SIGNAL ( triggered ( ) ) , this , SLOT ( filelog ( ) ) ) ;
mperforce - > addAction ( command ) ;
2009-07-13 14:48:44 +02:00
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 ( ) ) ) ;
mperforce - > addAction ( command ) ;
2008-12-02 17:05:53 +01:00
m_submitCurrentLogAction = new QAction ( VCSBase : : VCSBaseSubmitEditor : : submitIcon ( ) , tr ( " Submit " ) , this ) ;
2008-12-02 12:01:29 +01:00
command = am - > registerAction ( m_submitCurrentLogAction , Constants : : SUBMIT_CURRENT , perforcesubmitcontext ) ;
connect ( m_submitCurrentLogAction , SIGNAL ( triggered ( ) ) , this , SLOT ( submitCurrentLog ( ) ) ) ;
2008-12-02 17:05:53 +01:00
m_diffSelectedFiles = new QAction ( VCSBase : : VCSBaseSubmitEditor : : diffIcon ( ) , tr ( " Diff Selected Files " ) , this ) ;
2008-12-02 12:01:29 +01:00
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 ) ;
2009-01-20 11:52:04 +01:00
connect ( core , SIGNAL ( contextChanged ( Core : : IContext * ) ) ,
2008-12-02 12:01:29 +01:00
this , SLOT ( updateActions ( ) ) ) ;
2009-01-20 11:52:04 +01:00
connect ( core - > fileManager ( ) , SIGNAL ( currentFileChanged ( const QString & ) ) ,
2008-12-02 12:01:29 +01:00
this , SLOT ( updateActions ( ) ) ) ;
return true ;
}
void PerforcePlugin : : extensionsInitialized ( )
{
2009-03-04 09:38:01 +01:00
m_projectExplorer = ProjectExplorer : : ProjectExplorerPlugin : : instance ( ) ;
2008-12-02 12:01:29 +01:00
if ( m_projectExplorer ) {
connect ( m_projectExplorer ,
SIGNAL ( currentProjectChanged ( ProjectExplorer : : Project * ) ) ,
this , SLOT ( updateActions ( ) ) ) ;
}
updateActions ( ) ;
}
void PerforcePlugin : : openCurrentFile ( )
{
2008-12-04 16:24:15 +01:00
vcsOpen ( currentFileName ( ) ) ;
2008-12-02 12:01:29 +01:00
}
void PerforcePlugin : : addCurrentFile ( )
{
2008-12-04 16:24:15 +01:00
vcsAdd ( currentFileName ( ) ) ;
2008-12-02 12:01:29 +01:00
}
void PerforcePlugin : : deleteCurrentFile ( )
{
2008-12-04 16:24:15 +01:00
vcsDelete ( currentFileName ( ) ) ;
2008-12-02 12:01:29 +01:00
}
void PerforcePlugin : : revertCurrentFile ( )
{
const QString fileName = currentFileName ( ) ;
2009-01-20 11:52:04 +01:00
QTextCodec * codec = VCSBase : : VCSBaseEditor : : getCodec ( fileName ) ;
2008-12-02 12:01:29 +01:00
QStringList args ;
args < < QLatin1String ( " diff " ) < < QLatin1String ( " -sa " ) ;
2008-12-04 16:24:15 +01:00
PerforceResponse result = runP4Cmd ( args , QStringList ( ) , CommandToWindow | StdErrToWindow | ErrorToWindow , codec ) ;
2008-12-02 12:01:29 +01:00
if ( result . error )
return ;
if ( ! result . stdOut . isEmpty ( ) ) {
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 ;
}
2009-06-18 14:30:04 +02:00
Core : : FileChangeBlocker fcb ( fileName ) ;
fcb . setModifiedReload ( true ) ;
2008-12-04 16:24:15 +01:00
PerforceResponse result2 = runP4Cmd ( QStringList ( ) < < QLatin1String ( " revert " ) < < fileName , QStringList ( ) , CommandToWindow | StdOutToWindow | StdErrToWindow | ErrorToWindow ) ;
2008-12-02 12:01:29 +01:00
}
void PerforcePlugin : : diffCurrentFile ( )
{
p4Diff ( QStringList ( currentFileName ( ) ) ) ;
}
void PerforcePlugin : : diffCurrentProject ( )
{
QString name ;
2009-03-10 11:02:12 +01:00
const QStringList nativeFiles = currentProjectFiles ( & name ) ;
2008-12-02 12:01:29 +01:00
p4Diff ( nativeFiles , name ) ;
}
void PerforcePlugin : : diffAllOpened ( )
{
p4Diff ( QStringList ( ) ) ;
}
2009-07-13 14:48:44 +02:00
// Add the directory of a project to a list of p4 directory specifications
// ("path/...")
static inline void addProjectP4Directory ( const ProjectExplorer : : Project * p , QStringList * p4dirs )
{
if ( const Core : : IFile * file = p - > file ( ) ) {
const QFileInfo fi ( file - > fileName ( ) ) ;
QString p4dir = fi . absolutePath ( ) ;
if ( ! p4dir . isEmpty ( ) ) {
p4dir + = QDir : : separator ( ) ;
p4dir + = QLatin1String ( " ... " ) ;
p4dirs - > push_back ( p4dir ) ;
}
}
}
void PerforcePlugin : : updateCurrentProject ( )
{
if ( ! m_projectExplorer )
return ;
// Compile a list of project directories
QStringList p4Directories ;
if ( const ProjectExplorer : : Project * proj = m_projectExplorer - > currentProject ( ) ) {
addProjectP4Directory ( proj , & p4Directories ) ;
} else {
if ( const ProjectExplorer : : SessionManager * session = m_projectExplorer - > session ( ) )
foreach ( const ProjectExplorer : : Project * proj , session - > projects ( ) )
addProjectP4Directory ( proj , & p4Directories ) ;
}
if ( ! p4Directories . empty ( ) )
updateCheckout ( p4Directories ) ;
}
void PerforcePlugin : : updateAll ( )
{
updateCheckout ( ) ;
}
void PerforcePlugin : : updateCheckout ( const QStringList & dirs )
{
QStringList args ( QLatin1String ( " sync " ) ) ;
args . append ( dirs ) ;
runP4Cmd ( args , QStringList ( ) , CommandToWindow | StdOutToWindow | StdErrToWindow | ErrorToWindow ) ;
}
2008-12-02 12:01:29 +01:00
void PerforcePlugin : : printOpenedFileList ( )
{
2009-01-21 15:52:34 +01:00
Core : : IEditor * e = Core : : EditorManager : : instance ( ) - > currentEditor ( ) ;
2008-12-02 12:01:29 +01:00
if ( e )
e - > widget ( ) - > setFocus ( ) ;
2008-12-04 16:24:15 +01:00
PerforceResponse result = runP4Cmd ( QStringList ( ) < < QLatin1String ( " opened " ) , QStringList ( ) , CommandToWindow | StdOutToWindow | StdErrToWindow | ErrorToWindow ) ;
2008-12-02 12:01:29 +01:00
}
void PerforcePlugin : : submit ( )
{
2009-05-27 16:17:24 +02:00
if ( VCSBase : : VCSBaseSubmitEditor : : raiseSubmitEditor ( ) )
return ;
2009-05-28 10:30:10 +02:00
QString errorMessage ;
if ( ! checkP4Configuration ( & errorMessage ) ) {
2009-08-10 15:46:45 +02:00
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendError ( errorMessage ) ;
2008-12-02 12:01:29 +01:00
return ;
}
2009-09-22 12:23:44 +02:00
if ( isCommitEditorOpen ( ) ) {
2009-08-10 15:46:45 +02:00
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendWarning ( tr ( " Another submit is currently executed. " ) ) ;
2008-12-02 12:01:29 +01:00
return ;
}
2009-09-22 12:23:44 +02:00
QTemporaryFile changeTmpFile ;
changeTmpFile . setAutoRemove ( false ) ;
if ( ! changeTmpFile . open ( ) ) {
2009-08-10 15:46:45 +02:00
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendError ( tr ( " Cannot create temporary file. " ) ) ;
2009-09-22 12:23:44 +02:00
cleanCommitMessageFile ( ) ;
2008-12-02 12:01:29 +01:00
return ;
}
2008-12-04 16:24:15 +01:00
PerforceResponse result = runP4Cmd ( QStringList ( ) < < QLatin1String ( " change " ) < < QLatin1String ( " -o " ) , QStringList ( ) ,
CommandToWindow | StdErrToWindow | ErrorToWindow ) ;
2008-12-02 12:01:29 +01:00
if ( result . error ) {
2009-09-22 12:23:44 +02:00
cleanCommitMessageFile ( ) ;
2008-12-02 12:01:29 +01:00
return ;
}
2009-09-22 12:23:44 +02:00
m_commitMessageFileName = changeTmpFile . fileName ( ) ;
changeTmpFile . write ( result . stdOut . toAscii ( ) ) ;
changeTmpFile . close ( ) ;
2008-12-02 12:01:29 +01:00
// Assemble file list of project
QString name ;
2009-03-10 11:02:12 +01:00
const QStringList nativeFiles = currentProjectFiles ( & name ) ;
2008-12-04 16:24:15 +01:00
PerforceResponse result2 = runP4Cmd ( QStringList ( QLatin1String ( " fstat " ) ) , nativeFiles ,
CommandToWindow | StdErrToWindow | ErrorToWindow ) ;
2008-12-02 12:01:29 +01:00
if ( result2 . error ) {
2009-09-22 12:23:44 +02:00
cleanCommitMessageFile ( ) ;
2008-12-02 12:01:29 +01:00
return ;
}
QStringList stdOutLines = result2 . stdOut . split ( QLatin1Char ( ' \n ' ) ) ;
QStringList depotFileNames ;
2008-12-09 11:07:24 +01:00
foreach ( const QString & line , stdOutLines ) {
if ( line . startsWith ( " ... depotFile " ) )
2008-12-02 12:01:29 +01:00
depotFileNames . append ( line . mid ( 14 ) ) ;
}
if ( depotFileNames . isEmpty ( ) ) {
2009-08-10 15:46:45 +02:00
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendWarning ( tr ( " Project has no files " ) ) ;
2009-09-22 12:23:44 +02:00
cleanCommitMessageFile ( ) ;
2008-12-02 12:01:29 +01:00
return ;
}
2009-09-22 12:23:44 +02:00
openPerforceSubmitEditor ( m_commitMessageFileName , depotFileNames ) ;
2008-12-02 12:01:29 +01:00
}
Core : : IEditor * PerforcePlugin : : openPerforceSubmitEditor ( const QString & fileName , const QStringList & depotFileNames )
{
2009-01-21 15:52:34 +01:00
Core : : EditorManager * editorManager = Core : : EditorManager : : instance ( ) ;
Core : : IEditor * editor = editorManager - > openEditor ( fileName , Constants : : PERFORCESUBMITEDITOR_KIND ) ;
editorManager - > ensureEditorManagerVisible ( ) ;
2009-08-25 16:08:52 +02:00
PerforceSubmitEditor * submitEditor = static_cast < PerforceSubmitEditor * > ( editor ) ;
2008-12-02 12:01:29 +01:00
submitEditor - > restrictToProjectFiles ( depotFileNames ) ;
2009-01-13 14:06:42 +01:00
submitEditor - > registerActions ( m_undoAction , m_redoAction , m_submitCurrentLogAction , m_diffSelectedFiles ) ;
2008-12-02 12:01:29 +01:00
connect ( submitEditor , SIGNAL ( diffSelectedFiles ( QStringList ) ) , this , SLOT ( slotDiff ( QStringList ) ) ) ;
return editor ;
}
void PerforcePlugin : : printPendingChanges ( )
{
qApp - > setOverrideCursor ( Qt : : WaitCursor ) ;
2009-01-20 11:52:04 +01:00
PendingChangesDialog dia ( pendingChangesData ( ) , Core : : ICore : : instance ( ) - > mainWindow ( ) ) ;
2008-12-02 12:01:29 +01:00
qApp - > restoreOverrideCursor ( ) ;
if ( dia . exec ( ) = = QDialog : : Accepted ) {
2008-12-04 16:24:15 +01:00
const int i = dia . changeNumber ( ) ;
QStringList args ( QLatin1String ( " submit " ) ) ;
args < < QLatin1String ( " -c " ) < < QString : : number ( i ) ;
runP4Cmd ( args , QStringList ( ) , CommandToWindow | StdOutToWindow | StdErrToWindow | ErrorToWindow ) ;
2008-12-02 12:01:29 +01:00
}
}
void PerforcePlugin : : describeChange ( )
{
ChangeNumberDialog dia ;
if ( dia . exec ( ) = = QDialog : : Accepted & & dia . number ( ) > 0 )
describe ( QString ( ) , QString : : number ( dia . number ( ) ) ) ;
}
void PerforcePlugin : : annotateCurrentFile ( )
{
const QString file = currentFileName ( ) ;
if ( ! file . isEmpty ( ) )
annotate ( file ) ;
}
void PerforcePlugin : : annotate ( )
{
const QString file = QFileDialog : : getOpenFileName ( 0 , tr ( " p4 annotate " ) , currentFileName ( ) ) ;
if ( ! file . isEmpty ( ) )
annotate ( file ) ;
}
void PerforcePlugin : : annotate ( const QString & fileName )
{
2009-01-20 11:52:04 +01:00
QTextCodec * codec = VCSBase : : VCSBaseEditor : : getCodec ( fileName ) ;
2008-12-02 12:01:29 +01:00
QStringList args ;
args < < QLatin1String ( " annotate " ) < < QLatin1String ( " -cqi " ) < < fileName ;
2008-12-04 16:24:15 +01:00
const PerforceResponse result = runP4Cmd ( args , QStringList ( ) ,
CommandToWindow | StdErrToWindow | ErrorToWindow , codec ) ;
2008-12-02 12:01:29 +01:00
if ( ! result . error ) {
2009-10-01 17:32:26 +02:00
const int lineNumber = VCSBase : : VCSBaseEditor : : lineNumberOfCurrentEditor ( fileName ) ;
2008-12-02 12:01:29 +01:00
const QFileInfo fi ( fileName ) ;
2009-10-01 17:32:26 +02:00
Core : : IEditor * ed = showOutputInEditor ( tr ( " p4 annotate %1 " ) . arg ( fi . fileName ( ) ) ,
result . stdOut , VCSBase : : AnnotateOutput , codec ) ;
VCSBase : : VCSBaseEditor : : gotoLineOfEditor ( ed , lineNumber ) ;
2008-12-02 12:01:29 +01:00
}
}
void PerforcePlugin : : filelogCurrentFile ( )
{
const QString file = currentFileName ( ) ;
if ( ! file . isEmpty ( ) )
filelog ( file ) ;
}
void PerforcePlugin : : filelog ( )
{
const QString file = QFileDialog : : getOpenFileName ( 0 , tr ( " p4 filelog " ) , currentFileName ( ) ) ;
if ( ! file . isEmpty ( ) )
filelog ( file ) ;
}
void PerforcePlugin : : filelog ( const QString & fileName )
{
2009-01-20 11:52:04 +01:00
QTextCodec * codec = VCSBase : : VCSBaseEditor : : getCodec ( fileName ) ;
2008-12-02 12:01:29 +01:00
QStringList args ;
args < < QLatin1String ( " filelog " ) < < QLatin1String ( " -li " ) < < fileName ;
2008-12-04 16:24:15 +01:00
const PerforceResponse result = runP4Cmd ( args , QStringList ( ) ,
CommandToWindow | StdErrToWindow | ErrorToWindow , codec ) ;
2008-12-02 12:01:29 +01:00
if ( ! result . error ) {
const QFileInfo fi ( fileName ) ;
2009-01-20 15:31:33 +01:00
showOutputInEditor ( tr ( " p4 filelog %1 " ) . arg ( fi . fileName ( ) ) ,
result . stdOut , VCSBase : : LogOutput , codec ) ;
2008-12-02 12:01:29 +01:00
}
}
void PerforcePlugin : : updateActions ( )
{
2009-05-15 15:41:00 +02:00
const QString fileName = currentFileName ( ) ;
const QString baseName = fileName . isEmpty ( ) ? fileName : QFileInfo ( fileName ) . fileName ( ) ;
m_editAction - > setParameter ( baseName ) ;
m_addAction - > setParameter ( baseName ) ;
m_deleteAction - > setParameter ( baseName ) ;
m_revertAction - > setParameter ( baseName ) ;
m_diffCurrentAction - > setParameter ( baseName ) ;
m_annotateCurrentAction - > setParameter ( baseName ) ;
m_filelogCurrentAction - > setParameter ( baseName ) ;
2009-07-13 14:48:44 +02:00
// The project actions refer to the current project or the projects
// of a session, provided there are any.
2008-12-02 12:01:29 +01:00
if ( m_projectExplorer & & m_projectExplorer - > currentProject ( ) ) {
2009-07-13 14:48:44 +02:00
const QString currentProjectName = m_projectExplorer - > currentProject ( ) - > name ( ) ;
m_updateProjectAction - > setParameter ( currentProjectName ) ;
m_diffProjectAction - > setParameter ( currentProjectName ) ;
m_updateProjectAction - > setEnabled ( true ) ;
m_diffProjectAction - > setEnabled ( true ) ;
2008-12-02 12:01:29 +01:00
} else {
2009-07-13 14:48:44 +02:00
// Nope, either all projects of a session or none
m_updateProjectAction - > setParameter ( QString ( ) ) ;
2009-05-15 15:41:00 +02:00
m_diffProjectAction - > setParameter ( QString ( ) ) ;
2009-07-13 14:48:44 +02:00
const bool enabled = m_projectExplorer & & m_projectExplorer - > session ( ) & & ! m_projectExplorer - > session ( ) - > projects ( ) . empty ( ) ;
m_updateProjectAction - > setEnabled ( enabled ) ;
m_diffProjectAction - > setEnabled ( enabled ) ;
2008-12-02 12:01:29 +01:00
}
2009-07-13 14:48:44 +02:00
2008-12-02 12:01:29 +01:00
m_diffAllAction - > setEnabled ( true ) ;
m_openedAction - > setEnabled ( true ) ;
m_describeAction - > setEnabled ( true ) ;
m_annotateAction - > setEnabled ( true ) ;
m_filelogAction - > setEnabled ( true ) ;
m_pendingAction - > setEnabled ( true ) ;
2009-07-13 14:48:44 +02:00
m_updateAllAction - > setEnabled ( true ) ;
2008-12-02 12:01:29 +01:00
}
bool PerforcePlugin : : managesDirectory ( const QString & directory ) const
{
2009-05-28 10:30:10 +02:00
if ( ! checkP4Configuration ( ) )
2009-02-19 16:11:29 +01:00
return false ;
2008-12-02 12:01:29 +01:00
const QString p4Path = directory + QLatin1String ( " /... " ) ;
QStringList args ;
args < < QLatin1String ( " fstat " ) < < QLatin1String ( " -m1 " ) < < p4Path ;
2008-12-04 16:24:15 +01:00
const PerforceResponse result = runP4Cmd ( args , QStringList ( ) , 0u ) ;
2008-12-02 12:01:29 +01:00
return result . stdOut . contains ( " depotFile " ) | | result . stdErr . contains ( " ... - no such file(s) " ) ;
}
QString PerforcePlugin : : findTopLevelForDirectory ( const QString & /* dir */ ) const
{
// First check with p4 client -o
2008-12-04 16:24:15 +01:00
PerforceResponse result = runP4Cmd ( QStringList ( ) < < QLatin1String ( " client " ) < < QLatin1String ( " -o " ) , QStringList ( ) , 0u ) ;
2008-12-02 12:01:29 +01:00
if ( result . error )
return QString : : null ;
QRegExp regExp ( QLatin1String ( " ( \\ n| \\ r \\ n| \\ r) Root : \ \ s * ( . * ) ( \ \ n | \ \ r \ \ n | \ \ r ) " )) ;
2008-12-09 15:25:01 +01:00
QTC_ASSERT ( regExp . isValid ( ) , /**/ ) ;
2008-12-02 12:01:29 +01:00
regExp . setMinimal ( true ) ;
if ( regExp . indexIn ( result . stdOut ) ! = - 1 ) {
QString file = regExp . cap ( 2 ) . trimmed ( ) ;
if ( QFileInfo ( file ) . exists ( ) )
return file ;
}
return QString : : null ;
}
bool PerforcePlugin : : vcsOpen ( const QString & fileName )
{
2008-12-04 16:24:15 +01:00
PerforceResponse result = runP4Cmd ( QStringList ( ) < < QLatin1String ( " edit " ) < < QDir : : toNativeSeparators ( fileName ) , QStringList ( ) ,
CommandToWindow | StdOutToWindow | StdErrToWindow | ErrorToWindow ) ;
2008-12-02 12:01:29 +01:00
return ! result . error ;
}
bool PerforcePlugin : : vcsAdd ( const QString & fileName )
{
2008-12-04 16:24:15 +01:00
PerforceResponse result = runP4Cmd ( QStringList ( ) < < QLatin1String ( " add " ) < < fileName , QStringList ( ) ,
CommandToWindow | StdOutToWindow | StdErrToWindow | ErrorToWindow ) ;
2008-12-02 12:01:29 +01:00
return ! result . error ;
}
bool PerforcePlugin : : vcsDelete ( const QString & fileName )
{
2008-12-04 16:24:15 +01:00
PerforceResponse result = runP4Cmd ( QStringList ( ) < < QLatin1String ( " revert " ) < < fileName , QStringList ( ) ,
CommandToWindow | StdOutToWindow | StdErrToWindow | ErrorToWindow ) ;
PerforceResponse result2 = runP4Cmd ( QStringList ( ) < < QLatin1String ( " delete " ) < < fileName , QStringList ( ) ,
CommandToWindow | StdOutToWindow | StdErrToWindow | ErrorToWindow ) ;
2008-12-02 12:01:29 +01:00
// 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 ! ( result . error & & result2 . error ) ;
}
2009-08-17 09:49:56 +02:00
static QString formatCommand ( const QString & cmd , const QStringList & args )
{
const QChar blank = QLatin1Char ( ' ' ) ;
QString command = cmd ;
command + = blank ;
command + = args . join ( QString ( blank ) ) ;
return PerforcePlugin : : tr ( " Executing: %1 \n " ) . arg ( command ) ;
}
2008-12-02 12:01:29 +01:00
PerforceResponse PerforcePlugin : : runP4Cmd ( const QStringList & args ,
const QStringList & extraArgs ,
2008-12-04 16:24:15 +01:00
unsigned logFlags ,
2008-12-02 12:01:29 +01:00
QTextCodec * outputCodec ) const
{
if ( Perforce : : Constants : : debug )
qDebug ( ) < < " PerforcePlugin::runP4Cmd " < < args < < extraArgs < < debugCodec ( outputCodec ) ;
PerforceResponse response ;
response . error = true ;
2009-08-10 15:46:45 +02:00
VCSBase : : VCSBaseOutputWindow * outputWindow = VCSBase : : VCSBaseOutputWindow : : instance ( ) ;
2009-05-28 10:30:10 +02:00
if ( ! checkP4Configuration ( & response . message ) ) {
2009-08-10 15:46:45 +02:00
outputWindow - > appendError ( response . message ) ;
2008-12-02 12:01:29 +01:00
return response ;
}
// handle extra args
QTemporaryFile tempfile ;
tempfile . setAutoRemove ( true ) ;
const QChar newLine = QLatin1Char ( ' \n ' ) ;
const QChar blank = QLatin1Char ( ' ' ) ;
2009-02-19 16:11:29 +01:00
QStringList actualArgs = m_settings . basicP4Args ( ) ;
2008-12-02 12:01:29 +01:00
if ( ! extraArgs . isEmpty ( ) ) {
if ( tempfile . open ( ) ) {
QTextStream stream ( & tempfile ) ;
stream < < extraArgs . join ( QString ( newLine ) ) ;
actualArgs < < QLatin1String ( " -x " ) < < tempfile . fileName ( ) ;
tempfile . close ( ) ;
} else {
qWarning ( ) < < " Could not create temporary file. Appending all file names to command line. " ;
actualArgs < < extraArgs ;
}
}
actualArgs < < args ;
2009-08-17 09:49:56 +02:00
if ( logFlags & CommandToWindow )
outputWindow - > appendCommand ( formatCommand ( m_settings . p4Command ( ) , actualArgs ) ) ;
2008-12-02 12:01:29 +01:00
// Run, connect stderr to the output window
Core : : Utils : : SynchronousProcess process ;
process . setTimeout ( p4Timeout ) ;
process . setStdOutCodec ( outputCodec ) ;
process . setEnvironment ( environment ( ) ) ;
// connect stderr to the output window if desired
2008-12-04 16:24:15 +01:00
if ( logFlags & StdErrToWindow ) {
2008-12-02 12:01:29 +01:00
process . setStdErrBufferedSignalsEnabled ( true ) ;
2009-08-10 15:46:45 +02:00
connect ( & process , SIGNAL ( stdErrBuffered ( QString , bool ) ) , outputWindow , SLOT ( append ( QString ) ) ) ;
2008-12-02 12:01:29 +01:00
}
// connect stdout to the output window if desired
2008-12-04 16:24:15 +01:00
if ( logFlags & StdOutToWindow ) {
2008-12-02 12:01:29 +01:00
process . setStdOutBufferedSignalsEnabled ( true ) ;
2009-08-10 15:46:45 +02:00
connect ( & process , SIGNAL ( stdOutBuffered ( QString , bool ) ) , outputWindow , SLOT ( append ( QString ) ) ) ;
2008-12-02 12:01:29 +01:00
}
2009-02-19 16:11:29 +01:00
const Core : : Utils : : SynchronousProcessResponse sp_resp = process . run ( m_settings . p4Command ( ) , actualArgs ) ;
2008-12-02 12:01:29 +01:00
if ( Perforce : : Constants : : debug )
qDebug ( ) < < sp_resp ;
response . error = true ;
response . stdErr = sp_resp . stdErr ;
response . stdOut = sp_resp . stdOut ;
switch ( sp_resp . result ) {
case Core : : Utils : : SynchronousProcessResponse : : Finished :
response . error = false ;
break ;
case Core : : Utils : : SynchronousProcessResponse : : FinishedError :
response . message = tr ( " The process terminated with exit code %1. " ) . arg ( sp_resp . exitCode ) ;
break ;
case Core : : Utils : : SynchronousProcessResponse : : TerminatedAbnormally :
response . message = tr ( " The process terminated abnormally. " ) ;
break ;
case Core : : Utils : : SynchronousProcessResponse : : StartFailed :
2009-02-19 16:11:29 +01:00
response . message = tr ( " Could not start perforce '%1'. Please check your settings in the preferences. " ) . arg ( m_settings . p4Command ( ) ) ;
2008-12-02 12:01:29 +01:00
break ;
case Core : : Utils : : SynchronousProcessResponse : : Hang :
2008-12-04 16:24:15 +01:00
response . message = tr ( " Perforce did not respond within timeout limit (%1 ms). " ) . arg ( p4Timeout ) ;
2008-12-02 12:01:29 +01:00
break ;
}
2008-12-04 16:24:15 +01:00
if ( response . error ) {
if ( Perforce : : Constants : : debug )
qDebug ( ) < < response . message ;
if ( logFlags & ErrorToWindow )
2009-08-10 15:46:45 +02:00
outputWindow - > appendError ( response . message ) ;
2008-12-04 16:24:15 +01:00
}
2008-12-02 12:01:29 +01:00
return response ;
}
Core : : IEditor * PerforcePlugin : : showOutputInEditor ( const QString & title , const QString output ,
int editorType , QTextCodec * codec )
{
const VCSBase : : VCSBaseEditorParameters * params = findType ( editorType ) ;
2008-12-09 15:25:01 +01:00
QTC_ASSERT ( params , return 0 ) ;
2008-12-02 12:01:29 +01:00
const QString kind = QLatin1String ( params - > kind ) ;
if ( Perforce : : Constants : : debug )
qDebug ( ) < < " PerforcePlugin::showOutputInEditor " < < title < < kind < < " Size= " < < output . size ( ) < < " Type= " < < editorType < < debugCodec ( codec ) ;
QString s = title ;
2009-08-12 10:41:30 +02:00
Core : : IEditor * editor = Core : : EditorManager : : instance ( ) - > openEditorWithContents ( kind , & s , output ) ;
2009-01-21 15:52:34 +01:00
PerforceEditor * e = qobject_cast < PerforceEditor * > ( editor - > widget ( ) ) ;
2008-12-02 12:01:29 +01:00
if ( ! e )
return 0 ;
s . replace ( QLatin1Char ( ' ' ) , QLatin1Char ( ' _ ' ) ) ;
e - > setSuggestedFileName ( s ) ;
if ( codec )
e - > setCodec ( codec ) ;
2009-03-10 11:02:12 +01:00
Core : : IEditor * ie = e - > editableInterface ( ) ;
Core : : EditorManager : : instance ( ) - > activateEditor ( ie ) ;
return ie ;
2008-12-02 12:01:29 +01:00
}
QStringList PerforcePlugin : : environment ( ) const
{
QStringList newEnv = QProcess : : systemEnvironment ( ) ;
const QString name = " P4DIFF " ;
2009-01-21 15:52:34 +01:00
for ( int i = 0 ; i < newEnv . count ( ) ; + + i ) {
2008-12-02 12:01:29 +01:00
if ( newEnv . at ( i ) . startsWith ( name ) ) {
newEnv . removeAt ( i ) ;
return newEnv ;
}
}
return newEnv ;
}
void PerforcePlugin : : slotDiff ( const QStringList & files )
{
p4Diff ( files ) ;
}
void PerforcePlugin : : p4Diff ( const QStringList & files , QString diffname )
{
Core : : IEditor * editor = 0 ;
bool displayInEditor = true ;
Core : : IEditor * existingEditor = 0 ;
2009-01-20 11:52:04 +01:00
QTextCodec * codec = files . empty ( ) ? static_cast < QTextCodec * > ( 0 ) : VCSBase : : VCSBaseEditor : : getCodec ( files . front ( ) ) ;
2008-12-02 12:01:29 +01:00
if ( Perforce : : Constants : : debug )
qDebug ( ) < < Q_FUNC_INFO < < files < < debugCodec ( codec ) ;
// diff of a single file? re-use an existing view if possible to support the common
// usage pattern of continuously changing and diffing a file
if ( files . count ( ) = = 1 ) {
const QString fileName = files . at ( 0 ) ;
if ( diffname . isEmpty ( ) ) {
const QFileInfo fi ( fileName ) ;
diffname = fi . fileName ( ) ;
}
2009-01-21 15:52:34 +01:00
foreach ( Core : : IEditor * ed , Core : : EditorManager : : instance ( ) - > openedEditors ( ) ) {
2009-01-16 17:34:34 +01:00
if ( ed - > file ( ) - > property ( " originalFileName " ) . toString ( ) = = fileName ) {
2008-12-02 12:01:29 +01:00
existingEditor = ed ;
displayInEditor = false ;
break ;
}
}
}
2008-12-04 16:24:15 +01:00
const PerforceResponse result = runP4Cmd ( QStringList ( ) < < QLatin1String ( " diff " ) < < QLatin1String ( " -du " ) , files , CommandToWindow | StdErrToWindow | ErrorToWindow , codec ) ;
2008-12-02 12:01:29 +01:00
if ( result . error )
return ;
if ( displayInEditor )
editor = showOutputInEditor ( tr ( " p4 diff %1 " ) . arg ( diffname ) , result . stdOut , VCSBase : : DiffOutput , codec ) ;
if ( files . count ( ) = = 1 ) {
if ( displayInEditor & & editor ! = 0 ) {
2009-01-16 17:34:34 +01:00
editor - > file ( ) - > setProperty ( " originalFileName " , files . at ( 0 ) ) ;
2008-12-02 12:01:29 +01:00
} else if ( ! displayInEditor & & existingEditor ) {
if ( existingEditor ) {
existingEditor - > createNew ( result . stdOut ) ;
2009-01-26 16:36:02 +01:00
Core : : EditorManager : : instance ( ) - > activateEditor ( existingEditor ) ;
2008-12-02 12:01:29 +01:00
}
}
}
}
void PerforcePlugin : : describe ( const QString & source , const QString & n )
{
2009-01-20 11:52:04 +01:00
QTextCodec * codec = source . isEmpty ( ) ? static_cast < QTextCodec * > ( 0 ) : VCSBase : : VCSBaseEditor : : getCodec ( source ) ;
2008-12-02 12:01:29 +01:00
QStringList args ;
args < < QLatin1String ( " describe " ) < < QLatin1String ( " -du " ) < < n ;
2008-12-04 16:24:15 +01:00
const PerforceResponse result = runP4Cmd ( args , QStringList ( ) , CommandToWindow | StdErrToWindow | ErrorToWindow , codec ) ;
2008-12-02 12:01:29 +01:00
if ( ! result . error )
showOutputInEditor ( tr ( " p4 describe %1 " ) . arg ( n ) , result . stdOut , VCSBase : : DiffOutput , codec ) ;
}
void PerforcePlugin : : submitCurrentLog ( )
{
2009-03-20 10:16:18 +01:00
m_submitActionTriggered = true ;
2009-01-21 15:52:34 +01:00
Core : : EditorManager * em = Core : : EditorManager : : instance ( ) ;
2009-01-20 11:52:04 +01:00
em - > closeEditors ( QList < Core : : IEditor * > ( ) < < em - > currentEditor ( ) ) ;
2008-12-02 12:01:29 +01:00
}
2009-09-22 12:23:44 +02:00
void PerforcePlugin : : cleanCommitMessageFile ( )
2009-03-20 16:52:22 +01:00
{
2009-09-22 12:23:44 +02:00
if ( ! m_commitMessageFileName . isEmpty ( ) ) {
QFile : : remove ( m_commitMessageFileName ) ;
m_commitMessageFileName . clear ( ) ;
2009-03-20 16:52:22 +01:00
}
}
2009-09-22 12:23:44 +02:00
bool PerforcePlugin : : isCommitEditorOpen ( ) const
{
return ! m_commitMessageFileName . isEmpty ( ) ;
}
2008-12-02 12:01:29 +01:00
bool PerforcePlugin : : editorAboutToClose ( Core : : IEditor * editor )
{
2009-09-22 12:23:44 +02:00
if ( ! editor | | ! isCommitEditorOpen ( ) )
2008-12-02 12:01:29 +01:00
return true ;
2009-01-20 11:52:04 +01:00
Core : : ICore * core = Core : : ICore : : instance ( ) ;
2008-12-02 12:01:29 +01:00
Core : : IFile * fileIFace = editor - > file ( ) ;
if ( ! fileIFace )
return true ;
2009-03-19 17:40:01 +01:00
const PerforceSubmitEditor * perforceEditor = qobject_cast < PerforceSubmitEditor * > ( editor ) ;
if ( ! perforceEditor )
return true ;
2008-12-02 12:01:29 +01:00
QFileInfo editorFile ( fileIFace - > fileName ( ) ) ;
2009-09-22 12:23:44 +02:00
QFileInfo changeFile ( m_commitMessageFileName ) ;
2009-03-20 10:16:18 +01:00
if ( editorFile . absoluteFilePath ( ) = = changeFile . absoluteFilePath ( ) ) {
// Prompt the user. Force a prompt unless submit was actually invoked (that
// is, the editor was closed or shutdown).
2009-06-19 16:34:38 +02:00
bool wantsPrompt = m_settings . promptToSubmit ( ) ;
2009-03-19 17:40:01 +01:00
const VCSBase : : VCSBaseSubmitEditor : : PromptSubmitResult answer =
perforceEditor - > promptSubmit ( tr ( " Closing p4 Editor " ) ,
tr ( " Do you want to submit this change list? " ) ,
2009-03-20 10:16:18 +01:00
tr ( " The commit message check failed. Do you want to submit this change list " ) ,
2009-06-19 16:34:38 +02:00
& wantsPrompt , ! m_submitActionTriggered ) ;
2009-03-20 10:16:18 +01:00
m_submitActionTriggered = false ;
2009-03-19 17:40:01 +01:00
if ( answer = = VCSBase : : VCSBaseSubmitEditor : : SubmitCanceled )
2008-12-02 12:01:29 +01:00
return false ;
2009-06-19 16:34:38 +02:00
// Set without triggering the checking mechanism
if ( wantsPrompt ! = m_settings . promptToSubmit ( ) ) {
m_settings . setPromptToSubmit ( wantsPrompt ) ;
m_settings . toSettings ( Core : : ICore : : instance ( ) - > settings ( ) ) ;
}
2009-01-20 11:52:04 +01:00
core - > fileManager ( ) - > blockFileChange ( fileIFace ) ;
2008-12-02 12:01:29 +01:00
fileIFace - > save ( ) ;
2009-01-20 11:52:04 +01:00
core - > fileManager ( ) - > unblockFileChange ( fileIFace ) ;
2009-03-19 17:40:01 +01:00
if ( answer = = VCSBase : : VCSBaseSubmitEditor : : SubmitConfirmed ) {
2009-09-22 12:23:44 +02:00
QFile commitMessageFile ( m_commitMessageFileName ) ;
if ( ! commitMessageFile . open ( QIODevice : : ReadOnly | QIODevice : : Text ) ) {
2009-08-17 09:49:56 +02:00
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendError ( tr ( " Cannot open temporary file. " ) ) ;
return false ;
}
2009-09-22 12:23:44 +02:00
QByteArray change = commitMessageFile . readAll ( ) ;
commitMessageFile . close ( ) ;
2009-05-28 10:30:10 +02:00
QString errorMessage ;
if ( ! checkP4Configuration ( & errorMessage ) ) {
2009-08-10 15:46:45 +02:00
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendError ( errorMessage ) ;
2008-12-02 12:01:29 +01:00
return false ;
}
QProcess proc ;
proc . setEnvironment ( environment ( ) ) ;
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
2009-08-17 09:49:56 +02:00
QStringList submitArgs = m_settings . basicP4Args ( ) ;
submitArgs < < QLatin1String ( " submit " ) < < QLatin1String ( " -i " ) ;
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendCommand ( formatCommand ( m_settings . p4Command ( ) , submitArgs ) ) ;
proc . start ( m_settings . p4Command ( ) , submitArgs ) ;
2009-01-12 17:44:04 +01:00
if ( ! proc . waitForStarted ( p4Timeout ) ) {
2009-08-10 15:46:45 +02:00
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendError ( tr ( " Cannot execute p4 submit. " ) ) ;
2008-12-02 12:01:29 +01:00
QApplication : : restoreOverrideCursor ( ) ;
return false ;
}
proc . write ( change ) ;
proc . closeWriteChannel ( ) ;
if ( ! proc . waitForFinished ( ) ) {
2009-08-10 15:46:45 +02:00
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendError ( tr ( " Cannot execute p4 submit. " ) ) ;
2008-12-02 12:01:29 +01:00
QApplication : : restoreOverrideCursor ( ) ;
2009-08-17 09:49:56 +02:00
return false ;
}
const int exitCode = proc . exitCode ( ) ;
if ( exitCode ) {
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendError ( tr ( " p4 submit failed (exit code %1). " ) . arg ( exitCode ) ) ;
QApplication : : restoreOverrideCursor ( ) ;
2008-12-02 12:01:29 +01:00
return false ;
}
2009-08-10 15:46:45 +02:00
const QString output = QString : : fromLocal8Bit ( proc . readAll ( ) ) ;
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > append ( output ) ;
2009-03-20 10:16:18 +01:00
if ( output . contains ( QLatin1String ( " Out of date files must be resolved or reverted) " ) ) ) {
QMessageBox : : warning ( editor - > widget ( ) , tr ( " Pending change " ) , tr ( " Could not submit the change, because your workspace was out of date. Created a pending submit instead. " ) ) ;
2008-12-02 12:01:29 +01:00
}
QApplication : : restoreOverrideCursor ( ) ;
}
2009-09-22 12:23:44 +02:00
cleanCommitMessageFile ( ) ;
2008-12-02 12:01:29 +01:00
}
return true ;
}
void PerforcePlugin : : openFiles ( const QStringList & files )
{
2009-01-21 15:52:34 +01:00
Core : : EditorManager * em = Core : : EditorManager : : instance ( ) ;
foreach ( const QString & s , files )
2009-01-20 11:52:04 +01:00
em - > openEditor ( clientFilePath ( s ) ) ;
em - > ensureEditorManagerVisible ( ) ;
2008-12-02 12:01:29 +01:00
}
QString PerforcePlugin : : clientFilePath ( const QString & serverFilePath )
{
2009-05-28 10:30:10 +02:00
if ( ! checkP4Configuration ( ) )
2008-12-09 15:25:01 +01:00
return QString ( ) ;
2008-12-02 12:01:29 +01:00
QApplication : : setOverrideCursor ( Qt : : WaitCursor ) ;
QProcess proc ;
proc . setEnvironment ( environment ( ) ) ;
2009-02-19 16:11:29 +01:00
proc . start ( m_settings . p4Command ( ) ,
m_settings . basicP4Args ( ) < < QLatin1String ( " fstat " ) < < serverFilePath ) ;
2008-12-02 12:01:29 +01:00
2008-12-09 15:25:01 +01:00
QString path ;
2008-12-02 12:01:29 +01:00
if ( proc . waitForFinished ( 3000 ) ) {
QString output = QString : : fromUtf8 ( proc . readAllStandardOutput ( ) ) ;
if ( ! output . isEmpty ( ) ) {
QRegExp r ( QLatin1String ( " \\ . \\ . \\ . \\ sclientFile \\ s(.+) \ n " )) ;
r . setMinimal ( true ) ;
if ( r . indexIn ( output ) ! = - 1 )
path = r . cap ( 1 ) . trimmed ( ) ;
}
}
QApplication : : restoreOverrideCursor ( ) ;
return path ;
}
QString PerforcePlugin : : currentFileName ( )
{
2009-01-20 11:52:04 +01:00
QString fileName = Core : : ICore : : instance ( ) - > fileManager ( ) - > currentFile ( ) ;
2008-12-02 12:01:29 +01:00
// TODO: Use FileManager::fixPath
const QFileInfo fileInfo ( fileName ) ;
if ( fileInfo . exists ( ) )
fileName = fileInfo . absoluteFilePath ( ) ;
fileName = QDir : : toNativeSeparators ( fileName ) ;
return fileName ;
}
2009-05-28 10:30:10 +02:00
bool PerforcePlugin : : checkP4Configuration ( QString * errorMessage /* = 0 */ ) const
2008-12-02 12:01:29 +01:00
{
2009-05-28 10:30:10 +02:00
if ( m_settings . isValid ( ) )
return true ;
if ( errorMessage )
* errorMessage = tr ( " Invalid configuration: %1 " ) . arg ( m_settings . errorString ( ) ) ;
return false ;
2008-12-02 12:01:29 +01:00
}
QString PerforcePlugin : : pendingChangesData ( )
{
QString data ;
2009-05-28 10:30:10 +02:00
if ( ! checkP4Configuration ( ) )
2008-12-02 12:01:29 +01:00
return data ;
QString user ;
QProcess proc ;
proc . setEnvironment ( environment ( ) ) ;
2009-02-19 16:11:29 +01:00
proc . start ( m_settings . p4Command ( ) ,
m_settings . basicP4Args ( ) < < QLatin1String ( " info " ) ) ;
2008-12-02 12:01:29 +01:00
if ( proc . waitForFinished ( 3000 ) ) {
QString output = QString : : fromUtf8 ( proc . readAllStandardOutput ( ) ) ;
if ( ! output . isEmpty ( ) ) {
QRegExp r ( QLatin1String ( " User \\ sname: \\ s( \\ S+) \ \ s * \ n " )) ;
r . setMinimal ( true ) ;
if ( r . indexIn ( output ) ! = - 1 )
user = r . cap ( 1 ) . trimmed ( ) ;
}
}
if ( user . isEmpty ( ) )
return data ;
2009-02-19 16:11:29 +01:00
proc . start ( m_settings . p4Command ( ) ,
m_settings . basicP4Args ( ) < < QLatin1String ( " changes " ) < < QLatin1String ( " -s " ) < < QLatin1String ( " pending " ) < < QLatin1String ( " -u " ) < < user ) ;
2008-12-02 12:01:29 +01:00
if ( proc . waitForFinished ( 3000 ) )
data = QString : : fromUtf8 ( proc . readAllStandardOutput ( ) ) ;
return data ;
}
PerforcePlugin : : ~ PerforcePlugin ( )
{
}
2009-02-19 16:11:29 +01:00
const PerforceSettings & PerforcePlugin : : settings ( ) const
2008-12-02 12:01:29 +01:00
{
return m_settings ;
}
2009-05-28 10:30:10 +02:00
void PerforcePlugin : : setSettings ( const Settings & newSettings )
2008-12-02 12:01:29 +01:00
{
2009-05-28 10:30:10 +02:00
if ( newSettings ! = m_settings . settings ( ) ) {
m_settings . setSettings ( newSettings ) ;
2009-02-19 16:11:29 +01:00
m_settings . toSettings ( Core : : ICore : : instance ( ) - > settings ( ) ) ;
2008-12-02 12:01:29 +01:00
}
}
// Map a perforce name "//xx" to its real name in the file system
QString PerforcePlugin : : fileNameFromPerforceName ( const QString & perforceName ,
QString * errorMessage ) const
{
// All happy, already mapped
if ( ! perforceName . startsWith ( QLatin1String ( " // " ) ) )
return perforceName ;
// "where" remaps the file to client file tree
QProcess proc ;
2009-02-19 16:11:29 +01:00
QStringList args ( m_settings . basicP4Args ( ) ) ;
2008-12-02 12:01:29 +01:00
args < < QLatin1String ( " where " ) < < perforceName ;
2009-02-19 16:11:29 +01:00
proc . start ( m_settings . p4Command ( ) , args ) ;
2008-12-02 12:01:29 +01:00
if ( ! proc . waitForFinished ( ) ) {
* errorMessage = tr ( " Timeout waiting for \" where \" (%1). " ) . arg ( perforceName ) ;
return QString ( ) ;
}
QString output = QString : : fromLocal8Bit ( proc . readAllStandardOutput ( ) ) ;
if ( output . endsWith ( QLatin1Char ( ' \r ' ) ) )
output . chop ( 1 ) ;
if ( output . endsWith ( QLatin1Char ( ' \n ' ) ) )
output . chop ( 1 ) ;
if ( output . isEmpty ( ) ) {
* errorMessage = tr ( " Error running \" where \" on %1: The file is not mapped " ) . arg ( perforceName ) ;
return QString ( ) ;
}
const QString rc = output . mid ( output . lastIndexOf ( QLatin1Char ( ' ' ) ) + 1 ) ;
if ( Perforce : : Constants : : debug )
qDebug ( ) < < " fileNameFromPerforceName " < < perforceName < < rc ;
return rc ;
}
2008-12-09 15:25:01 +01:00
PerforcePlugin * PerforcePlugin : : perforcePluginInstance ( )
{
QTC_ASSERT ( m_perforcePluginInstance , return 0 ) ;
return m_perforcePluginInstance ;
}
2008-12-02 12:01:29 +01:00
Q_EXPORT_PLUGIN ( PerforcePlugin )