~ubuntu-branches/debian/wheezy/komparator/wheezy

« back to all changes in this revision

Viewing changes to src/komparatorcopyjob.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2010-06-23 09:50:13 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100623095013-h2d0h6d9v7vpbt9n
Tags: 1:0.3-1
* New upstream release - KDE 4 port (Closes: #555056, #586829)
  - add epoch to version number
* Switch to dpkg-source 3.0 (quilt) format
* Update debian/control:
  - update build dependencies for KDE 4 port
  - bump Standards-Version to 3.8.4
  - update Homepage
* Rewrite debian/copyright from scratch.
* Update debian/rules: switch to dh usage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2005-2008 by Georg Hennig                               *
3
 
 *   Email: georg.hennig@web.de                                            *
4
 
 *                                                                         *
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.                                   *
9
 
 *                                                                         *
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.                          *
14
 
 *                                                                         *
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
 
 ***************************************************************************/
20
 
 
21
 
#include <klocale.h>
22
 
 
23
 
#include "kfileitemext.h"
24
 
 
25
 
#include "komparatorcopyjob.h"
26
 
 
27
 
#ifdef HAVE_CONFIG_H
28
 
#include <config.h>
29
 
#endif
30
 
 
31
 
KomparatorCopyJob::KomparatorCopyJob( QWidget *_parent )
32
 
        : KomparatorJob( _parent )
33
 
{
34
 
}
35
 
 
36
 
KomparatorCopyJob::~KomparatorCopyJob()
37
 
{
38
 
}
39
 
 
40
 
bool KomparatorCopyJob::initialize()
41
 
{
42
 
        m_mutex.lock();
43
 
 
44
 
 
45
 
 
46
 
        m_initialized = true;
47
 
        m_canceled = false;
48
 
 
49
 
        m_mutex.unlock();
50
 
 
51
 
        return true;
52
 
}
53
 
 
54
 
void KomparatorCopyJob::run()
55
 
{
56
 
        if ( !m_initialized ) return;
57
 
 
58
 
//      KFileItemExt *curfile = NULL;
59
 
//      KFileItemExt *match = NULL;
60
 
//      FileTree *checktree_dupes = NULL;
61
 
//      FileTree *checktree_comp = NULL;
62
 
// 
63
 
//      QString status;
64
 
//      uint current_file;
65
 
// 
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..." );
69
 
//              current_file = 0;
70
 
// 
71
 
//              match = NULL;
72
 
//              curfile = m_files;
73
 
// 
74
 
//              while ( curfile )
75
 
//              {
76
 
//                      if ( isCanceled() ) break;
77
 
// 
78
 
//                      emitProgress( status, (int)((current_file*100)/m_number_of_files) );
79
 
// 
80
 
//                      if ( !checktree_dupes ) 
81
 
//                              registerFile( &checktree_dupes, curfile );
82
 
//                      else 
83
 
//                              match = checkMatchDupes( &checktree_dupes, checktree_dupes, curfile );
84
 
// 
85
 
//                      if ( match != NULL )
86
 
//                      {
87
 
//                              if ( !curfile->isReadable() )
88
 
//                              {
89
 
//                                      curfile = curfile->next;
90
 
//                                      continue;
91
 
//                              }
92
 
// 
93
 
//                              if ( !match->isReadable() )
94
 
//                              {
95
 
//                                      curfile = curfile->next;
96
 
//                                      continue;
97
 
//                              }
98
 
// 
99
 
//                              if ( m_ignore_empty )  if ( match->size() == 0 )
100
 
//                              {
101
 
//                                      curfile = curfile->next;
102
 
//                                      continue;
103
 
//                              }
104
 
// 
105
 
//                              if ( m_binary_comparison )
106
 
//                              {
107
 
//                                      if ( confirmMatchDupes( match, curfile ) )
108
 
//                                      {
109
 
//                                              match->hasdupes_size = 1;
110
 
//                                              match->isdupe_size = 1;
111
 
//                                              curfile->isdupe_size = 1;
112
 
//                                              if ( match->duplicates_size )
113
 
//                                              {
114
 
//                                                      match->duplicates_size->isdupe_size = 1;
115
 
//                                                      match->duplicates_size->dup_size_parent = curfile;
116
 
//                                              }
117
 
//                                              curfile->duplicates_size = match->duplicates_size;
118
 
//                                              match->duplicates_size = curfile;
119
 
//                                              curfile->dup_size_parent = match;
120
 
//                                      }
121
 
//                              }
122
 
//                              else
123
 
//                              {
124
 
//                                      match->hasdupes_size = 1;
125
 
//                                      match->isdupe_size = 1;
126
 
//                                      curfile->isdupe_size = 1;
127
 
//                                      if ( match->duplicates_size )
128
 
//                                      {
129
 
//                                              match->duplicates_size->isdupe_size = 1;
130
 
//                                              match->duplicates_size->dup_size_parent = curfile;
131
 
//                                      }
132
 
//                                      curfile->duplicates_size = match->duplicates_size;
133
 
//                                      match->duplicates_size = curfile;
134
 
//                                      curfile->dup_size_parent = match;
135
 
//                              }
136
 
//                      }
137
 
// 
138
 
//                      current_file++;
139
 
//                      curfile = curfile->next;
140
 
//              }
141
 
// 
142
 
//              emitProgress( status, -1 );
143
 
// 
144
 
//              if ( m_enable_duplicates_search )
145
 
//              {
146
 
//                      status = i18n( "Appending duplicates to list view..." );
147
 
//                      current_file = 0;
148
 
// 
149
 
//                      curfile = m_files;
150
 
// 
151
 
//                      while ( curfile )
152
 
//                      {
153
 
//                              if ( isCanceled() )  break;
154
 
// 
155
 
//                              emitProgress( status, (int)((current_file*100)/m_number_of_files) );
156
 
// 
157
 
//                              if ( curfile->hasdupes_size )
158
 
//                              {
159
 
//                                      QCustomEvent *event = new QCustomEvent( RESULT_DUPLICATE );
160
 
//                                      event->setData( curfile );
161
 
//                                      QApplication::postEvent( m_parent, event );
162
 
//                              }
163
 
// 
164
 
//                              current_file++;
165
 
//                              curfile = curfile->next;
166
 
//                      }
167
 
//              }
168
 
// 
169
 
//              emitProgress( status, -1 );
170
 
//      }
171
 
// 
172
 
//      if ( ( m_enable_duplicates_search && !m_size ) || m_enable_missing_search || m_enable_newer_search )
173
 
//      {
174
 
//              status = i18n( "Searching for missing / newer files..." );
175
 
//              current_file = 0;
176
 
// 
177
 
//              match = NULL;
178
 
//              curfile = m_files;
179
 
// 
180
 
//              while ( curfile )
181
 
//              {
182
 
//                      if ( isCanceled() )  break;
183
 
// 
184
 
//                      emitProgress( status, (int)((current_file*100)/m_number_of_files) );
185
 
// 
186
 
//                      if ( !checktree_comp )
187
 
//                              registerFile( &checktree_comp, curfile );
188
 
//                      else
189
 
//                              match = checkMatchComp( &checktree_comp, checktree_comp, curfile );
190
 
// 
191
 
//                      if ( match != NULL )
192
 
//                      {
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;
199
 
//                      }
200
 
// 
201
 
//                      current_file++;
202
 
//                      curfile = curfile->next;
203
 
//              }
204
 
// 
205
 
//              emitProgress( status, -1 );
206
 
// 
207
 
//              KFileItemExt *tmpfile;
208
 
// 
209
 
//              status = i18n( "Appending missing / newer files to list views..." );
210
 
//              current_file = 0;
211
 
// 
212
 
//              curfile = m_files;
213
 
// 
214
 
//              while ( curfile )
215
 
//              {
216
 
//                      if ( isCanceled() ) break;
217
 
// 
218
 
//                      emitProgress( status, (int)((current_file*100)/m_number_of_files) );
219
 
// 
220
 
//                      QPtrList< QPair<KFileItemExt*, KFileItemExt*> > list;
221
 
// 
222
 
//                      if ( curfile->hasdupes_path )
223
 
//                      {
224
 
//                              QPair<KFileItemExt*, KFileItemExt*> *pair = new QPair<KFileItemExt*, KFileItemExt*>;
225
 
//                              *pair = qMakePair( curfile, (KFileItemExt*)NULL );
226
 
//                              list.append( pair );
227
 
// 
228
 
//                              QPair<KFileItemExt*, KFileItemExt*> *tmppair;
229
 
//                              bool inserted;
230
 
// 
231
 
//                              tmpfile = curfile->duplicates_path;
232
 
//                              while ( tmpfile )
233
 
//                              {
234
 
//                                      if ( isCanceled() ) break;
235
 
// 
236
 
//                                      inserted = false;
237
 
// 
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 )
241
 
//                                              {
242
 
//                                                      if ( comparePath( tmpfile, tmppair->first ) == 0 ) // comparePath returns qstrcmp result; 0 if equal
243
 
//                                                      {
244
 
//                                                              tmppair->second = tmpfile;
245
 
//                                                              inserted = true;
246
 
//                                                      }
247
 
//                                              }
248
 
//                                      }
249
 
// 
250
 
//                                      if ( !inserted )
251
 
//                                      {
252
 
//                                              QPair<KFileItemExt*, KFileItemExt*> *pair2 = new QPair<KFileItemExt*, KFileItemExt*>;
253
 
//                                              *pair2 = qMakePair( curfile, (KFileItemExt*)NULL );
254
 
//                                              list.append( pair2 );
255
 
//                                      }
256
 
// 
257
 
//                                      tmpfile = tmpfile->duplicates_path;
258
 
//                              }
259
 
// 
260
 
//                              for ( tmppair = list.first(); tmppair; tmppair = list.next() )
261
 
//                              {
262
 
//                                      if ( tmppair->second == NULL ) // a file that has no equivalent on the other side.
263
 
//                                      {
264
 
//                                              if ( m_enable_missing_search )
265
 
//                                              {
266
 
//                                                      QCustomEvent *event = new QCustomEvent( RESULT_COMP_MISSING );
267
 
//                                                      event->setData( tmppair->first );
268
 
//                                                      QApplication::postEvent( m_parent, event );
269
 
//                                              }
270
 
//                                      }
271
 
//                                      else                          // found two identical paths. must check for newer file.
272
 
//                                      {
273
 
//                                              KFileItemExt *neweritem = newerItem( tmppair->first, tmppair->second );
274
 
//                                              if ( neweritem != NULL )    // we have files with the same path+name, but different mod time...
275
 
//                                              {
276
 
//                                                      QPair<KFileItemExt*, KFileItemExt*> *resultpair = new QPair<KFileItemExt*, KFileItemExt*>;
277
 
// 
278
 
//                                                      if ( neweritem == tmppair->first ) *resultpair = qMakePair( tmppair->first, tmppair->second );
279
 
//                                                      else *resultpair = qMakePair( tmppair->second, tmppair->first );
280
 
// 
281
 
//                                                      // check if files are duplicates.
282
 
//                                                      bool are_duplicates = false;
283
 
// 
284
 
//                                                      if ( resultpair->first->size() == 0 && resultpair->second->size() == 0 ) are_duplicates = true;
285
 
// 
286
 
//                                                      tmpfile = resultpair->first;
287
 
//                                                      while( tmpfile && !are_duplicates )
288
 
//                                                      {
289
 
//                                                              if ( tmpfile == resultpair->second ) are_duplicates = true;
290
 
//                                                              tmpfile = tmpfile->duplicates_size;
291
 
//                                                      }
292
 
// 
293
 
//                                                      tmpfile = resultpair->second;
294
 
//                                                      while( tmpfile && !are_duplicates )
295
 
//                                                      {
296
 
//                                                              if ( tmpfile == resultpair->first ) are_duplicates = true;
297
 
//                                                              tmpfile = tmpfile->duplicates_size;
298
 
//                                                      }
299
 
// 
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 );
305
 
//                                                      }
306
 
//                                                      else
307
 
//                                                      {
308
 
//                                                              delete resultpair;
309
 
//                                                      }
310
 
//                                              }
311
 
//                                              else // ... find files that are different, but have the same timestamp
312
 
//                                              {
313
 
//                                                      if ( isCanceled() ) break;
314
 
// 
315
 
//                                                      // check if files are duplicates.
316
 
//                                                      bool are_duplicates = false;
317
 
// 
318
 
//                                                      if ( tmppair->first->size() == 0 && tmppair->second->size() == 0 ) are_duplicates = true;
319
 
// 
320
 
//                                                      tmpfile = tmppair->first;
321
 
//                                                      while( tmpfile && !are_duplicates )
322
 
//                                                      {
323
 
//                                                              if ( tmpfile == tmppair->second ) are_duplicates = true;
324
 
//                                                              tmpfile = tmpfile->duplicates_size;
325
 
//                                                      }
326
 
// 
327
 
//                                                      tmpfile = tmppair->second;
328
 
//                                                      while( tmpfile && !are_duplicates )
329
 
//                                                      {
330
 
//                                                              if ( tmpfile == tmppair->first ) are_duplicates = true;
331
 
//                                                              tmpfile = tmpfile->duplicates_size;
332
 
//                                                      }
333
 
// 
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.
336
 
//                                                              if ( m_size )
337
 
//                                                              {
338
 
//                                                                      if ( m_enable_newer_search )
339
 
//                                                                      {
340
 
//                                                                              QPair<KFileItemExt*, KFileItemExt*> *resultpair = new QPair<KFileItemExt*, KFileItemExt*>;
341
 
//                                                                              *resultpair = qMakePair( tmppair->first, tmppair->second );
342
 
// 
343
 
//                                                                              QCustomEvent *event = new QCustomEvent( RESULT_COMP_DIFFERENT );
344
 
//                                                                              event->setData( resultpair );
345
 
//                                                                              QApplication::postEvent( m_parent, event );
346
 
//                                                                      }
347
 
//                                                              }
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 )
351
 
//                                                                      {
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 );
360
 
//                                                                      }
361
 
//                                                              }
362
 
//                                                      }
363
 
//                                              }
364
 
//                                      }
365
 
//                              }
366
 
// 
367
 
//                              QPair<KFileItemExt*, KFileItemExt*> *delpair;
368
 
// 
369
 
//                              for ( delpair = list.first(); delpair; delpair = list.next() )
370
 
//                              {
371
 
//                                      delete delpair;
372
 
//                              }
373
 
//                      }
374
 
//                      else
375
 
//                      {
376
 
//                              if ( !curfile->isdupe_path )
377
 
//                              {
378
 
//                                      if ( m_enable_missing_search )
379
 
//                                      {
380
 
//                                              QCustomEvent *event = new QCustomEvent( RESULT_COMP_MISSING );
381
 
//                                              event->setData( curfile );
382
 
//                                              QApplication::postEvent( m_parent, event );
383
 
//                                      }
384
 
//                              }
385
 
//                      }
386
 
// 
387
 
//                      current_file++;
388
 
//                      curfile = curfile->next;
389
 
//              }
390
 
// 
391
 
//              emitProgress( status, -1 );
392
 
//      }
393
 
// 
394
 
//      purgeTree( checktree_dupes );
395
 
//      purgeTree( checktree_comp );
396
 
// 
397
 
//      if ( !isCanceled() )
398
 
//      {
399
 
//              QCustomEvent *event = new QCustomEvent( RESULT_COMP_FINISHED );
400
 
//              QApplication::postEvent( m_parent, event );
401
 
//      }
402
 
 
403
 
        m_initialized = false;
404
 
}