AstRawDark
Manage your astrophoto dark frames
 All Classes Functions Variables Enumerations Enumerator Pages
darkCopyCommand.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 "darkCopyCommand.h"
21 #include "data/dto/imageInfo.h"
22 #include "data/dataStore.h"
23 
24 #include <QFileInfo>
25 
26 #ifndef QT_NO_DEBUG
27 #include <QDebug>
28 #endif
29 
30 DarkCopyCommand::DarkCopyCommand() {
31 
32  _description = tr("Copy darks");
33 
34 }
35 
36 DarkCopyCommand::~DarkCopyCommand() {
37 
38 
39 }
40 
42 
43 #ifndef QT_NO_DEBUG
44  qDebug() << "DarkCopyCommand::do_processing -- START";
45 #endif
46 
47  // Get matched darks from dataStore
48  QList<ImageInfo> darks = DataStore::getInstance()->getMatchedDarks();
49 
50  // get destination folder path
51  QString copyPath = DataStore::getInstance()->getDarkCopyFolderPath();
52 
53  // get infos from the first dark, since they are all shot with same settings
54  ImageInfo reference = darks.at(0);
55 
56  int expopsure = reference.getExposure();
57  int iso = reference.getIso();
58 
59  int currentProgress = 0;
60  emit progressMax(darks.size());
61 
62  QStringList copiedFilesReports;
63 
64  foreach ( ImageInfo dark, darks ) {
65 
66  QFile sourceFile(dark.getPath());
67  QFileInfo sourceInfo(sourceFile);
68  int temperature = dark.getTemperature();
69 
70  QString destFileName = QString("%1_iso%2_%3sec_%4C.%5")
71  .arg(currentProgress +1, 4, 10, QLatin1Char('0'))
72  .arg(iso)
73  .arg(expopsure)
74  .arg(temperature)
75  .arg(sourceInfo.completeSuffix());
76 
77  QString sourcePath = sourceInfo.filePath();
78  QString destFilePath = copyPath + "/" + destFileName;
79 
80  _message = tr("Copying file %1/%2").arg(currentProgress +1 ).arg(darks.size());
81 
82  if ( sourceFile.copy( destFilePath) ) {
83 
84  copiedFilesReports << tr("Copied %1\nto %2\n").arg(sourcePath).arg(destFilePath);
85 
86  } else {
87 
88  _error = true;
89  QString msg = tr("Error on file copy");
90 
91  QStringList errorDetails;
92  errorDetails << tr("Could not copy %1\nto\n%2").arg(sourcePath).arg(destFilePath);
93 
94  _reportMessages << msg;
95  _commandReport.addSection(msg, errorDetails);
96 
97 #ifndef QT_NO_DEBUG
98  qDebug() << "Failed copy to " << destFilePath;
99 #endif
100  break;
101  }
102 
103  emit progress(++currentProgress);
104  emit statusChanged(this);
105  }
106 
107  if ( ! _error ) {
108 
109  _reportMessages << tr("OK");
110  _commandReport.addSection(tr("Completed successfully"),copiedFilesReports);
111  }
112 
113 }