• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kleopatra

  • sources
  • kde-4.14
  • kdepim
  • kleopatra
  • crypto
createchecksumscontroller.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  crypto/createchecksumscontroller.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2010 Klarälvdalens Datakonsult AB
6 
7  Kleopatra is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  Kleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #include <config-kleopatra.h>
34 
35 #include "createchecksumscontroller.h"
36 
37 #include <utils/input.h>
38 #include <utils/output.h>
39 #include <utils/classify.h>
40 #include <utils/kleo_assert.h>
41 
42 #include <kleo/stl_util.h>
43 #include <kleo/checksumdefinition.h>
44 
45 #include <KLocalizedString>
46 #include <kdebug.h>
47 #include <KSaveFile>
48 #include <KConfigGroup>
49 #include <KSharedConfig>
50 
51 #include <QDialog>
52 #include <QDialogButtonBox>
53 #include <QLabel>
54 #include <QListWidget>
55 #include <QVBoxLayout>
56 
57 #include <QPointer>
58 #include <QFileInfo>
59 #include <QThread>
60 #include <QMutex>
61 #include <QProgressDialog>
62 #include <QDir>
63 #include <QProcess>
64 
65 #ifndef Q_MOC_RUN
66 #include <boost/bind.hpp>
67 #include <boost/function.hpp>
68 #endif
69 
70 #include <gpg-error.h>
71 
72 #include <deque>
73 #include <map>
74 #include <limits>
75 
76 using namespace Kleo;
77 using namespace Kleo::Crypto;
78 using namespace boost;
79 
80 namespace {
81 
82  class ResultDialog : public QDialog {
83  Q_OBJECT
84  public:
85  ResultDialog( const QStringList & created, const QStringList & errors, QWidget * parent=0, Qt::WindowFlags f=0 )
86  : QDialog( parent, f ),
87  createdLB( created.empty()
88  ? i18nc("@info","No checksum files have been created.")
89  : i18nc("@info","These checksum files have been successfully created:"), this ),
90  createdLW( this ),
91  errorsLB( errors.empty()
92  ? i18nc("@info","There were no errors.")
93  : i18nc("@info","The following errors were encountered:"), this ),
94  errorsLW( this ),
95  buttonBox( QDialogButtonBox::Ok, Qt::Horizontal, this ),
96  vlay( this )
97  {
98  KDAB_SET_OBJECT_NAME( createdLB );
99  KDAB_SET_OBJECT_NAME( createdLW );
100  KDAB_SET_OBJECT_NAME( errorsLB );
101  KDAB_SET_OBJECT_NAME( errorsLW );
102  KDAB_SET_OBJECT_NAME( buttonBox );
103  KDAB_SET_OBJECT_NAME( vlay );
104 
105  createdLW.addItems( created );
106  QRect r;
107  for( int i = 0; i < created.size(); ++i )
108  r = r.united( createdLW.visualRect( createdLW.model()->index( 0, i ) ) );
109  createdLW.setMinimumWidth( qMin( 1024, r.width() + 4 * createdLW.frameWidth() ) );
110 
111  errorsLW.addItems( errors );
112 
113  vlay.addWidget( &createdLB );
114  vlay.addWidget( &createdLW, 1 );
115  vlay.addWidget( &errorsLB );
116  vlay.addWidget( &errorsLW, 1 );
117  vlay.addWidget( &buttonBox );
118 
119  if ( created.empty() )
120  createdLW.hide();
121  if ( errors.empty() )
122  errorsLW.hide();
123 
124  connect( &buttonBox, SIGNAL(accepted()), this, SLOT(accept()) );
125  connect( &buttonBox, SIGNAL(rejected()), this, SLOT(reject()) );
126  readConfig();
127  }
128  ~ResultDialog()
129  {
130  writeConfig();
131  }
132 
133  void readConfig()
134  {
135  KConfigGroup dialog( KGlobal::config(), "ResultDialog" );
136  const QSize size = dialog.readEntry( "Size", QSize(600, 400) );
137  if ( size.isValid() ) {
138  resize( size );
139  }
140  }
141  void writeConfig()
142  {
143  KConfigGroup dialog( KGlobal::config(), "ResultDialog" );
144  dialog.writeEntry( "Size",size() );
145  dialog.sync();
146  }
147 
148  private:
149  QLabel createdLB;
150  QListWidget createdLW;
151  QLabel errorsLB;
152  QListWidget errorsLW;
153  QDialogButtonBox buttonBox;
154  QVBoxLayout vlay;
155  };
156 
157 }
158 
159 #ifdef Q_OS_UNIX
160 static const bool HAVE_UNIX = true;
161 #else
162 static const bool HAVE_UNIX = false;
163 #endif
164 
165 static const Qt::CaseSensitivity fs_cs = HAVE_UNIX ? Qt::CaseSensitive : Qt::CaseInsensitive ; // can we use QAbstractFileEngine::caseSensitive()?
166 
167 static QStringList fs_sort( QStringList l ) {
168  int (*QString_compare)(const QString&,const QString&,Qt::CaseSensitivity) = &QString::compare;
169  kdtools::sort( l, boost::bind( QString_compare, _1, _2, fs_cs ) < 0 );
170  return l;
171 }
172 
173 static QStringList fs_intersect( QStringList l1, QStringList l2 ) {
174  int (*QString_compare)(const QString&,const QString&,Qt::CaseSensitivity) = &QString::compare;
175  fs_sort( l1 );
176  fs_sort( l2 );
177  QStringList result;
178  std::set_intersection( l1.begin(), l1.end(),
179  l2.begin(), l2.end(),
180  std::back_inserter( result ),
181  boost::bind( QString_compare, _1, _2, fs_cs ) < 0 );
182  return result;
183 }
184 
185 static QList<QRegExp> get_patterns( const std::vector< shared_ptr<ChecksumDefinition> > & checksumDefinitions )
186 {
187  QList<QRegExp> result;
188  Q_FOREACH( const shared_ptr<ChecksumDefinition> & cd, checksumDefinitions )
189  if ( cd )
190  Q_FOREACH( const QString & pattern, cd->patterns() )
191  result.push_back( QRegExp( pattern, fs_cs ) );
192  return result;
193 }
194 
195 namespace {
196  struct matches_any : std::unary_function<QString,bool> {
197  const QList<QRegExp> m_regexps;
198  explicit matches_any( const QList<QRegExp> & regexps ) : m_regexps( regexps ) {}
199  bool operator()( const QString & s ) const {
200  return kdtools::any( m_regexps, boost::bind( &QRegExp::exactMatch, _1, s ) );
201  }
202  };
203 }
204 
205 class CreateChecksumsController::Private : public QThread {
206  Q_OBJECT
207  friend class ::Kleo::Crypto::CreateChecksumsController;
208  CreateChecksumsController * const q;
209 public:
210  explicit Private( CreateChecksumsController * qq );
211  ~Private();
212 
213 Q_SIGNALS:
214  void progress( int, int, const QString & );
215 
216 private:
217  void slotOperationFinished() {
218 #ifndef QT_NO_PROGRESSDIALOG
219  if ( progressDialog ) {
220  progressDialog->setValue( progressDialog->maximum() );
221  progressDialog->close();
222  }
223 #endif // QT_NO_PROGRESSDIALOG
224  ResultDialog * const dlg = new ResultDialog( created, errors );
225  dlg->setAttribute(Qt::WA_DeleteOnClose);
226  q->bringToForeground( dlg );
227  if ( !errors.empty() )
228  q->setLastError( gpg_error( GPG_ERR_GENERAL ),
229  errors.join( QLatin1String("\n") ) );
230  q->emitDoneOrError();
231  }
232  void slotProgress( int current, int total, const QString & what ) {
233  kDebug() << "progress: " << current << "/" << total << ": " << qPrintable( what );
234 #ifndef QT_NO_PROGRESSDIALOG
235  if ( !progressDialog )
236  return;
237  progressDialog->setMaximum( total );
238  progressDialog->setValue( current );
239  progressDialog->setLabelText( what );
240 #endif // QT_NO_PROGRESSDIALOG
241  }
242 
243 private:
244  /* reimp */ void run();
245 
246 private:
247 #ifndef QT_NO_PROGRESSDIALOG
248  QPointer<QProgressDialog> progressDialog;
249 #endif
250  mutable QMutex mutex;
251  const std::vector< shared_ptr<ChecksumDefinition> > checksumDefinitions;
252  shared_ptr<ChecksumDefinition> checksumDefinition;
253  QStringList files;
254  QStringList errors, created;
255  bool allowAddition;
256  volatile bool canceled;
257 };
258 
259 CreateChecksumsController::Private::Private( CreateChecksumsController * qq )
260  : q( qq ),
261 #ifndef QT_NO_PROGRESSDIALOG
262  progressDialog(),
263 #endif
264  mutex(),
265  checksumDefinitions( ChecksumDefinition::getChecksumDefinitions() ),
266  checksumDefinition( ChecksumDefinition::getDefaultChecksumDefinition( checksumDefinitions ) ),
267  files(),
268  errors(),
269  created(),
270  allowAddition( false ),
271  canceled( false )
272 {
273  connect( this, SIGNAL(progress(int,int,QString)),
274  q, SLOT(slotProgress(int,int,QString)) );
275  connect( this, SIGNAL(progress(int,int,QString)),
276  q, SIGNAL(progress(int,int,QString)) );
277  connect( this, SIGNAL(finished()),
278  q, SLOT(slotOperationFinished()) );
279 }
280 
281 CreateChecksumsController::Private::~Private() { kDebug(); }
282 
283 CreateChecksumsController::CreateChecksumsController( QObject * p )
284  : Controller( p ), d( new Private( this ) )
285 {
286 
287 }
288 
289 CreateChecksumsController::CreateChecksumsController( const shared_ptr<const ExecutionContext> & ctx, QObject * p )
290  : Controller( ctx, p ), d( new Private( this ) )
291 {
292 
293 }
294 
295 CreateChecksumsController::~CreateChecksumsController() {
296  kDebug();
297 }
298 
299 void CreateChecksumsController::setFiles( const QStringList & files ) {
300  kleo_assert( !d->isRunning() );
301  kleo_assert( !files.empty() );
302  const QList<QRegExp> patterns = get_patterns( d->checksumDefinitions );
303  if ( !kdtools::all( files, matches_any( patterns ) ) &&
304  !kdtools::none_of( files, matches_any( patterns ) ) )
305  throw Exception( gpg_error( GPG_ERR_INV_ARG ), i18n("Create Checksums: input files must be either all checksum files or all files to be checksummed, not a mixture of both.") );
306  const QMutexLocker locker( &d->mutex );
307  d->files = files;
308 }
309 
310 void CreateChecksumsController::setAllowAddition( bool allow ) {
311  kleo_assert( !d->isRunning() );
312  const QMutexLocker locker( &d->mutex );
313  d->allowAddition = allow;
314 }
315 
316 bool CreateChecksumsController::allowAddition() const {
317  const QMutexLocker locker( &d->mutex );
318  return d->allowAddition;
319 }
320 
321 void CreateChecksumsController::start() {
322 
323  {
324  const QMutexLocker locker( &d->mutex );
325 
326 #ifndef QT_NO_PROGRESSDIALOG
327  d->progressDialog = new QProgressDialog( i18n("Initializing..."), i18n("Cancel"), 0, 0 );
328  applyWindowID( d->progressDialog );
329  d->progressDialog->setAttribute( Qt::WA_DeleteOnClose );
330  d->progressDialog->setMinimumDuration( 1000 );
331  d->progressDialog->setWindowTitle( i18nc("@title:window","Create Checksum Progress") );
332  connect( d->progressDialog, SIGNAL(canceled()), this, SLOT(cancel()) );
333 #endif // QT_NO_PROGRESSDIALOG
334 
335  d->canceled = false;
336  d->errors.clear();
337  d->created.clear();
338  }
339 
340  d->start();
341 
342 }
343 
344 void CreateChecksumsController::cancel() {
345  kDebug();
346  const QMutexLocker locker( &d->mutex );
347  d->canceled = true;
348 }
349 
350 namespace {
351 
352  struct Dir {
353  QDir dir;
354  QString sumFile;
355  QStringList inputFiles;
356  quint64 totalSize;
357  shared_ptr<ChecksumDefinition> checksumDefinition;
358  };
359 
360 }
361 
362 static QStringList remove_checksum_files( QStringList l, const QList<QRegExp> & rxs ) {
363  QStringList::iterator end = l.end();
364  Q_FOREACH( const QRegExp & rx, rxs )
365  end = std::remove_if( l.begin(), end,
366  boost::bind( &QRegExp::exactMatch, rx, _1 ) );
367  l.erase( end, l.end() );
368  return l;
369 }
370 
371 namespace {
372  struct File {
373  QString name;
374  QByteArray checksum;
375  bool binary;
376  };
377 }
378 
379 static QString decode( const QString & encoded ) {
380  QString decoded;
381  decoded.reserve( encoded.size() );
382  bool shift = false;
383  Q_FOREACH( const QChar ch, encoded )
384  if ( shift ) {
385  switch ( ch.toLatin1() ) {
386  case '\\': decoded += QLatin1Char( '\\' ); break;
387  case 'n': decoded += QLatin1Char( '\n' ); break;
388  default:
389  kDebug() << "invalid escape sequence" << '\\' << ch << "(interpreted as '" << ch << "')";
390  decoded += ch;
391  break;
392  }
393  shift = false;
394  } else {
395  if ( ch == QLatin1Char( '\\' ) )
396  shift = true;
397  else
398  decoded += ch;
399  }
400  return decoded;
401 }
402 
403 static std::vector<File> parse_sum_file( const QString & fileName ) {
404  std::vector<File> files;
405  QFile f( fileName );
406  if ( f.open( QIODevice::ReadOnly ) ) {
407  QTextStream s( &f );
408  QRegExp rx( QLatin1String("(\\?)([a-f0-9A-F]+) ([ *])([^\n]+)\n*") );
409  while ( !s.atEnd() ) {
410  const QString line = s.readLine();
411  if ( rx.exactMatch( line ) ) {
412  assert( !rx.cap(4).endsWith( QLatin1Char('\n') ) );
413  const File file = {
414  rx.cap( 1 ) == QLatin1String("\\") ? decode( rx.cap( 4 ) ) : rx.cap( 4 ),
415  rx.cap( 2 ).toLatin1(),
416  rx.cap( 3 ) == QLatin1String("*"),
417  };
418  files.push_back( file );
419  }
420  }
421  }
422  return files;
423 }
424 
425 static quint64 aggregate_size( const QDir & dir, const QStringList & files ) {
426  quint64 n = 0;
427  Q_FOREACH( const QString & file, files )
428  n += QFileInfo( dir.absoluteFilePath( file ) ).size();
429  return n;
430 }
431 
432 static shared_ptr<ChecksumDefinition> filename2definition( const QString & fileName,
433  const std::vector< shared_ptr<ChecksumDefinition> > & checksumDefinitions )
434 {
435  Q_FOREACH( const shared_ptr<ChecksumDefinition> & cd, checksumDefinitions )
436  if ( cd )
437  Q_FOREACH( const QString & pattern, cd->patterns() )
438  if ( QRegExp( pattern, fs_cs ).exactMatch( fileName ) )
439  return cd;
440  return shared_ptr<ChecksumDefinition>();
441 }
442 
443 static std::vector<Dir> find_dirs_by_sum_files( const QStringList & files, bool allowAddition,
444  const function<void(int)> & progress,
445  const std::vector< shared_ptr<ChecksumDefinition> > & checksumDefinitions )
446 {
447 
448  const QList<QRegExp> patterns = get_patterns( checksumDefinitions );
449 
450  std::vector<Dir> dirs;
451  dirs.reserve( files.size() );
452 
453  int i = 0;
454 
455  Q_FOREACH( const QString & file, files ) {
456 
457  const QFileInfo fi( file );
458  const QDir dir = fi.dir();
459  const QStringList entries = remove_checksum_files( dir.entryList( QDir::Files ), patterns );
460 
461  QStringList inputFiles;
462  if ( allowAddition ) {
463  inputFiles = entries;
464  } else {
465  const std::vector<File> parsed = parse_sum_file( fi.absoluteFilePath() );
466  const QStringList oldInputFiles =
467  kdtools::transform<QStringList>( parsed, mem_fn( &File::name ) );
468  inputFiles = fs_intersect( oldInputFiles, entries );
469  }
470 
471  const Dir item = {
472  dir,
473  fi.fileName(),
474  inputFiles,
475  aggregate_size( dir, inputFiles ),
476  filename2definition( fi.fileName(), checksumDefinitions )
477  };
478 
479  dirs.push_back( item );
480 
481  if ( !progress.empty() )
482  progress( ++i );
483 
484  }
485  return dirs;
486 }
487 
488 namespace {
489  struct less_dir : std::binary_function<QDir,QDir,bool> {
490  bool operator()( const QDir & lhs, const QDir & rhs ) const {
491  return QString::compare( lhs.absolutePath(), rhs.absolutePath(), fs_cs ) < 0 ;
492  }
493  };
494 }
495 
496 static std::vector<Dir> find_dirs_by_input_files( const QStringList & files, const shared_ptr<ChecksumDefinition> & checksumDefinition, bool allowAddition,
497  const function<void(int)> & progress,
498  const std::vector< shared_ptr<ChecksumDefinition> > & checksumDefinitions )
499 {
500  Q_UNUSED( allowAddition );
501  if ( !checksumDefinition )
502  return std::vector<Dir>();
503 
504  const QList<QRegExp> patterns = get_patterns( checksumDefinitions );
505 
506  std::map<QDir,QStringList,less_dir> dirs2files;
507 
508  // Step 1: sort files by the dir they're contained in:
509 
510  std::deque<QString> inputs( files.begin(), files.end() );
511 
512  int i = 0;
513  while ( !inputs.empty() ) {
514  const QString file = inputs.front();
515  inputs.pop_front();
516  const QFileInfo fi( file );
517  if ( fi.isDir() ) {
518  QDir dir( file );
519  dirs2files[ dir ] = remove_checksum_files( dir.entryList( QDir::Files ), patterns );
520  kdtools::transform( dir.entryList( QDir::Dirs|QDir::NoDotAndDotDot ),
521  std::inserter( inputs, inputs.begin() ),
522  boost::bind( &QDir::absoluteFilePath, cref(dir), _1 ) );
523  } else {
524  dirs2files[fi.dir()].push_back( file );
525  }
526  if ( !progress.empty() )
527  progress( ++i );
528  }
529 
530  // Step 2: convert into vector<Dir>:
531 
532  std::vector<Dir> dirs;
533  dirs.reserve( dirs2files.size() );
534 
535  for ( std::map<QDir,QStringList,less_dir>::const_iterator it = dirs2files.begin(), end = dirs2files.end() ; it != end ; ++it ) {
536 
537  const QStringList inputFiles = remove_checksum_files( it->second, patterns );
538  if ( inputFiles.empty() )
539  continue;
540 
541  const Dir dir = {
542  it->first,
543  checksumDefinition->outputFileName(),
544  inputFiles,
545  aggregate_size( it->first, inputFiles ),
546  checksumDefinition
547  };
548  dirs.push_back( dir );
549 
550  if ( !progress.empty() )
551  progress( ++i );
552 
553  }
554  return dirs;
555 }
556 
557 static QString process( const Dir & dir, bool * fatal ) {
558  const QString absFilePath = dir.dir.absoluteFilePath( dir.sumFile );
559  KSaveFile file( absFilePath );
560  if ( !file.open() )
561  return i18n( "Failed to open file \"%1\" for reading and writing: %2",
562  dir.dir.absoluteFilePath( file.fileName() ),
563  file.errorString() );
564  QProcess p;
565  p.setWorkingDirectory( dir.dir.absolutePath() );
566  p.setStandardOutputFile( dir.dir.absoluteFilePath( file.QFile::fileName() ) );
567  const QString program = dir.checksumDefinition->createCommand();
568  dir.checksumDefinition->startCreateCommand( &p, dir.inputFiles );
569  p.waitForFinished();
570  kDebug() << "[" << &p << "] Exit code " << p.exitCode();
571 
572  if ( p.exitStatus() != QProcess::NormalExit || p.exitCode() != 0 ) {
573  file.abort();
574  if ( fatal && p.error() == QProcess::FailedToStart )
575  *fatal = true;
576  if ( p.error() == QProcess::UnknownError )
577  return i18n( "Error while running %1: %2", program,
578  QString::fromLocal8Bit( p.readAllStandardError().trimmed().constData() ) );
579  else
580  return i18n( "Failed to execute %1: %2", program, p.errorString() );
581  }
582 
583  if ( !file.finalize() )
584  return i18n( "Failed to move file %1 to its final destination, %2: %3",
585  file.fileName(), dir.sumFile, file.errorString() );
586 
587  return QString();
588 }
589 
590 namespace {
591  static QDebug operator<<( QDebug s, const Dir & dir ) {
592  return s << "Dir(" << dir.dir << "->" << dir.sumFile << "<-(" << dir.totalSize << ')' << dir.inputFiles << ")\n";
593  }
594 }
595 
596 void CreateChecksumsController::Private::run() {
597 
598  QMutexLocker locker( &mutex );
599 
600  const QStringList files = this->files;
601  const std::vector< shared_ptr<ChecksumDefinition> > checksumDefinitions = this->checksumDefinitions;
602  const shared_ptr<ChecksumDefinition> checksumDefinition = this->checksumDefinition;
603  const bool allowAddition = this->allowAddition;
604 
605  locker.unlock();
606 
607  QStringList errors;
608  QStringList created;
609 
610  if ( !checksumDefinition ) {
611  errors.push_back( i18n("No checksum programs defined.") );
612  locker.relock();
613  this->errors = errors;
614  return;
615  } else {
616  kDebug() << "using checksum-definition" << checksumDefinition->id();
617  }
618 
619  //
620  // Step 1: build a list of work to do (no progress):
621  //
622 
623  const QString scanning = i18n("Scanning directories...");
624  emit progress( 0, 0, scanning );
625 
626  const bool haveSumFiles
627  = kdtools::all( files, matches_any( get_patterns( checksumDefinitions ) ) );
628  const function<void(int)> progressCb = boost::bind( &Private::progress, this, _1, 0, scanning );
629  const std::vector<Dir> dirs = haveSumFiles
630  ? find_dirs_by_sum_files( files, allowAddition, progressCb, checksumDefinitions )
631  : find_dirs_by_input_files( files, checksumDefinition, allowAddition, progressCb, checksumDefinitions ) ;
632 
633  Q_FOREACH( const Dir & dir, dirs )
634  kDebug() << dir;
635 
636  if ( !canceled ) {
637 
638  emit progress( 0, 0, i18n("Calculating total size...") );
639 
640  const quint64 total
641  = kdtools::accumulate_transform( dirs, mem_fn( &Dir::totalSize ), Q_UINT64_C(0) );
642 
643  if ( !canceled ) {
644 
645  //
646  // Step 2: perform work (with progress reporting):
647  //
648 
649  // re-scale 'total' to fit into ints (wish QProgressDialog would use quint64...)
650  const quint64 factor = total / std::numeric_limits<int>::max() + 1 ;
651 
652  quint64 done = 0;
653  Q_FOREACH( const Dir & dir, dirs ) {
654  emit progress( done/factor, total/factor,
655  i18n("Checksumming (%2) in %1", dir.checksumDefinition->label(), dir.dir.path() ) );
656  bool fatal = false;
657  const QString error = process( dir, &fatal );
658  if ( !error.isEmpty() )
659  errors.push_back( error );
660  else
661  created.push_back( dir.dir.absoluteFilePath( dir.sumFile ) );
662  done += dir.totalSize;
663  if ( fatal || canceled )
664  break;
665  }
666  emit progress( done/factor, total/factor, i18n("Done.") );
667 
668  }
669  }
670 
671  locker.relock();
672 
673  this->errors = errors;
674  this->created = created;
675 
676  // mutex unlocked by QMutexLocker
677 
678 }
679 
680 #include "moc_createchecksumscontroller.cpp"
681 #include "createchecksumscontroller.moc"
HAVE_UNIX
static const bool HAVE_UNIX
Definition: createchecksumscontroller.cpp:162
QMutex
QWidget
fs_sort
static QStringList fs_sort(QStringList l)
Definition: createchecksumscontroller.cpp:167
QSize::isValid
bool isValid() const
parse_sum_file
static std::vector< File > parse_sum_file(const QString &fileName)
Definition: createchecksumscontroller.cpp:403
QRegExp::cap
QString cap(int nth) const
Kleo::ExecutionContextUser::applyWindowID
void applyWindowID(QWidget *wid)
Definition: types.cpp:73
output.h
input.h
QTextStream::readLine
QString readLine(qint64 maxlen)
QByteArray::trimmed
QByteArray trimmed() const
QList::push_back
void push_back(const T &value)
QByteArray
get_patterns
static QList< QRegExp > get_patterns(const std::vector< shared_ptr< ChecksumDefinition > > &checksumDefinitions)
Definition: createchecksumscontroller.cpp:185
QIODevice::errorString
QString errorString() const
QProcess::error
QProcess::ProcessError error() const
QChar
QString::size
int size() const
QPointer< QProgressDialog >
classify.h
fs_intersect
static QStringList fs_intersect(QStringList l1, QStringList l2)
Definition: createchecksumscontroller.cpp:173
QList::erase
iterator erase(iterator pos)
QStringList::join
QString join(const QString &separator) const
QListWidget
Kleo::Crypto::CreateChecksumsController::CreateChecksumsController
CreateChecksumsController(QObject *parent=0)
Definition: createchecksumscontroller.cpp:283
Kleo::Crypto::CreateChecksumsController
Definition: createchecksumscontroller.h:52
QFile
QTextStream
QList::size
int size() const
fs_cs
static const Qt::CaseSensitivity fs_cs
Definition: createchecksumscontroller.cpp:165
Kleo::Crypto::CreateChecksumsController::start
void start()
Definition: createchecksumscontroller.cpp:321
kleo_assert.h
QRegExp
QRect
boost::shared_ptr< ChecksumDefinition >
QString::fromLocal8Bit
QString fromLocal8Bit(const char *str, int size)
d
#define d
Definition: adduseridcommand.cpp:89
QTextStream::atEnd
bool atEnd() const
QList::empty
bool empty() const
Kleo::Crypto::CreateChecksumsController::allowAddition
bool allowAddition() const
Definition: createchecksumscontroller.cpp:316
QFileInfo::isDir
bool isDir() const
QProcess::setStandardOutputFile
void setStandardOutputFile(const QString &fileName, QFlags< QIODevice::OpenModeFlag > mode)
QFileInfo::fileName
QString fileName() const
aggregate_size
static quint64 aggregate_size(const QDir &dir, const QStringList &files)
Definition: createchecksumscontroller.cpp:425
QProcess
QObject
process
static QString process(const Dir &dir, bool *fatal)
Definition: createchecksumscontroller.cpp:557
remove_checksum_files
static QStringList remove_checksum_files(QStringList l, const QList< QRegExp > &rxs)
Definition: createchecksumscontroller.cpp:362
QFileInfo::absoluteFilePath
QString absoluteFilePath() const
QString::isEmpty
bool isEmpty() const
QByteArray::constData
const char * constData() const
operator<<
QDebug operator<<(QDebug debug, const std::vector< T, A > &v)
Definition: headerview.cpp:78
Kleo::Crypto::CreateChecksumsController::cancel
void cancel()
Definition: createchecksumscontroller.cpp:344
KDAB_SET_OBJECT_NAME
#define KDAB_SET_OBJECT_NAME(x)
Definition: kdtoolsglobal.h:66
QVBoxLayout
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
QtConcurrent::run
QFuture< T > run(Function function,...)
find_dirs_by_input_files
static std::vector< Dir > find_dirs_by_input_files(const QStringList &files, const shared_ptr< ChecksumDefinition > &checksumDefinition, bool allowAddition, const function< void(int)> &progress, const std::vector< shared_ptr< ChecksumDefinition > > &checksumDefinitions)
Definition: createchecksumscontroller.cpp:496
QFileInfo::dir
QDir dir() const
QString
QList
Definition: commands/command.h:46
mutex
static QMutex mutex
Definition: sessiondata.cpp:50
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QList::iterator
QStringList
QFileInfo
QList::end
iterator end()
QSize
QLatin1Char
QProcess::setWorkingDirectory
void setWorkingDirectory(const QString &dir)
QChar::toLatin1
char toLatin1() const
QDebug
kleo_assert
#define kleo_assert(cond)
Definition: kleo_assert.h:86
QDir
dir
static QString dir(const QString &id)
Definition: filedialog.cpp:54
Kleo::Crypto::CreateChecksumsController::setAllowAddition
void setAllowAddition(bool allow)
Definition: createchecksumscontroller.cpp:310
createchecksumscontroller.h
QString::toLatin1
QByteArray toLatin1() const
QRect::width
int width() const
find_dirs_by_sum_files
static std::vector< Dir > find_dirs_by_sum_files(const QStringList &files, bool allowAddition, const function< void(int)> &progress, const std::vector< shared_ptr< ChecksumDefinition > > &checksumDefinitions)
Definition: createchecksumscontroller.cpp:443
QLatin1String
QDir::absolutePath
QString absolutePath() const
QMutexLocker
Ok
Definition: setinitialpindialog.cpp:61
QDir::entryList
QStringList entryList(QFlags< QDir::Filter > filters, QFlags< QDir::SortFlag > sort) const
QDialogButtonBox
q
#define q
Definition: adduseridcommand.cpp:90
Kleo::Crypto::CreateChecksumsController::setFiles
void setFiles(const QStringList &files)
Definition: createchecksumscontroller.cpp:299
QDir::absoluteFilePath
QString absoluteFilePath(const QString &fileName) const
QString::reserve
void reserve(int size)
name
const char * name
Definition: uiserver/selectcertificatecommand.cpp:113
QDialog
Qt::WindowFlags
typedef WindowFlags
Kleo::Crypto::CreateChecksumsController::~CreateChecksumsController
~CreateChecksumsController()
Definition: createchecksumscontroller.cpp:295
QThread
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLabel
QProgressDialog
QString::compare
int compare(const QString &other) const
QRegExp::exactMatch
bool exactMatch(const QString &str) const
QRect::united
QRect united(const QRect &rectangle) const
QProcess::exitStatus
QProcess::ExitStatus exitStatus() const
QList::begin
iterator begin()
Kleo::Crypto::Controller
Definition: controller.h:52
QProcess::exitCode
int exitCode() const
QProcess::readAllStandardError
QByteArray readAllStandardError()
filename2definition
static shared_ptr< ChecksumDefinition > filename2definition(const QString &fileName, const std::vector< shared_ptr< ChecksumDefinition > > &checksumDefinitions)
Definition: createchecksumscontroller.cpp:432
decode
static QString decode(const QString &encoded)
Definition: createchecksumscontroller.cpp:379
QProcess::waitForFinished
bool waitForFinished(int msecs)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

Skip menu "kleopatra"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal