directorymergewindow.cpp 101 KB
Newer Older
Joachim Eibl's avatar
Joachim Eibl committed
1
2
/***************************************************************************
                          directorymergewindow.cpp
Joachim Eibl's avatar
Joachim Eibl committed
3
                             -----------------
Joachim Eibl's avatar
Joachim Eibl committed
4
    begin                : Sat Oct 19 2002
Joachim Eibl's avatar
Joachim Eibl committed
5
6
    copyright            : (C) 2002-2005 by Joachim Eibl
    email                : joachim.eibl at gmx.de
Joachim Eibl's avatar
Joachim Eibl committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 "directorymergewindow.h"
#include "optiondialog.h"
#include <vector>
#include <map>

#include <qdir.h>
#include <qapplication.h>
#include <qpixmap.h>
#include <qimage.h>
Joachim Eibl's avatar
Joachim Eibl committed
27
28
29
30
31
32
33
34
35
36
37
//Added by qt3to4:
#include <QFocusEvent>
#include <QTextStream>
#include <Q3GridLayout>
#include <QKeyEvent>
#include <QEvent>
#include <Q3Frame>
#include <Q3ValueList>
#include <QResizeEvent>
#include <Q3PopupMenu>
#include <Q3VBoxLayout>
Joachim Eibl's avatar
Joachim Eibl committed
38
#include <kpopupmenu.h>
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
39
#include <kaction.h>
Joachim Eibl's avatar
Joachim Eibl committed
40
41
42
43
#include <qregexp.h>
#include <qmessagebox.h>
#include <qlayout.h>
#include <qlabel.h>
Joachim Eibl's avatar
Joachim Eibl committed
44
#include <q3table.h>
Joachim Eibl's avatar
Joachim Eibl committed
45
#include <qsplitter.h>
Joachim Eibl's avatar
Joachim Eibl committed
46
47
#include <q3textedit.h>
#include <q3progressdialog.h>
Joachim Eibl's avatar
Joachim Eibl committed
48
#include <kmessagebox.h>
Joachim Eibl's avatar
Joachim Eibl committed
49
#include <kfiledialog.h>
Joachim Eibl's avatar
Joachim Eibl committed
50
51
52
53
#include <kiconloader.h>
#include <klocale.h>
#include <iostream>
#include <assert.h>
Joachim Eibl's avatar
Joachim Eibl committed
54
#include <konq_popupmenu.h>
Joachim Eibl's avatar
Joachim Eibl committed
55

Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
56
static bool conflictingFileTypes(MergeFileInfos& mfi);
Joachim Eibl's avatar
Joachim Eibl committed
57
/*
Joachim Eibl's avatar
Joachim Eibl committed
58
59
60
class StatusInfo : public QListView
{
public:
Joachim Eibl's avatar
Joachim Eibl committed
61
   StatusInfo(QWidget* pParent) : QListView( pParent, "StatusInfo", Qt::WShowModal )
Joachim Eibl's avatar
Joachim Eibl committed
62
63
64
65
66
67
68
69
70
71
72
   {
      addColumn("");
      setSorting(-1); //disable sorting
   }

   QListViewItem* m_pLast;
   QListViewItem* last()
   {
      if (firstChild()==0) return 0;
      else                 return m_pLast;
   }
Joachim Eibl's avatar
Joachim Eibl committed
73

Joachim Eibl's avatar
Joachim Eibl committed
74
75
76
77
78
79
   void addText(const QString& s )
   {
      if (firstChild()==0) m_pLast = new QListViewItem( this, s );
      else                 m_pLast = new QListViewItem( this, last(), s );
   }
};
Joachim Eibl's avatar
Joachim Eibl committed
80
*/
Joachim Eibl's avatar
Joachim Eibl committed
81
class StatusInfo : public Q3TextEdit
Joachim Eibl's avatar
Joachim Eibl committed
82
83
{
public:
Joachim Eibl's avatar
Joachim Eibl committed
84
   StatusInfo(QWidget* pParent) : Q3TextEdit( pParent, "StatusInfo" )
Joachim Eibl's avatar
Joachim Eibl committed
85
   {
Joachim Eibl's avatar
Joachim Eibl committed
86
87
      setWindowFlags(Qt::Dialog);
      setWordWrap(Q3TextEdit::NoWrap);
Joachim Eibl's avatar
Joachim Eibl committed
88
89
90
91
92
93
94
95
96
97
98
99
100
101
      setReadOnly(true);
      showMaximized();
   }

   bool isEmpty(){ return text().isEmpty(); }

   void addText(const QString& s )
   {
      append(s);
   }

   void show()
   {
      scrollToBottom();
Joachim Eibl's avatar
Joachim Eibl committed
102
      Q3TextEdit::show();
Joachim Eibl's avatar
Joachim Eibl committed
103
104
   }
};
Joachim Eibl's avatar
Joachim Eibl committed
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143


class TempRemover
{
public:
   TempRemover( const QString& origName, FileAccess& fa );
   ~TempRemover();
   QString name() { return m_name; }
   bool success() { return m_bSuccess; }
private:
   QString m_name;
   bool m_bTemp;
   bool m_bSuccess;
};
TempRemover::TempRemover(const QString& origName, FileAccess& fa)
{
   if ( fa.isLocal() )
   {
      m_name = origName;
      m_bTemp = false;
      m_bSuccess = true;
   }
   else
   {
      m_name = FileAccess::tempFileName();
      m_bSuccess = fa.copyFile( m_name );
      m_bTemp = m_bSuccess;
   }
}
TempRemover::~TempRemover()
{
   if ( m_bTemp && ! m_name.isEmpty() )
      FileAccess::removeFile(m_name);
}

void DirectoryMergeWindow::fastFileComparison(
   FileAccess& fi1, FileAccess& fi2,
   bool& bEqual, bool& bError, QString& status )
{
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
144
   ProgressProxy pp;
Joachim Eibl's avatar
Joachim Eibl committed
145
146
147
148
149
150
151
152
   status = "";
   bEqual = false;
   bError = true;

   if ( !m_bFollowFileLinks )
   {
      if ( fi1.isSymLink() != fi2.isSymLink() )
      {
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
153
         status = i18n("Mix of links and normal files.");
Joachim Eibl's avatar
Joachim Eibl committed
154
155
156
157
158
159
         return;
      }
      else if ( fi1.isSymLink() && fi2.isSymLink() )
      {
         bError = false;
         bEqual = fi1.readLink() == fi2.readLink();
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
160
         status = i18n("Link: ");
Joachim Eibl's avatar
Joachim Eibl committed
161
162
163
164
165
166
167
         return;
      }
   }

   if ( fi1.size()!=fi2.size() )
   {
      bEqual = false;
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
168
169
170
171
172
173
      status = i18n("Size. ");
      return;
   }
   else if ( m_pOptions->m_bDmTrustSize )
   {
      bEqual = true;
Joachim Eibl's avatar
Joachim Eibl committed
174
175
176
177
178
179
180
      return;
   }

   if ( m_pOptions->m_bDmTrustDate )
   {
      bEqual = ( fi1.lastModified() == fi2.lastModified()  &&  fi1.size()==fi2.size() );
      bError = false;
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
181
      status = i18n("Date & Size: ");
Joachim Eibl's avatar
Joachim Eibl committed
182
183
184
185
186
187
188
189
      return;
   }

   QString fileName1 = fi1.absFilePath();
   QString fileName2 = fi2.absFilePath();
   TempRemover tr1( fileName1, fi1 );
   if ( !tr1.success() )
   {
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
190
      status = i18n("Creating temp copy of %1 failed.").arg(fileName1);
Joachim Eibl's avatar
Joachim Eibl committed
191
192
193
194
195
      return;
   }
   TempRemover tr2( fileName2, fi2 );
   if ( !tr2.success() )
   {
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
196
      status = i18n("Creating temp copy of %1 failed.").arg(fileName2);
Joachim Eibl's avatar
Joachim Eibl committed
197
198
199
200
201
202
203
204
      return;
   }

   std::vector<char> buf1(100000);
   std::vector<char> buf2(buf1.size());

   QFile file1( tr1.name() );

Joachim Eibl's avatar
Joachim Eibl committed
205
   if ( ! file1.open(QIODevice::ReadOnly) )
Joachim Eibl's avatar
Joachim Eibl committed
206
   {
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
207
      status = i18n("Opening %1 failed.").arg(fileName1);
Joachim Eibl's avatar
Joachim Eibl committed
208
209
210
211
212
      return;
   }

   QFile file2( tr2.name() );

Joachim Eibl's avatar
Joachim Eibl committed
213
   if ( ! file2.open(QIODevice::ReadOnly) )
Joachim Eibl's avatar
Joachim Eibl committed
214
   {
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
215
      status = i18n("Opening %1 failed.").arg(fileName2);
Joachim Eibl's avatar
Joachim Eibl committed
216
217
218
      return;
   }

Joachim Eibl's avatar
Joachim Eibl committed
219
   pp.setInformation( i18n("Comparing file..."), 0, false );
Joachim Eibl's avatar
Joachim Eibl committed
220
   typedef QFile::Offset t_FileSize;
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
221
222
   t_FileSize fullSize = file1.size();
   t_FileSize sizeLeft = fullSize;
Joachim Eibl's avatar
Joachim Eibl committed
223

Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
224
   while( sizeLeft>0 && ! pp.wasCancelled() )
Joachim Eibl's avatar
Joachim Eibl committed
225
   {
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
226
      int len = min2( sizeLeft, (t_FileSize)buf1.size() );
Joachim Eibl's avatar
Joachim Eibl committed
227
228
      if( len != file1.readBlock( &buf1[0], len ) )
      {
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
229
         status = i18n("Error reading from %1").arg(fileName1);
Joachim Eibl's avatar
Joachim Eibl committed
230
231
232
233
234
         return;
      }

      if( len != file2.readBlock( &buf2[0], len ) )
      {
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
235
         status = i18n("Error reading from %1").arg(fileName2);
Joachim Eibl's avatar
Joachim Eibl committed
236
237
238
239
240
241
242
243
         return;
      }

      if ( memcmp( &buf1[0], &buf2[0], len ) != 0 )
      {
         bError = false;
         return;
      }
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
244
245
      sizeLeft-=len;
      pp.setCurrent(double(fullSize-sizeLeft)/fullSize, false );
Joachim Eibl's avatar
Joachim Eibl committed
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
   }

   // If the program really arrives here, then the files are really equal.
   bError = false;
   bEqual = true;
}





static int s_nameCol = 0;
static int s_ACol = 1;
static int s_BCol = 2;
static int s_CCol = 3;
static int s_OpCol = 4;
static int s_OpStatusCol = 5;
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
263
264
265
266
static int s_UnsolvedCol = 6;    // Nr of unsolved conflicts (for 3 input files)
static int s_SolvedCol = 7;      // Nr of auto-solvable conflicts (for 3 input files)
static int s_NonWhiteCol = 8;    // Nr of nonwhite deltas (for 2 input files)
static int s_WhiteCol = 9;       // Nr of white deltas (for 2 input files)
Joachim Eibl's avatar
Joachim Eibl committed
267
DirectoryMergeWindow::DirectoryMergeWindow( QWidget* pParent, OptionDialog* pOptions, KIconLoader* pIconLoader )
Joachim Eibl's avatar
Joachim Eibl committed
268
269
270
271
272
273
274
275
276
   : Q3ListView( pParent )
{
   connect( this, SIGNAL(doubleClicked(Q3ListViewItem*)), this, SLOT(onDoubleClick(Q3ListViewItem*)));
   connect( this, SIGNAL(returnPressed(Q3ListViewItem*)), this, SLOT(onDoubleClick(Q3ListViewItem*)));
   connect( this, SIGNAL( mouseButtonPressed(int,Q3ListViewItem*,const QPoint&, int)),
            this, SLOT(   onClick(int,Q3ListViewItem*,const QPoint&, int))  );
   connect( this, SIGNAL(contextMenuRequested(Q3ListViewItem*,const QPoint &,int)),
            this, SLOT(   slotShowContextMenu(Q3ListViewItem*,const QPoint &,int)));
   connect( this, SIGNAL(selectionChanged(Q3ListViewItem*)), this, SLOT(onSelectionChanged(Q3ListViewItem*)));
Joachim Eibl's avatar
Joachim Eibl committed
277
278
279
280
281
282
283
284
285
286
   m_pOptions = pOptions;
   m_pIconLoader = pIconLoader;
   m_pDirectoryMergeInfo = 0;
   m_bAllowResizeEvents = true;
   m_bSimulatedMergeStarted=false;
   m_bRealMergeStarted=false;
   m_bError = false;
   m_bSyncMode = false;
   m_pStatusInfo = new StatusInfo(0);
   m_pStatusInfo->hide();
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
287
   m_bScanning = false;
Joachim Eibl's avatar
Joachim Eibl committed
288
289
290
291
   m_pSelection1Item = 0;
   m_pSelection2Item = 0;
   m_pSelection3Item = 0;
   m_bCaseSensitive = true;
Joachim Eibl's avatar
Joachim Eibl committed
292

Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
293
   addColumn(i18n("Name"));
Joachim Eibl's avatar
Joachim Eibl committed
294
295
296
   addColumn("A");
   addColumn("B");
   addColumn("C");
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
297
298
   addColumn(i18n("Operation"));
   addColumn(i18n("Status"));
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
299
300
301
302
   addColumn(i18n("Unsolved"));
   addColumn(i18n("Solved"));
   addColumn(i18n("Nonwhite"));
   addColumn(i18n("White"));
Joachim Eibl's avatar
Joachim Eibl committed
303

Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
304
305
306
307
   setColumnAlignment( s_UnsolvedCol, Qt::AlignRight );
   setColumnAlignment( s_SolvedCol,   Qt::AlignRight );
   setColumnAlignment( s_NonWhiteCol, Qt::AlignRight );
   setColumnAlignment( s_WhiteCol,    Qt::AlignRight );
Joachim Eibl's avatar
Joachim Eibl committed
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
}

DirectoryMergeWindow::~DirectoryMergeWindow()
{
}


int DirectoryMergeWindow::totalColumnWidth()
{
   int w=0;
   for (int i=0; i<s_OpStatusCol; ++i)
   {
      w += columnWidth(i);
   }
   return w;
}

void DirectoryMergeWindow::reload()
{
   if ( isDirectoryMergeInProgress() )
   {
      int result = KMessageBox::warningYesNo(this,
         i18n("You are currently doing a directory merge. Are you sure, you want to abort the merge and rescan the directory?"),
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
331
         i18n("Warning"), i18n("Rescan"), i18n("Continue Merging") );
Joachim Eibl's avatar
Joachim Eibl committed
332
333
334
      if ( result!=KMessageBox::Yes )
         return;
   }
Joachim Eibl's avatar
Joachim Eibl committed
335

Joachim Eibl's avatar
Joachim Eibl committed
336
337
338
339
   init( m_dirA, m_dirB, m_dirC, m_dirDest, m_bDirectoryMerge );
}

// Copy pm2 onto pm1, but preserve the alpha value from pm1 where pm2 is transparent.
Joachim Eibl's avatar
Joachim Eibl committed
340
static QPixmap pixCombiner( const QPixmap* pm1, const QPixmap* pm2 )
Joachim Eibl's avatar
Joachim Eibl committed
341
{
Joachim Eibl's avatar
Joachim Eibl committed
342
343
   QImage img1 = pm1->convertToImage().convertDepth(32);
   QImage img2 = pm2->convertToImage().convertDepth(32);
Joachim Eibl's avatar
Joachim Eibl committed
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360

   for (int y = 0; y < img1.height(); y++)
   {
      Q_UINT32 *line1 = reinterpret_cast<Q_UINT32 *>(img1.scanLine(y));
      Q_UINT32 *line2 = reinterpret_cast<Q_UINT32 *>(img2.scanLine(y));
      for (int x = 0; x < img1.width();  x++)
      {
         if ( qAlpha( line2[x] ) >0 )
            line1[x] = (line2[x] | 0xff000000);
      }
   }
   QPixmap pix;
   pix.convertFromImage(img1);
   return pix;
}

// like pixCombiner but let the pm1 color shine through
Joachim Eibl's avatar
Joachim Eibl committed
361
static QPixmap pixCombiner2( const QPixmap* pm1, const QPixmap* pm2 )
Joachim Eibl's avatar
Joachim Eibl committed
362
{
Joachim Eibl's avatar
Joachim Eibl committed
363
364
   QImage img1 = pm1->convertToImage().convertDepth(32);
   QImage img2 = pm2->convertToImage().convertDepth(32);
Joachim Eibl's avatar
Joachim Eibl committed
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405

   for (int y = 0; y < img1.height(); y++)
   {
      Q_UINT32 *line1 = reinterpret_cast<Q_UINT32 *>(img1.scanLine(y));
      Q_UINT32 *line2 = reinterpret_cast<Q_UINT32 *>(img2.scanLine(y));
      for (int x = 0; x < img1.width();  x++)
      {
         if ( qAlpha( line2[x] ) >0 )
         {
            int r = ( qRed( line1[x] ) + qRed( line2[x] ))/2;
            int g = ( qGreen( line1[x] ) + qGreen( line2[x] ))/2;
            int b = ( qBlue( line1[x] ) + qBlue( line2[x] ))/2;
            line1[x] = qRgba( r,g,b, 0xff );
         }
      }
   }
   QPixmap pix;
   pix.convertFromImage(img1);
   return pix;
}

static void calcDirStatus( bool bThreeDirs, DirMergeItem* i, int& nofFiles,
                           int& nofDirs, int& nofEqualFiles, int& nofManualMerges )
{
   if ( i->m_pMFI->m_bDirA || i->m_pMFI->m_bDirB || i->m_pMFI->m_bDirC )
   {
      ++nofDirs;
   }
   else
   {
      ++nofFiles;
      if ( i->m_pMFI->m_bEqualAB && (!bThreeDirs || i->m_pMFI->m_bEqualAC ))
      {
         ++nofEqualFiles;
      }
      else
      {
         if ( i->m_pMFI->m_eMergeOperation==eMergeABCToDest || i->m_pMFI->m_eMergeOperation==eMergeABToDest )
            ++nofManualMerges;
      }
   }
Joachim Eibl's avatar
Joachim Eibl committed
406
   for( Q3ListViewItem* p = i->firstChild();  p!=0; p = p->nextSibling() )
Joachim Eibl's avatar
Joachim Eibl committed
407
408
409
      calcDirStatus( bThreeDirs, static_cast<DirMergeItem*>(p), nofFiles, nofDirs, nofEqualFiles, nofManualMerges );
}

Joachim Eibl's avatar
Joachim Eibl committed
410
static QString sortString(const QString& s, bool bCaseSensitive)
Joachim Eibl's avatar
Joachim Eibl committed
411
{
Joachim Eibl's avatar
Joachim Eibl committed
412
413
414
415
   if (bCaseSensitive)
      return s;
   else
      return s.upper();
Joachim Eibl's avatar
Joachim Eibl committed
416
417
}

Joachim Eibl's avatar
Joachim Eibl committed
418
419
420
421
422
423
424
425
426
bool DirectoryMergeWindow::init
   (
   FileAccess& dirA,
   FileAccess& dirB,
   FileAccess& dirC,
   FileAccess& dirDest,
   bool bDirectoryMerge
   )
{
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
427
428
   if ( m_pOptions->m_bDmFullAnalysis )
   {
Joachim Eibl's avatar
Joachim Eibl committed
429
      // A full analysis uses the same ressources that a normal text-diff/merge uses.
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
430
431
432
433
434
      // So make sure that the user saves his data first.
      bool bCanContinue=false;
      checkIfCanContinue( &bCanContinue );
      if ( !bCanContinue )
         return false;
Joachim Eibl's avatar
Joachim Eibl committed
435
      startDiffMerge("","","","","","","",0);  // hide main window
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
436
   }
Joachim Eibl's avatar
Joachim Eibl committed
437

Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
438
439
440
   show();

   ProgressProxy pp;
Joachim Eibl's avatar
Joachim Eibl committed
441
442
443
444
445
446
   m_bFollowDirLinks = m_pOptions->m_bDmFollowDirLinks;
   m_bFollowFileLinks = m_pOptions->m_bDmFollowFileLinks;
   m_bSimulatedMergeStarted=false;
   m_bRealMergeStarted=false;
   m_bError=false;
   m_bDirectoryMerge = bDirectoryMerge;
Joachim Eibl's avatar
Joachim Eibl committed
447
448
449
450
   m_pSelection1Item = 0;
   m_pSelection2Item = 0;
   m_pSelection3Item = 0;
   m_bCaseSensitive = m_pOptions->m_bDmCaseSensitiveFilenameComparison;
Joachim Eibl's avatar
Joachim Eibl committed
451
452
453

   clear();

Joachim Eibl's avatar
Joachim Eibl committed
454
   m_mergeItemList.clear();
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
455
   m_currentItemForOperation = m_mergeItemList.end();
Joachim Eibl's avatar
Joachim Eibl committed
456
457
458
459
460
461

   m_dirA = dirA;
   m_dirB = dirB;
   m_dirC = dirC;
   m_dirDest = dirDest;

Joachim Eibl's avatar
Joachim Eibl committed
462
463
464
465
466
467
   m_pDirShowIdenticalFiles->setChecked(true);
   m_pDirShowDifferentFiles->setChecked(true);
   m_pDirShowFilesOnlyInA->setChecked(true);
   m_pDirShowFilesOnlyInB->setChecked(true);
   m_pDirShowFilesOnlyInC->setChecked(true);

Joachim Eibl's avatar
Joachim Eibl committed
468
469
470
471
472
473
474
475
   // Check if all input directories exist and are valid. The dest dir is not tested now.
   // The test will happen only when we are going to write to it.
   if ( !m_dirA.isDir() || !m_dirB.isDir() ||
        (m_dirC.isValid() && !m_dirC.isDir()) )
   {
       QString text( i18n("Opening of directories failed:") );
       text += "\n\n";
       if ( !dirA.isDir() )
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
476
       {  text += i18n("Dir A \"%1\" does not exist or is not a directory.\n").arg(m_dirA.prettyAbsPath()); }
Joachim Eibl's avatar
Joachim Eibl committed
477
478

       if ( !dirB.isDir() )
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
479
       {  text += i18n("Dir B \"%1\" does not exist or is not a directory.\n").arg(m_dirB.prettyAbsPath()); }
Joachim Eibl's avatar
Joachim Eibl committed
480
481

       if ( m_dirC.isValid() && !m_dirC.isDir() )
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
482
       {  text += i18n("Dir C \"%1\" does not exist or is not a directory.\n").arg(m_dirC.prettyAbsPath()); }
Joachim Eibl's avatar
Joachim Eibl committed
483

Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
484
       KMessageBox::sorry( this, text, i18n("Directory Open Error") );
Joachim Eibl's avatar
Joachim Eibl committed
485
486
487
488
489
490
491
       return false;
   }

   if ( m_dirC.isValid() &&
        (m_dirDest.prettyAbsPath() == m_dirA.prettyAbsPath()  ||  m_dirDest.prettyAbsPath()==m_dirB.prettyAbsPath() ) )
   {
      KMessageBox::error(this,
Joachim Eibl's avatar
Joachim Eibl committed
492
         i18n( "The destination directory must not be the same as A or B when "
Joachim Eibl's avatar
Joachim Eibl committed
493
         "three directories are merged.\nCheck again before continuing."),
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
494
         i18n("Parameter Warning"));
Joachim Eibl's avatar
Joachim Eibl committed
495
496
      return false;
   }
Joachim Eibl's avatar
Joachim Eibl committed
497

Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
498
   m_bScanning = true;
Joachim Eibl's avatar
Joachim Eibl committed
499
   statusBarMessage(i18n("Scanning directories..."));
Joachim Eibl's avatar
Joachim Eibl committed
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516

   m_bSyncMode = m_pOptions->m_bDmSyncMode && !m_dirC.isValid() && !m_dirDest.isValid();

   if ( m_dirDest.isValid() )
      m_dirDestInternal = m_dirDest;
   else
      m_dirDestInternal = m_dirC.isValid() ? m_dirC : m_dirB;

   QString origCurrentDirectory = QDir::currentDirPath();

   m_fileMergeMap.clear();
   t_DirectoryList::iterator i;

   // calc how many directories will be read:
   double nofScans = ( m_dirA.isValid() ? 1 : 0 )+( m_dirB.isValid() ? 1 : 0 )+( m_dirC.isValid() ? 1 : 0 );
   int currentScan = 0;

Joachim Eibl's avatar
Joachim Eibl committed
517
518
519
520
   setColumnWidthMode(s_UnsolvedCol, Q3ListView::Manual);
   setColumnWidthMode(s_SolvedCol,   Q3ListView::Manual);
   setColumnWidthMode(s_WhiteCol,    Q3ListView::Manual);
   setColumnWidthMode(s_NonWhiteCol, Q3ListView::Manual);
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
521
522
523
524
525
526
   if ( !m_pOptions->m_bDmFullAnalysis )
   {
      setColumnWidth( s_WhiteCol,    0 );
      setColumnWidth( s_NonWhiteCol, 0 );
      setColumnWidth( s_UnsolvedCol, 0 );
      setColumnWidth( s_SolvedCol,   0 );
Joachim Eibl's avatar
Joachim Eibl committed
527
   }
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
528
529
530
531
532
533
534
535
536
537
538
539
540
541
   else if ( m_dirC.isValid() )
   {
      setColumnWidth(s_WhiteCol,    50 );
      setColumnWidth(s_NonWhiteCol, 50 );
      setColumnWidth(s_UnsolvedCol, 50 );
      setColumnWidth(s_SolvedCol,   50 );
   }
   else
   {
      setColumnWidth(s_WhiteCol,    50 );
      setColumnWidth(s_NonWhiteCol, 50 );
      setColumnWidth(s_UnsolvedCol, 50 );
      setColumnWidth(s_SolvedCol,    0 );
   }
Joachim Eibl's avatar
Joachim Eibl committed
542

Joachim Eibl's avatar
Joachim Eibl committed
543
544
545
546
547
   bool bListDirSuccessA = true;
   bool bListDirSuccessB = true;
   bool bListDirSuccessC = true;
   if ( m_dirA.isValid() )
   {
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
548
549
      pp.setInformation(i18n("Reading Directory A"));
      pp.setSubRangeTransformation(currentScan/nofScans, (currentScan+1)/nofScans);
Joachim Eibl's avatar
Joachim Eibl committed
550
551
552
553
554
555
556
557
558
559
560
      ++currentScan;

      t_DirectoryList dirListA;
      bListDirSuccessA = m_dirA.listDir( &dirListA,
         m_pOptions->m_bDmRecursiveDirs, m_pOptions->m_bDmFindHidden,
         m_pOptions->m_DmFilePattern, m_pOptions->m_DmFileAntiPattern,
         m_pOptions->m_DmDirAntiPattern, m_pOptions->m_bDmFollowDirLinks,
         m_pOptions->m_bDmUseCvsIgnore);

      for (i=dirListA.begin(); i!=dirListA.end();++i )
      {
Joachim Eibl's avatar
Joachim Eibl committed
561
         MergeFileInfos& mfi = m_fileMergeMap[sortString(i->filePath(), m_bCaseSensitive)];
Joachim Eibl's avatar
Joachim Eibl committed
562
563
564
565
566
567
568
569
         //std::cout <<i->filePath()<<std::endl;
         mfi.m_bExistsInA = true;
         mfi.m_fileInfoA = *i;
      }
   }

   if ( m_dirB.isValid() )
   {
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
570
571
      pp.setInformation(i18n("Reading Directory B"));
      pp.setSubRangeTransformation(currentScan/nofScans, (currentScan+1)/nofScans);
Joachim Eibl's avatar
Joachim Eibl committed
572
573
574
575
576
577
578
579
580
581
582
      ++currentScan;

      t_DirectoryList dirListB;
      bListDirSuccessB =  m_dirB.listDir( &dirListB,
         m_pOptions->m_bDmRecursiveDirs, m_pOptions->m_bDmFindHidden,
         m_pOptions->m_DmFilePattern, m_pOptions->m_DmFileAntiPattern,
         m_pOptions->m_DmDirAntiPattern, m_pOptions->m_bDmFollowDirLinks,
         m_pOptions->m_bDmUseCvsIgnore);

      for (i=dirListB.begin(); i!=dirListB.end();++i )
      {
Joachim Eibl's avatar
Joachim Eibl committed
583
         MergeFileInfos& mfi = m_fileMergeMap[sortString(i->filePath(), m_bCaseSensitive)];
Joachim Eibl's avatar
Joachim Eibl committed
584
585
586
587
588
589
590
591
         mfi.m_bExistsInB = true;
         mfi.m_fileInfoB = *i;
      }
   }

   e_MergeOperation eDefaultMergeOp;
   if ( m_dirC.isValid() )
   {
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
592
593
      pp.setInformation(i18n("Reading Directory C"));
      pp.setSubRangeTransformation(currentScan/nofScans, (currentScan+1)/nofScans);
Joachim Eibl's avatar
Joachim Eibl committed
594
595
596
597
598
599
600
601
602
603
604
      ++currentScan;

      t_DirectoryList dirListC;
      bListDirSuccessC = m_dirC.listDir( &dirListC,
         m_pOptions->m_bDmRecursiveDirs, m_pOptions->m_bDmFindHidden,
         m_pOptions->m_DmFilePattern, m_pOptions->m_DmFileAntiPattern,
         m_pOptions->m_DmDirAntiPattern, m_pOptions->m_bDmFollowDirLinks,
         m_pOptions->m_bDmUseCvsIgnore);

      for (i=dirListC.begin(); i!=dirListC.end();++i )
      {
Joachim Eibl's avatar
Joachim Eibl committed
605
         MergeFileInfos& mfi = m_fileMergeMap[sortString(i->filePath(),m_bCaseSensitive)];
Joachim Eibl's avatar
Joachim Eibl committed
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
         mfi.m_bExistsInC = true;
         mfi.m_fileInfoC = *i;
      }

      eDefaultMergeOp = eMergeABCToDest;
   }
   else
      eDefaultMergeOp = m_bSyncMode ? eMergeToAB : eMergeABToDest;

   bool bContinue = true;
   if ( !bListDirSuccessA || !bListDirSuccessB || !bListDirSuccessC )
   {
      QString s = i18n("Some subdirectories were not readable in");
      if ( !bListDirSuccessA )   s += "\nA: " + m_dirA.prettyAbsPath();
      if ( !bListDirSuccessB )   s += "\nB: " + m_dirB.prettyAbsPath();
      if ( !bListDirSuccessC )   s += "\nC: " + m_dirC.prettyAbsPath();
      s+="\n";
      s+= i18n("Check the permissions of the subdirectories.");
      bContinue = KMessageBox::Continue == KMessageBox::warningContinueCancel( this, s );
   }

   if ( bContinue )
   {
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
629
      prepareListView(pp);
Joachim Eibl's avatar
Joachim Eibl committed
630

Joachim Eibl's avatar
Joachim Eibl committed
631
      for( Q3ListViewItem* p = firstChild();  p!=0; p = p->nextSibling() )
Joachim Eibl's avatar
Joachim Eibl committed
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
      {
         DirMergeItem* pDMI = static_cast<DirMergeItem*>( p );
         calcSuggestedOperation( *pDMI->m_pMFI, eDefaultMergeOp );
      }
   }
   else
   {
      setSelected( 0, true );
   }

   QDir::setCurrent(origCurrentDirectory);

   // Try to improve the view a little bit.
   QWidget* pParent = parentWidget();
   QSplitter* pSplitter = static_cast<QSplitter*>(pParent);
   if (pSplitter!=0)
   {
Joachim Eibl's avatar
Joachim Eibl committed
649
      Q3ValueList<int> sizes = pSplitter->sizes();
Joachim Eibl's avatar
Joachim Eibl committed
650
651
652
653
654
      int total = sizes[0] + sizes[1];
      sizes[0]=total*6/10;
      sizes[1]=total - sizes[0];
      pSplitter->setSizes( sizes );
   }
Joachim Eibl's avatar
Joachim Eibl committed
655

Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
656
657
   m_bScanning = false;
   statusBarMessage(i18n("Ready."));
Joachim Eibl's avatar
Joachim Eibl committed
658
659
660
661
662
663
664
665

   if ( bContinue )
   {
      // Generate a status report
      int nofFiles=0;
      int nofDirs=0;
      int nofEqualFiles=0;
      int nofManualMerges=0;
Joachim Eibl's avatar
Joachim Eibl committed
666
      for( Q3ListViewItem* p = firstChild();  p!=0; p = p->nextSibling() )
Joachim Eibl's avatar
Joachim Eibl committed
667
668
669
670
         calcDirStatus( m_dirC.isValid(), static_cast<DirMergeItem*>(p),
                        nofFiles, nofDirs, nofEqualFiles, nofManualMerges );

      QString s;
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
671
      s = i18n("Directory Comparison Status") + "\n\n" +
Joachim Eibl's avatar
Joachim Eibl committed
672
673
674
675
676
677
678
679
680
          i18n("Number of subdirectories:") +" "+ QString::number(nofDirs)       + "\n"+
          i18n("Number of equal files:")     +" "+ QString::number(nofEqualFiles) + "\n"+
          i18n("Number of different files:") +" "+ QString::number(nofFiles-nofEqualFiles);

      if ( m_dirC.isValid() )
         s += "\n" + i18n("Number of manual merges:")   +" "+ QString::number(nofManualMerges);
      KMessageBox::information( this, s );
      setSelected( firstChild(), true );
   }
Joachim Eibl's avatar
Joachim Eibl committed
681

Joachim Eibl's avatar
Joachim Eibl committed
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
   return true;
}



void DirectoryMergeWindow::slotChooseAEverywhere(){ setAllMergeOperations( eCopyAToDest ); }

void DirectoryMergeWindow::slotChooseBEverywhere(){ setAllMergeOperations( eCopyBToDest ); }

void DirectoryMergeWindow::slotChooseCEverywhere(){ setAllMergeOperations( eCopyCToDest ); }

void DirectoryMergeWindow::slotAutoChooseEverywhere()
{
   e_MergeOperation eDefaultMergeOp = m_dirC.isValid() ?  eMergeABCToDest :
                                           m_bSyncMode ?  eMergeToAB      : eMergeABToDest;
   setAllMergeOperations(eDefaultMergeOp );
}

void DirectoryMergeWindow::slotNoOpEverywhere(){ setAllMergeOperations(eNoOperation); }

Joachim Eibl's avatar
Joachim Eibl committed
702
static void setListViewItemOpen( Q3ListViewItem* p, bool bOpen )
Joachim Eibl's avatar
Joachim Eibl committed
703
{
Joachim Eibl's avatar
Joachim Eibl committed
704
   for( Q3ListViewItem* pChild = p->firstChild();  pChild!=0; pChild = pChild->nextSibling() )
Joachim Eibl's avatar
Joachim Eibl committed
705
706
707
708
709
710
711
      setListViewItemOpen( pChild, bOpen );

   p->setOpen( bOpen );
}

void DirectoryMergeWindow::slotFoldAllSubdirs()
{
Joachim Eibl's avatar
Joachim Eibl committed
712
   for( Q3ListViewItem* p = firstChild();  p!=0; p = p->nextSibling() )
Joachim Eibl's avatar
Joachim Eibl committed
713
714
715
716
717
      setListViewItemOpen( p, false );
}

void DirectoryMergeWindow::slotUnfoldAllSubdirs()
{
Joachim Eibl's avatar
Joachim Eibl committed
718
   for( Q3ListViewItem* p = firstChild();  p!=0; p = p->nextSibling() )
Joachim Eibl's avatar
Joachim Eibl committed
719
720
721
      setListViewItemOpen( p, true );
}

Joachim Eibl's avatar
Joachim Eibl committed
722
static void setMergeOperation( Q3ListViewItem* pLVI, e_MergeOperation eMergeOp )
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
723
724
725
726
727
728
729
730
731
732
733
{
   if ( pLVI==0 ) return;

   DirMergeItem* pDMI = static_cast<DirMergeItem*>(pLVI);
   MergeFileInfos& mfi = *pDMI->m_pMFI;

   mfi.setMergeOperation(eMergeOp );
}

// Merge current item (merge mode)
void DirectoryMergeWindow::slotCurrentDoNothing() { setMergeOperation(currentItem(), eNoOperation ); }
Joachim Eibl's avatar
Joachim Eibl committed
734
735
void DirectoryMergeWindow::slotCurrentChooseA()   { setMergeOperation(currentItem(), m_bSyncMode ? eCopyAToB : eCopyAToDest ); }
void DirectoryMergeWindow::slotCurrentChooseB()   { setMergeOperation(currentItem(), m_bSyncMode ? eCopyBToA : eCopyBToDest ); }
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
void DirectoryMergeWindow::slotCurrentChooseC()   { setMergeOperation(currentItem(), eCopyCToDest ); }
void DirectoryMergeWindow::slotCurrentMerge()
{
   bool bThreeDirs = m_dirC.isValid();
   setMergeOperation(currentItem(), bThreeDirs ? eMergeABCToDest : eMergeABToDest );
}
void DirectoryMergeWindow::slotCurrentDelete()    { setMergeOperation(currentItem(), eDeleteFromDest ); }
// Sync current item
void DirectoryMergeWindow::slotCurrentCopyAToB()     { setMergeOperation(currentItem(), eCopyAToB ); }
void DirectoryMergeWindow::slotCurrentCopyBToA()     { setMergeOperation(currentItem(), eCopyBToA ); }
void DirectoryMergeWindow::slotCurrentDeleteA()      { setMergeOperation(currentItem(), eDeleteA );  }
void DirectoryMergeWindow::slotCurrentDeleteB()      { setMergeOperation(currentItem(), eDeleteB );  }
void DirectoryMergeWindow::slotCurrentDeleteAAndB()  { setMergeOperation(currentItem(), eDeleteAB ); }
void DirectoryMergeWindow::slotCurrentMergeToA()     { setMergeOperation(currentItem(), eMergeToA ); }
void DirectoryMergeWindow::slotCurrentMergeToB()     { setMergeOperation(currentItem(), eMergeToB ); }
void DirectoryMergeWindow::slotCurrentMergeToAAndB() { setMergeOperation(currentItem(), eMergeToAB ); }


void DirectoryMergeWindow::keyPressEvent( QKeyEvent* e )
{
Joachim Eibl's avatar
Joachim Eibl committed
756
   if ( (e->state() & Qt::ControlModifier)!=0 )
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
757
758
759
   {
      bool bThreeDirs = m_dirC.isValid();

Joachim Eibl's avatar
Joachim Eibl committed
760
      Q3ListViewItem* lvi = currentItem();
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
761
762
763
764
765
766
767
768
769
770
771
      DirMergeItem* pDMI = lvi==0 ? 0 : static_cast<DirMergeItem*>(lvi);
      MergeFileInfos* pMFI = pDMI==0 ? 0 : pDMI->m_pMFI;

      if ( pMFI==0 ) return;
      bool bMergeMode = bThreeDirs || !m_bSyncMode;
      bool bFTConflict = pMFI==0 ? false : conflictingFileTypes(*pMFI);

      if ( bMergeMode )
      {
         switch(e->key())
         {
Joachim Eibl's avatar
Joachim Eibl committed
772
773
774
775
776
777
         case Qt::Key_1:      if(pMFI->m_bExistsInA){ slotCurrentChooseA(); }  return;
         case Qt::Key_2:      if(pMFI->m_bExistsInB){ slotCurrentChooseB(); }  return;
         case Qt::Key_3:      if(pMFI->m_bExistsInC){ slotCurrentChooseC(); }  return;
         case Qt::Key_Space:  slotCurrentDoNothing();                          return;
         case Qt::Key_4:      if ( !bFTConflict )   { slotCurrentMerge();   }  return;
         case Qt::Key_Delete: slotCurrentDelete();                             return;
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
778
779
780
781
782
783
784
         default: break;
         }
      }
      else
      {
         switch(e->key())
         {
Joachim Eibl's avatar
Joachim Eibl committed
785
786
787
788
789
         case Qt::Key_1:      if(pMFI->m_bExistsInA){ slotCurrentCopyAToB(); }  return;
         case Qt::Key_2:      if(pMFI->m_bExistsInB){ slotCurrentCopyBToA(); }  return;
         case Qt::Key_Space:  slotCurrentDoNothing();                           return;
         case Qt::Key_4:      if ( !bFTConflict ) { slotCurrentMergeToAAndB(); }  return;
         case Qt::Key_Delete: if( pMFI->m_bExistsInA && pMFI->m_bExistsInB ) slotCurrentDeleteAAndB();
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
790
791
792
793
794
795
796
797
                          else if( pMFI->m_bExistsInA ) slotCurrentDeleteA();
                          else if( pMFI->m_bExistsInB ) slotCurrentDeleteB();
                          return;
         default: break;
         }
      }
   }

Joachim Eibl's avatar
Joachim Eibl committed
798
   Q3ListView::keyPressEvent(e);
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
799
800
}

Joachim Eibl's avatar
Joachim Eibl committed
801
802
803
804
805
806
807
808
void DirectoryMergeWindow::focusInEvent(QFocusEvent*)
{
   updateAvailabilities();
}
void DirectoryMergeWindow::focusOutEvent(QFocusEvent*)
{
   updateAvailabilities();
}
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
809

Joachim Eibl's avatar
Joachim Eibl committed
810
811
812
813
void DirectoryMergeWindow::setAllMergeOperations( e_MergeOperation eDefaultOperation )
{
   if ( KMessageBox::Yes == KMessageBox::warningYesNo(this,
        i18n("This affects all merge operations."),
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
814
        i18n("Changing All Merge Operations"),i18n("C&ontinue"), i18n("&Cancel") ) )
Joachim Eibl's avatar
Joachim Eibl committed
815
   {
Joachim Eibl's avatar
Joachim Eibl committed
816
      for( Q3ListViewItem* p = firstChild(); p!=0; p = p->nextSibling() )
Joachim Eibl's avatar
Joachim Eibl committed
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
      {
         DirMergeItem* pDMI = static_cast<DirMergeItem*>( p );
         calcSuggestedOperation( *pDMI->m_pMFI, eDefaultOperation );
      }
   }
}


void DirectoryMergeWindow::compareFilesAndCalcAges( MergeFileInfos& mfi )
{
   std::map<QDateTime,int> dateMap;

   if( mfi.m_bExistsInA )
   {
      mfi.m_bLinkA = mfi.m_fileInfoA.isSymLink();
      mfi.m_bDirA  = mfi.m_fileInfoA.isDir();
      dateMap[ mfi.m_fileInfoA.lastModified() ] = 0;
   }
   if( mfi.m_bExistsInB )
   {
      mfi.m_bLinkB = mfi.m_fileInfoB.isSymLink();
      mfi.m_bDirB  = mfi.m_fileInfoB.isDir();
      dateMap[ mfi.m_fileInfoB.lastModified() ] = 1;
   }
   if( mfi.m_bExistsInC )
   {
      mfi.m_bLinkC = mfi.m_fileInfoC.isSymLink();
      mfi.m_bDirC  = mfi.m_fileInfoC.isDir();
      dateMap[ mfi.m_fileInfoC.lastModified() ] = 2;
   }

Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
848
   if ( m_pOptions->m_bDmFullAnalysis )
Joachim Eibl's avatar
Joachim Eibl committed
849
   {
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
850
851
852
853
854
855
856
      if( mfi.m_bExistsInA && mfi.m_bDirA || mfi.m_bExistsInB && mfi.m_bDirB || mfi.m_bExistsInC && mfi.m_bDirC )
      {
         // If any input is a directory, don't start any comparison.
         mfi.m_bEqualAB=mfi.m_bExistsInA && mfi.m_bExistsInB;
         mfi.m_bEqualAC=mfi.m_bExistsInA && mfi.m_bExistsInC;
         mfi.m_bEqualBC=mfi.m_bExistsInB && mfi.m_bExistsInC;
      }
Joachim Eibl's avatar
Joachim Eibl committed
857
858
      else
      {
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
859
860
861
862
863
864
865
         emit startDiffMerge(
            mfi.m_bExistsInA ? mfi.m_fileInfoA.absFilePath() : QString(""),
            mfi.m_bExistsInB ? mfi.m_fileInfoB.absFilePath() : QString(""),
            mfi.m_bExistsInC ? mfi.m_fileInfoC.absFilePath() : QString(""),
            "",
            "","","",&mfi.m_totalDiffStatus
            );
Joachim Eibl's avatar
Joachim Eibl committed
866
867
868
869
870
871
872
873
874
875
876
877
878
         int nofNonwhiteConflicts = mfi.m_totalDiffStatus.nofUnsolvedConflicts + 
            mfi.m_totalDiffStatus.nofSolvedConflicts - mfi.m_totalDiffStatus.nofWhitespaceConflicts;

         if (m_pOptions->m_bDmWhiteSpaceEqual && nofNonwhiteConflicts == 0)
         {
            mfi.m_bEqualAB =  mfi.m_bEqualBC =  mfi.m_bEqualAC = true;
         }
         else
         {
            mfi.m_bEqualAB = mfi.m_totalDiffStatus.bBinaryAEqB;
            mfi.m_bEqualBC = mfi.m_totalDiffStatus.bBinaryBEqC;
            mfi.m_bEqualAC = mfi.m_totalDiffStatus.bBinaryAEqC;
         }
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
879
880
881
      }
   }
   else
Joachim Eibl's avatar
Joachim Eibl committed
882
   {
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
      bool bError;
      QString eqStatus;
      if( mfi.m_bExistsInA && mfi.m_bExistsInB )
      {
         if( mfi.m_bDirA ) mfi.m_bEqualAB=true;
         else fastFileComparison( mfi.m_fileInfoA, mfi.m_fileInfoB, mfi.m_bEqualAB, bError, eqStatus );
      }
      if( mfi.m_bExistsInA && mfi.m_bExistsInC )
      {
         if( mfi.m_bDirA ) mfi.m_bEqualAC=true;
         else fastFileComparison( mfi.m_fileInfoA, mfi.m_fileInfoC, mfi.m_bEqualAC, bError, eqStatus );
      }
      if( mfi.m_bExistsInB && mfi.m_bExistsInC )
      {
         if (mfi.m_bEqualAB && mfi.m_bEqualAC)
            mfi.m_bEqualBC = true;
         else
         {
            if( mfi.m_bDirB ) mfi.m_bEqualBC=true;
            else fastFileComparison( mfi.m_fileInfoB, mfi.m_fileInfoC, mfi.m_bEqualBC, bError, eqStatus );
         }
Joachim Eibl's avatar
Joachim Eibl committed
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
      }
   }

   if (mfi.m_bLinkA!=mfi.m_bLinkB) mfi.m_bEqualAB=false;
   if (mfi.m_bLinkA!=mfi.m_bLinkC) mfi.m_bEqualAC=false;
   if (mfi.m_bLinkB!=mfi.m_bLinkC) mfi.m_bEqualBC=false;

   if (mfi.m_bDirA!=mfi.m_bDirB) mfi.m_bEqualAB=false;
   if (mfi.m_bDirA!=mfi.m_bDirC) mfi.m_bEqualAC=false;
   if (mfi.m_bDirB!=mfi.m_bDirC) mfi.m_bEqualBC=false;

   assert(eNew==0 && eMiddle==1 && eOld==2);

   // The map automatically sorts the keys.
   int age = eNew;
   std::map<QDateTime,int>::reverse_iterator i;
   for( i=dateMap.rbegin(); i!=dateMap.rend(); ++i )
   {
      int n = i->second;
      if ( n==0 && mfi.m_ageA==eNotThere )
      {
         mfi.m_ageA = (e_Age)age; ++age;
         if ( mfi.m_bEqualAB ) { mfi.m_ageB = mfi.m_ageA; ++age; }
         if ( mfi.m_bEqualAC ) { mfi.m_ageC = mfi.m_ageA; ++age; }
      }
      else if  ( n==1 && mfi.m_ageB==eNotThere )
      {
         mfi.m_ageB = (e_Age)age; ++age;
         if ( mfi.m_bEqualAB ) { mfi.m_ageA = mfi.m_ageB; ++age; }
         if ( mfi.m_bEqualBC ) { mfi.m_ageC = mfi.m_ageB; ++age; }
      }
      else if  ( n==2 && mfi.m_ageC==eNotThere)
      {
         mfi.m_ageC = (e_Age)age; ++age;
         if ( mfi.m_bEqualAC ) { mfi.m_ageA = mfi.m_ageC; ++age; }
         if ( mfi.m_bEqualBC ) { mfi.m_ageB = mfi.m_ageC; ++age; }
      }
   }

   // The checks below are necessary when the dates of the file are equal but the
   // files are not. One wouldn't expect this to happen, yet it happens sometimes.
   if ( mfi.m_bExistsInC && mfi.m_ageC==eNotThere )
   {
      mfi.m_ageC = (e_Age)age; ++age;
      mfi.m_bConflictingAges = true;
   }
   if ( mfi.m_bExistsInB && mfi.m_ageB==eNotThere )
   {
      mfi.m_ageB = (e_Age)age; ++age;
      mfi.m_bConflictingAges = true;
   }
   if ( mfi.m_bExistsInA && mfi.m_ageA==eNotThere )
   {
      mfi.m_ageA = (e_Age)age; ++age;
      mfi.m_bConflictingAges = true;
   }

   if ( mfi.m_ageA != eOld  && mfi.m_ageB != eOld && mfi.m_ageC != eOld )
   {
      if (mfi.m_ageA == eMiddle) mfi.m_ageA = eOld;
      if (mfi.m_ageB == eMiddle) mfi.m_ageB = eOld;
      if (mfi.m_ageC == eMiddle) mfi.m_ageC = eOld;
   }
}

static QPixmap* s_pm_dir;
static QPixmap* s_pm_file;

Joachim Eibl's avatar
Joachim Eibl committed
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
static QPixmap* pmNotThere;
static QPixmap* pmNew;
static QPixmap* pmOld;
static QPixmap* pmMiddle;

static QPixmap* pmLink;

static QPixmap* pmDirLink;
static QPixmap* pmFileLink;

static QPixmap* pmNewLink;
static QPixmap* pmOldLink;
static QPixmap* pmMiddleLink;

static QPixmap* pmNewDir;
static QPixmap* pmMiddleDir;
static QPixmap* pmOldDir;

static QPixmap* pmNewDirLink;
static QPixmap* pmMiddleDirLink;
static QPixmap* pmOldDirLink;


static QPixmap colorToPixmap(QColor c)
Joachim Eibl's avatar
Joachim Eibl committed
996
{
Joachim Eibl's avatar
Joachim Eibl committed
997
998
999
1000
   QPixmap pm(16,16);
   QPainter p(&pm);
   p.setPen( Qt::black );
   p.setBrush( c );