1
/***************************************************************************
2
* Copyright (C) 2005-2008 by Georg Hennig *
3
* Email: georg.hennig@web.de *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
23
#include "kfileitemext.h"
25
#include "komparatorcopyjob.h"
31
KomparatorCopyJob::KomparatorCopyJob( QWidget *_parent )
32
: KomparatorJob( _parent )
36
KomparatorCopyJob::~KomparatorCopyJob()
40
bool KomparatorCopyJob::initialize()
54
void KomparatorCopyJob::run()
56
if ( !m_initialized ) return;
58
// KFileItemExt *curfile = NULL;
59
// KFileItemExt *match = NULL;
60
// FileTree *checktree_dupes = NULL;
61
// FileTree *checktree_comp = NULL;
66
// if ( m_size && ( m_enable_duplicates_search || m_enable_missing_search || m_enable_newer_search ) )
67
// { // comparing duplicates by size is the minimum we can do.
68
// status = i18n( "Searching for duplicates..." );
76
// if ( isCanceled() ) break;
78
// emitProgress( status, (int)((current_file*100)/m_number_of_files) );
80
// if ( !checktree_dupes )
81
// registerFile( &checktree_dupes, curfile );
83
// match = checkMatchDupes( &checktree_dupes, checktree_dupes, curfile );
85
// if ( match != NULL )
87
// if ( !curfile->isReadable() )
89
// curfile = curfile->next;
93
// if ( !match->isReadable() )
95
// curfile = curfile->next;
99
// if ( m_ignore_empty ) if ( match->size() == 0 )
101
// curfile = curfile->next;
105
// if ( m_binary_comparison )
107
// if ( confirmMatchDupes( match, curfile ) )
109
// match->hasdupes_size = 1;
110
// match->isdupe_size = 1;
111
// curfile->isdupe_size = 1;
112
// if ( match->duplicates_size )
114
// match->duplicates_size->isdupe_size = 1;
115
// match->duplicates_size->dup_size_parent = curfile;
117
// curfile->duplicates_size = match->duplicates_size;
118
// match->duplicates_size = curfile;
119
// curfile->dup_size_parent = match;
124
// match->hasdupes_size = 1;
125
// match->isdupe_size = 1;
126
// curfile->isdupe_size = 1;
127
// if ( match->duplicates_size )
129
// match->duplicates_size->isdupe_size = 1;
130
// match->duplicates_size->dup_size_parent = curfile;
132
// curfile->duplicates_size = match->duplicates_size;
133
// match->duplicates_size = curfile;
134
// curfile->dup_size_parent = match;
139
// curfile = curfile->next;
142
// emitProgress( status, -1 );
144
// if ( m_enable_duplicates_search )
146
// status = i18n( "Appending duplicates to list view..." );
149
// curfile = m_files;
153
// if ( isCanceled() ) break;
155
// emitProgress( status, (int)((current_file*100)/m_number_of_files) );
157
// if ( curfile->hasdupes_size )
159
// QCustomEvent *event = new QCustomEvent( RESULT_DUPLICATE );
160
// event->setData( curfile );
161
// QApplication::postEvent( m_parent, event );
165
// curfile = curfile->next;
169
// emitProgress( status, -1 );
172
// if ( ( m_enable_duplicates_search && !m_size ) || m_enable_missing_search || m_enable_newer_search )
174
// status = i18n( "Searching for missing / newer files..." );
178
// curfile = m_files;
182
// if ( isCanceled() ) break;
184
// emitProgress( status, (int)((current_file*100)/m_number_of_files) );
186
// if ( !checktree_comp )
187
// registerFile( &checktree_comp, curfile );
189
// match = checkMatchComp( &checktree_comp, checktree_comp, curfile );
191
// if ( match != NULL )
193
// match->hasdupes_path = 1;
194
// match->isdupe_path = 1;
195
// curfile->isdupe_path = 1;
196
// curfile->duplicates_path = match->duplicates_path;
197
// match->duplicates_path = curfile;
198
// curfile->dup_path_parent = match;
202
// curfile = curfile->next;
205
// emitProgress( status, -1 );
207
// KFileItemExt *tmpfile;
209
// status = i18n( "Appending missing / newer files to list views..." );
212
// curfile = m_files;
216
// if ( isCanceled() ) break;
218
// emitProgress( status, (int)((current_file*100)/m_number_of_files) );
220
// QPtrList< QPair<KFileItemExt*, KFileItemExt*> > list;
222
// if ( curfile->hasdupes_path )
224
// QPair<KFileItemExt*, KFileItemExt*> *pair = new QPair<KFileItemExt*, KFileItemExt*>;
225
// *pair = qMakePair( curfile, (KFileItemExt*)NULL );
226
// list.append( pair );
228
// QPair<KFileItemExt*, KFileItemExt*> *tmppair;
231
// tmpfile = curfile->duplicates_path;
234
// if ( isCanceled() ) break;
238
// for ( tmppair = list.first(); tmppair; tmppair = list.next() ) // if two paths are identical, we have a pair.
239
// { // otherwise it's <item, NULL>.
240
// if ( tmppair->second == NULL )
242
// if ( comparePath( tmpfile, tmppair->first ) == 0 ) // comparePath returns qstrcmp result; 0 if equal
244
// tmppair->second = tmpfile;
252
// QPair<KFileItemExt*, KFileItemExt*> *pair2 = new QPair<KFileItemExt*, KFileItemExt*>;
253
// *pair2 = qMakePair( curfile, (KFileItemExt*)NULL );
254
// list.append( pair2 );
257
// tmpfile = tmpfile->duplicates_path;
260
// for ( tmppair = list.first(); tmppair; tmppair = list.next() )
262
// if ( tmppair->second == NULL ) // a file that has no equivalent on the other side.
264
// if ( m_enable_missing_search )
266
// QCustomEvent *event = new QCustomEvent( RESULT_COMP_MISSING );
267
// event->setData( tmppair->first );
268
// QApplication::postEvent( m_parent, event );
271
// else // found two identical paths. must check for newer file.
273
// KFileItemExt *neweritem = newerItem( tmppair->first, tmppair->second );
274
// if ( neweritem != NULL ) // we have files with the same path+name, but different mod time...
276
// QPair<KFileItemExt*, KFileItemExt*> *resultpair = new QPair<KFileItemExt*, KFileItemExt*>;
278
// if ( neweritem == tmppair->first ) *resultpair = qMakePair( tmppair->first, tmppair->second );
279
// else *resultpair = qMakePair( tmppair->second, tmppair->first );
281
// // check if files are duplicates.
282
// bool are_duplicates = false;
284
// if ( resultpair->first->size() == 0 && resultpair->second->size() == 0 ) are_duplicates = true;
286
// tmpfile = resultpair->first;
287
// while( tmpfile && !are_duplicates )
289
// if ( tmpfile == resultpair->second ) are_duplicates = true;
290
// tmpfile = tmpfile->duplicates_size;
293
// tmpfile = resultpair->second;
294
// while( tmpfile && !are_duplicates )
296
// if ( tmpfile == resultpair->first ) are_duplicates = true;
297
// tmpfile = tmpfile->duplicates_size;
300
// if ( m_enable_newer_search )
301
// { // if !size we always find newer, not newer_equal
302
// QCustomEvent *event = new QCustomEvent( are_duplicates ? RESULT_COMP_NEWER_EQUAL : RESULT_COMP_NEWER );
303
// event->setData( resultpair );
304
// QApplication::postEvent( m_parent, event );
308
// delete resultpair;
311
// else // ... find files that are different, but have the same timestamp
313
// if ( isCanceled() ) break;
315
// // check if files are duplicates.
316
// bool are_duplicates = false;
318
// if ( tmppair->first->size() == 0 && tmppair->second->size() == 0 ) are_duplicates = true;
320
// tmpfile = tmppair->first;
321
// while( tmpfile && !are_duplicates )
323
// if ( tmpfile == tmppair->second ) are_duplicates = true;
324
// tmpfile = tmpfile->duplicates_size;
327
// tmpfile = tmppair->second;
328
// while( tmpfile && !are_duplicates )
330
// if ( tmpfile == tmppair->first ) are_duplicates = true;
331
// tmpfile = tmpfile->duplicates_size;
334
// if ( !are_duplicates ) // if !size we shouldn't report all the files as different.
335
// { // the rare case of equal but same time isn't considered as user disabled search by size.
338
// if ( m_enable_newer_search )
340
// QPair<KFileItemExt*, KFileItemExt*> *resultpair = new QPair<KFileItemExt*, KFileItemExt*>;
341
// *resultpair = qMakePair( tmppair->first, tmppair->second );
343
// QCustomEvent *event = new QCustomEvent( RESULT_COMP_DIFFERENT );
344
// event->setData( resultpair );
345
// QApplication::postEvent( m_parent, event );
348
// else // we don't search for size duplicates, and the file doesn't belong to missing or newer list.
349
// { // so we abuse the duplicates list view to display the duplicates by path. (no duplicates by size will be displayed!).
350
// if ( m_enable_duplicates_search )
352
// tmppair->first->duplicates_size = tmppair->second;
353
// tmppair->second->dup_size_parent = tmppair->first;
354
// tmppair->first->hasdupes_size = 1;
355
// tmppair->first->isdupe_size = 1;
356
// tmppair->second->isdupe_size = 1;
357
// QCustomEvent *event = new QCustomEvent( RESULT_DUPLICATE );
358
// event->setData( tmppair->first );
359
// QApplication::postEvent( m_parent, event );
367
// QPair<KFileItemExt*, KFileItemExt*> *delpair;
369
// for ( delpair = list.first(); delpair; delpair = list.next() )
376
// if ( !curfile->isdupe_path )
378
// if ( m_enable_missing_search )
380
// QCustomEvent *event = new QCustomEvent( RESULT_COMP_MISSING );
381
// event->setData( curfile );
382
// QApplication::postEvent( m_parent, event );
388
// curfile = curfile->next;
391
// emitProgress( status, -1 );
394
// purgeTree( checktree_dupes );
395
// purgeTree( checktree_comp );
397
// if ( !isCanceled() )
399
// QCustomEvent *event = new QCustomEvent( RESULT_COMP_FINISHED );
400
// QApplication::postEvent( m_parent, event );
403
m_initialized = false;