AstRawDark
Manage your astrophoto dark frames
 All Classes Functions Variables Enumerations Enumerator Pages
abstractScanCommand.cpp
1 /*
2  * AstRawDark
3  *
4  * Copyright (C) 2015 - Frédéric CORNU
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "abstractScanCommand.h"
21 #include "data/access/exifReader.h"
22 
23 #include <QDirIterator>
24 
25 AbstractScanCommand::AbstractScanCommand(const QStringList sources)
26  : _sources(sources)
27 {
28 
29 }
30 
31 void AbstractScanCommand::getRawPathsInDirectory(const QString directory)
32 {
33  /*
34  * retrieve paths of all RAW files located in current dark source folder,
35  * including subdirectories
36  */
37  _message = tr("Locating raw files...");
38  emit statusChanged(this);
39 
40  QDirIterator it(directory,
41  QStringList() << "*.CR2" << "*.CRW",
42  QDir::NoDotAndDotDot | QDir::Files,
43  QDirIterator::Subdirectories);
44 
45  int found=0;
46  while (it.hasNext()) {
47 
48  _imagePaths << it.next();
49  _message = tr("%1 RAW file(s) found").arg(++found);
50  emit statusChanged(this);
51  }
52 
53  _message = tr("%1 RAW file(s) found").arg(found);
54  emit statusChanged(this);
55 }
56 
58 {
59  int fileCount = 0;
60  emit progressMax(_imagePaths.count());
61 
62  /*
63  * Retrieve EXIF metadata for each RAW file
64  */
65  foreach (QString path, _imagePaths) {
66 
67  ImageInfo imageInfo(path);
68 
69  if ( ! ExifReader::retrieveExifMetadata(imageInfo) ) {
70 
71  _badFilesPaths << imageInfo.getPath();
72 
73  }
74  else if ( imageInfo.getExposure() < 1 ) {
75 
76  _shortFilesPaths << imageInfo.getPath();
77 
78  } else {
79 
80  _imageInfos << imageInfo;
81  }
82 
83  _message = tr("Scanned file %1 / %2").arg(++fileCount).arg(_imagePaths.count());
84  emit statusChanged(this);
85  emit progress(fileCount);
86  }
87 }
88 
90 {
91 
92 }
93 
95 {
96  if ( ! _shortFilesPaths.isEmpty() ) {
97 
98  _warning = true;
99 
100  QString msg = tr("WARNING - Ignored %1 short exposure image(s)")
101  .arg(_shortFilesPaths.count());
102 
103  _reportMessages << msg;
104 
106  }
107 
108  /*
109  * If we saw bad files, update error message
110  */
111  if ( ! _badFilesPaths.isEmpty() ) {
112 
113  _warning = true;
114 
115  QString msg = tr("WARNING - Ignored %1 invalid RAW file(s)")
116  .arg(_badFilesPaths.count());
117 
118  _reportMessages << msg;
119 
121  }
122 
123  if ( ! _warning && ! _error ) {
124 
125  _reportMessages << tr("OK");
126  _commandReport.addSection(tr("Completed successfully"),QStringList());
127 
128  }
129 }
130