Commit 0977c04f authored by Jeremy Whiting's avatar Jeremy Whiting

Use external libkomparediff2.

Get actions from KompareModelList's actionCollection and add them to ours in KomparePart.
parent 857f533f
......@@ -5,18 +5,18 @@ project(kompare)
find_package(KDE4 REQUIRED)
include(KDE4Defaults)
add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES})
find_package(LibKompareDiff2 REQUIRED)
include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES} ${LIBKOMPAREDIFF2_INCLUDE_DIR})
add_subdirectory( doc )
add_subdirectory( interfaces )
add_subdirectory( libdiff2 )
add_subdirectory( libdialogpages )
add_subdirectory( komparenavtreepart )
add_subdirectory( komparepart )
add_subdirectory( pics )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/komparepart
${CMAKE_CURRENT_SOURCE_DIR}/libdiff2
${CMAKE_CURRENT_SOURCE_DIR}/libdialogpages
${CMAKE_CURRENT_SOURCE_DIR}/interfaces
${CMAKE_CURRENT_SOURCE_DIR}/komparenavtreepart
......
......@@ -81,8 +81,12 @@ KomparePart::KomparePart( QWidget *parentWidget, QObject *parent, const QVariant
m_splitter = m_view->splitter();
// This creates the "Model creator" and connects the signals and slots
m_modelList = new Diff2::KompareModelList( m_diffSettings, m_splitter, this, "komparemodellist" );
m_modelList = new Diff2::KompareModelList( m_diffSettings, m_splitter, this, "komparemodellist" , KParts::ReadWritePart::isReadWrite());
Q_FOREACH(QAction* action, m_modelList->actionCollection()->actions())
{
actionCollection()->addAction(action->objectName(), action);
}
connect( m_modelList, SIGNAL(status( Kompare::Status )),
this, SLOT(slotSetStatus( Kompare::Status )) );
connect( m_modelList, SIGNAL(setStatusBarModelInfo( int, int, int, int, int )),
......
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../libdiff2 )
########### next target ###############
set(dialogpages_PART_SRCS
settingsbase.cpp
diffsettings.cpp
filessettings.cpp
viewsettings.cpp
pagebase.cpp
......@@ -17,7 +12,7 @@ set(dialogpages_PART_SRCS
kde4_add_library(komparedialogpages SHARED ${dialogpages_PART_SRCS})
target_link_libraries(komparedialogpages ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} )
target_link_libraries(komparedialogpages ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${LIBKOMPAREDIFF2_LIBRARIES})
set_target_properties(komparedialogpages PROPERTIES VERSION ${GENERIC_LIB_VERSION}
SOVERSION ${GENERIC_LIB_SOVERSION} )
......
/***************************************************************************
diffsettings.cpp
----------------
begin : Sun Mar 4 2001
Copyright 2001-2004 Otto Bruggeman <otto.bruggeman@home.nl>
Copyright 2007 Kevin Kofler <kevin.kofler@chello.at>
****************************************************************************/
/***************************************************************************
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
****************************************************************************/
#include "diffsettings.h"
#include <kconfig.h>
#include <kconfiggroup.h>
DiffSettings::DiffSettings( QWidget* parent )
: SettingsBase( parent ),
m_linesOfContext( 0 ),
m_format( Kompare::Unified ),
m_largeFiles( false ),
m_ignoreWhiteSpace( false ),
m_ignoreAllWhiteSpace( false ),
m_ignoreEmptyLines( false ),
m_ignoreChangesDueToTabExpansion( false ),
m_createSmallerDiff( false ),
m_ignoreChangesInCase( false ),
m_showCFunctionChange( false ),
m_convertTabsToSpaces( false ),
m_ignoreRegExp( false ),
m_recursive( false ),
m_newFiles( false ),
m_excludeFilePattern( false ),
m_excludeFilesFile( false )
{
}
DiffSettings::~DiffSettings()
{
}
void DiffSettings::loadSettings( KConfig* config )
{
KConfigGroup group( config, "Diff Options" );
m_diffProgram = group.readEntry ( "DiffProgram", "" );
m_linesOfContext = group.readEntry ( "LinesOfContext", 3 );
m_largeFiles = group.readEntry( "LargeFiles", true );
m_ignoreWhiteSpace = group.readEntry( "IgnoreWhiteSpace", false );
m_ignoreAllWhiteSpace = group.readEntry( "IgnoreAllWhiteSpace", false );
m_ignoreEmptyLines = group.readEntry( "IgnoreEmptyLines", false );
m_ignoreChangesDueToTabExpansion = group.readEntry( "IgnoreChangesDueToTabExpansion", false );
m_ignoreChangesInCase = group.readEntry( "IgnoreChangesInCase", false );
m_ignoreRegExp = group.readEntry( "IgnoreRegExp", false );
m_ignoreRegExpText = group.readEntry ( "IgnoreRegExpText", "" );
m_ignoreRegExpTextHistory = group.readEntry( "IgnoreRegExpTextHistory", QStringList() );
m_createSmallerDiff = group.readEntry( "CreateSmallerDiff", true );
m_convertTabsToSpaces = group.readEntry( "ConvertTabsToSpaces", false );
m_showCFunctionChange = group.readEntry( "ShowCFunctionChange", false );
m_recursive = group.readEntry( "CompareRecursively", true );
m_newFiles = group.readEntry( "NewFiles", true );
m_format = static_cast<Kompare::Format>( group.readEntry( "Format", (int) Kompare::Unified ) );
KConfigGroup group2 ( config, "Exclude File Options" );
m_excludeFilePattern = group2.readEntry( "Pattern", false );
m_excludeFilePatternList = group2.readEntry( "PatternList", QStringList() );
m_excludeFilesFile = group2.readEntry( "File", false );
m_excludeFilesFileURL = group2.readEntry ( "FileURL", "" );
m_excludeFilesFileHistoryList = group2.readEntry( "FileHistoryList", QStringList() );
}
void DiffSettings::saveSettings( KConfig* config )
{
KConfigGroup group( config, "Diff Options" );
group.writeEntry( "DiffProgram", m_diffProgram );
group.writeEntry( "LinesOfContext", m_linesOfContext );
group.writeEntry( "Format", QString(m_format) );
group.writeEntry( "LargeFiles", m_largeFiles );
group.writeEntry( "IgnoreWhiteSpace", m_ignoreWhiteSpace );
group.writeEntry( "IgnoreAllWhiteSpace", m_ignoreAllWhiteSpace );
group.writeEntry( "IgnoreEmptyLines", m_ignoreEmptyLines );
group.writeEntry( "IgnoreChangesInCase", m_ignoreChangesInCase );
group.writeEntry( "IgnoreChangesDueToTabExpansion", m_ignoreChangesDueToTabExpansion );
group.writeEntry( "IgnoreRegExp", m_ignoreRegExp );
group.writeEntry( "IgnoreRegExpText", m_ignoreRegExpText );
group.writeEntry( "IgnoreRegExpTextHistory", m_ignoreRegExpTextHistory );
group.writeEntry( "CreateSmallerDiff", m_createSmallerDiff );
group.writeEntry( "ConvertTabsToSpaces", m_convertTabsToSpaces );
group.writeEntry( "ShowCFunctionChange", m_showCFunctionChange );
group.writeEntry( "CompareRecursively", m_recursive );
group.writeEntry( "NewFiles", m_newFiles );
KConfigGroup group2( config, "Exclude File Options" );
group2.writeEntry( "Pattern", m_excludeFilePattern );
group2.writeEntry( "PatternList", m_excludeFilePatternList );
group2.writeEntry( "File", m_excludeFilesFile );
group2.writeEntry( "FileURL", m_excludeFilesFileURL );
group2.writeEntry( "FileHistoryList", m_excludeFilesFileHistoryList );
config->sync();
}
#include "diffsettings.moc"
/***************************************************************************
diffsettings.h
--------------
begin : Sun Mar 4 2001
Copyright 2001-2003 Otto Bruggeman <otto.bruggeman@home.nl>
Copyright 2001-2003 John Firebaugh <jfirebaugh@kde.org>
****************************************************************************/
/***************************************************************************
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
***************************************************************************/
#ifndef DIFFSETTINGS_H
#define DIFFSETTINGS_H
#include <QtCore/QStringList>
#include <QtGui/QWidget>
#include "kompare.h"
#include "settingsbase.h"
#include "dialogpagesexport.h"
class DIALOGPAGES_EXPORT DiffSettings : public SettingsBase
{
Q_OBJECT
public:
DiffSettings( QWidget* parent );
virtual ~DiffSettings();
public:
// some virtual functions that will be overloaded from the base class
virtual void loadSettings( KConfig* config );
virtual void saveSettings( KConfig* config );
public:
QString m_diffProgram;
int m_linesOfContext;
Kompare::Format m_format;
bool m_largeFiles; // -H
bool m_ignoreWhiteSpace; // -b
bool m_ignoreAllWhiteSpace; // -w
bool m_ignoreEmptyLines; // -B
bool m_ignoreChangesDueToTabExpansion; // -E
bool m_createSmallerDiff; // -d
bool m_ignoreChangesInCase; // -i
bool m_showCFunctionChange; // -p
bool m_convertTabsToSpaces; // -t
bool m_ignoreRegExp; // -I
QString m_ignoreRegExpText; // the RE for -I
QStringList m_ignoreRegExpTextHistory;
bool m_recursive; // -r
bool m_newFiles; // -N
// bool m_allText; // -a
bool m_excludeFilePattern; // -x
QStringList m_excludeFilePatternList; // The list of patterns for -x
bool m_excludeFilesFile; // -X
QString m_excludeFilesFileURL; // The filename to -X
QStringList m_excludeFilesFileHistoryList; // The history list of filenames
};
#endif
/***************************************************************************
settingsbase.cpp
----------------
begin : Sun Mar 4 2001
Copyright 2001 Otto Bruggeman <otto.bruggeman@home.nl>
Copyright 2001 John Firebaugh <jfirebaugh@kde.org>
****************************************************************************/
/***************************************************************************
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
***************************************************************************/
#include "settingsbase.h"
#include <QtGui/QWidget>
SettingsBase::SettingsBase( QWidget* parent ) : QObject( parent )
{
}
SettingsBase::~SettingsBase()
{
}
void SettingsBase::loadSettings( KConfig* /* config */ )
{
}
void SettingsBase::saveSettings( KConfig* /* config */ )
{
}
#include "settingsbase.moc"
/***************************************************************************
settingsbase.h
--------------
begin : Sun Mar 4 2001
Copyright 2001 Otto Bruggeman <otto.bruggeman@home.nl>
Copyright 2001 John Firebaugh <jfirebaugh@kde.org>
****************************************************************************/
/***************************************************************************
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
***************************************************************************/
#ifndef SETTINGSBASE_H
#define SETTINGSBASE_H
#include <QtCore/QObject>
#include "kompare.h"
class QWidget;
class KConfig;
class SettingsBase : public QObject
{
Q_OBJECT
public:
SettingsBase( QWidget* parent );
~SettingsBase();
public:
virtual void loadSettings( KConfig* config );
virtual void saveSettings( KConfig* config );
};
#endif
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../libdialogpages ${CMAKE_CURRENT_SOURCE_DIR}/../komparepart ${CMAKE_CURRENT_SOURCE_DIR}/../interfaces )
########### next target ###############
set(diff2_PART_SRCS
kompareprocess.cpp
komparemodellist.cpp
diffmodellist.cpp
diffmodel.cpp
difference.cpp
diffhunk.cpp
parser.cpp
parserbase.cpp
cvsdiffparser.cpp
diffparser.cpp
perforceparser.cpp
stringlistpair.cpp)
kde4_add_library(komparediff2 SHARED ${diff2_PART_SRCS})
target_link_libraries(komparediff2 ${KDE4_KDECORE_LIBS} ${KDE4_KPARTS_LIBS})
set_target_properties(komparediff2 PROPERTIES VERSION ${GENERIC_LIB_VERSION}
SOVERSION ${GENERIC_LIB_SOVERSION} )
install(TARGETS komparediff2 ${INSTALL_TARGETS_DEFAULT_ARGS})
add_subdirectory(tests)
/**************************************************************************
** cvsdiffparser.cpp
** -----------------
** begin : Sun Aug 4 15:05:35 2002
** Copyright 2002-2004 Otto Bruggeman <otto.bruggeman@home.nl>
***************************************************************************/
/***************************************************************************
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** ( at your option ) any later version.
**
***************************************************************************/
#include "cvsdiffparser.h"
#include <QtCore/QRegExp>
#include <kdebug.h>
#include "komparemodellist.h"
using namespace Diff2;
CVSDiffParser::CVSDiffParser( const KompareModelList* list, const QStringList& diff ) : ParserBase( list, diff )
{
// The regexps needed for context cvs diff parsing, the rest is the same as in parserbase.cpp
// third capture in header1 is non optional for cvs diff, it is the revision
m_contextDiffHeader1.setPattern( "\\*\\*\\* ([^\\t]+)\\t([^\\t]+)\\t(.*)\\n" );
m_contextDiffHeader2.setPattern( "--- ([^\\t]+)\\t([^\\t]+)(|\\t(.*))\\n" );
m_normalDiffHeader.setPattern( "Index: (.*)\\n" );
}
CVSDiffParser::~CVSDiffParser()
{
}
enum Kompare::Format CVSDiffParser::determineFormat()
{
// kDebug(8101) << "Determining the format of the CVSDiff";
QRegExp normalRE ( "[0-9]+[0-9,]*[acd][0-9]+[0-9,]*" );
QRegExp unifiedRE( "^--- [^\\t]+\\t" );
QRegExp contextRE( "^\\*\\*\\* [^\\t]+\\t" );
QRegExp rcsRE ( "^[acd][0-9]+ [0-9]+" );
QRegExp edRE ( "^[0-9]+[0-9,]*[acd]" );
QStringList::ConstIterator it = m_diffLines.begin();
while( it != m_diffLines.end() )
{
if( (*it).indexOf( normalRE, 0 ) == 0 )
{
// kDebug(8101) << "Difflines are from a Normal diff...";
return Kompare::Normal;
}
else if( (*it).indexOf( unifiedRE, 0 ) == 0 )
{
// kDebug(8101) << "Difflines are from a Unified diff...";
return Kompare::Unified;
}
else if( (*it).indexOf( contextRE, 0 ) == 0 )
{
// kDebug(8101) << "Difflines are from a Context diff...";
return Kompare::Context;
}
else if( (*it).indexOf( rcsRE, 0 ) == 0 )
{
// kDebug(8101) << "Difflines are from a RCS diff...";
return Kompare::RCS;
}
else if( (*it).indexOf( edRE, 0 ) == 0 )
{
// kDebug(8101) << "Difflines are from an ED diff...";
return Kompare::Ed;
}
++it;
}
// kDebug(8101) << "Difflines are from an unknown diff...";
return Kompare::UnknownFormat;
}
bool CVSDiffParser::parseNormalDiffHeader()
{
kDebug(8101) << "CVSDiffParser::parseNormalDiffHeader()";
bool result = false;
QStringList::ConstIterator diffEnd = m_diffLines.end();
while ( m_diffIterator != diffEnd )
{
if ( m_normalDiffHeader.exactMatch( *m_diffIterator ) )
{
kDebug(8101) << "Matched length Header = " << m_normalDiffHeader.matchedLength();
kDebug(8101) << "Matched string Header = " << m_normalDiffHeader.cap( 0 );
m_currentModel = new DiffModel();
m_currentModel->setSourceFile ( m_normalDiffHeader.cap( 1 ) );
m_currentModel->setDestinationFile ( m_normalDiffHeader.cap( 1 ) );
result = true;
++m_diffIterator;
break;
}
else
{
kDebug(8101) << "No match for: " << ( *m_diffIterator );
}
++m_diffIterator;
}
if ( result == false )
{
// Set this to the first line again and hope it is a single file diff
m_diffIterator = m_diffLines.begin();
m_currentModel = new DiffModel();
m_singleFileDiff = true;
}
return result;
}
bool CVSDiffParser::parseEdDiffHeader()
{
return false;
}
bool CVSDiffParser::parseRCSDiffHeader()
{
return false;
}
bool CVSDiffParser::parseEdHunkHeader()
{
return false;
}
bool CVSDiffParser::parseRCSHunkHeader()
{
return false;
}
bool CVSDiffParser::parseEdHunkBody()
{
return false;
}
bool CVSDiffParser::parseRCSHunkBody()
{
return false;
}
/**************************************************************************
** cvsdiffparser.h
** ----------------
** begin : Sun Aug 4 15:05:35 2002
** Copyright 2002-2004 Otto Bruggeman <otto.bruggeman@home.nl>
***************************************************************************/
/***************************************************************************
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** ( at your option ) any later version.
**
***************************************************************************/
#ifndef CVSDIFF_PARSER_H
#define CVSDIFF_PARSER_H
#include <QtCore/QRegExp>
#include "parserbase.h"
namespace Diff2
{
class KompareModelList;
class CVSDiffParser : public ParserBase
{
public:
CVSDiffParser( const KompareModelList* list, const QStringList& diff );
virtual ~CVSDiffParser();
protected:
virtual enum Kompare::Format determineFormat();
protected:
// virtual bool parseContextDiffHeader();
virtual bool parseEdDiffHeader();
virtual bool parseNormalDiffHeader();
virtual bool parseRCSDiffHeader();
// virtual bool parseUnifiedDiffHeader();
// virtual bool parseContextHunkHeader();
virtual bool parseEdHunkHeader();
// virtual bool parseNormalHunkHeader();
virtual bool parseRCSHunkHeader();
// virtual bool parseUnifiedHunkHeader();
// virtual bool parseContextHunkBody();
virtual bool parseEdHunkBody();
// virtual bool parseNormalHunkBody();
virtual bool parseRCSHunkBody();
// virtual bool parseUnifiedHunkBody();
};
} // End of namespace Diff2
#endif
/***************************************************************************
* Copyright 2007 Andreas Pakulat <apaku@gmx.de> *
* Copyright 2006 Matt Rogers <mattr@kde.org> *
* Copyright 2004 Jarosław Staniek <staniek@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef LIBDIFF2EXPORT_H
#define LIBDIFF2EXPORT_H
/* needed for KDE_EXPORT macros */
#include <kdemacros.h>
#ifndef DIFF2_EXPORT
# ifdef MAKE_KOMPAREDIFF2_LIB
# define DIFF2_EXPORT KDE_EXPORT
# else
# define DIFF2_EXPORT KDE_IMPORT
# endif
#endif
#endif
/***************************************************************************
difference.cpp
--------------