TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.2KB

  1. /*
  2. This file is part of libtdepim.
  3. Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include <tqstringlist.h>
  18. #include <klocale.h>
  19. #include "genericdiffalgo.h"
  20. using namespace KSync;
  21. #define MAX( a, b ) ( a > b ? a : b )
  22. #ifndef KDE_USE_FINAL
  23. // With --enable-final, we get the (identical) compareString from
  24. // addresseediffalgo.cpp
  25. static bool compareString( const TQString &left, const TQString &right )
  26. {
  27. if ( left.isEmpty() && right.isEmpty() )
  28. return true;
  29. else
  30. return left == right;
  31. }
  32. #endif
  33. GenericDiffAlgo::GenericDiffAlgo( const TQString &leftData, const TQString &rightData )
  34. : mLeftData( leftData ), mRightData( rightData )
  35. {
  36. }
  37. void GenericDiffAlgo::run()
  38. {
  39. begin();
  40. TQStringList leftList = TQStringList::split( '\n', mLeftData, true );
  41. TQStringList rightList = TQStringList::split( '\n', mRightData, true );
  42. uint lines = MAX( leftList.count(), rightList.count() );
  43. for ( uint i = 0; i < lines; ++i ) {
  44. if ( i < leftList.count() && i < rightList.count() ) {
  45. if ( !compareString( leftList[ i ], rightList[ i ] ) )
  46. conflictField( i18n( "Line %1" ).tqarg( i ), leftList[ i ], rightList[ i ] );
  47. } else if ( i < leftList.count() && i >= rightList.count() ) {
  48. additionalLeftField( i18n( "Line %1" ).tqarg( i ), leftList[ i ] );
  49. } else if ( i >= leftList.count() && i < rightList.count() ) {
  50. additionalRightField( i18n( "Line %1" ).tqarg( i ), rightList[ i ] );
  51. }
  52. }
  53. end();
  54. }