3 #include "CnetDisplayProperties.h" 11 #include <QFutureWatcher> 13 #include <QReadWriteLock> 15 #include <QStringList> 16 #include <QTextStream> 18 #include <QtConcurrentRun> 28 CnetDisplayProperties *CnetDisplayProperties::m_instance = NULL;
31 CnetDisplayProperties *CnetDisplayProperties::getInstance() {
32 return m_instance ? m_instance : m_instance =
new CnetDisplayProperties;
36 CnetDisplayProperties::CnetDisplayProperties() {
40 m_curComposing =
false;
41 m_showFullPath =
false;
43 m_readWriteLock =
new QReadWriteLock;
47 m_composedCount =
new QAtomicInt;
48 m_interruptFlag =
new QAtomicInt;
49 m_interruptFlag->fetchAndStoreRelaxed(0);
51 m_composeStatusPoller =
new QTimer;
52 connect(m_composeStatusPoller, SIGNAL(timeout()),
53 this, SLOT(composeStatusUpdated()));
56 connect(m_composeWatcher, SIGNAL(finished()),
57 this, SLOT(serialNumbersComposed()));
78 CnetDisplayProperties::~CnetDisplayProperties() {
79 delete m_serialNumberToFileNameMap;
80 m_serialNumberToFileNameMap = NULL;
82 delete m_composeWatcher;
83 m_composeWatcher = NULL;
85 delete m_composedCount;
86 m_composedCount = NULL;
88 delete m_interruptFlag;
89 m_interruptFlag = NULL;
93 bool CnetDisplayProperties::currentlyComposing()
const {
94 return m_curComposing;
109 if (!currentlyComposing()) {
111 QString possibleFileName =
getImageName(serialNumber,
true);
113 if (possibleFileName != serialNumber)
114 results.append(possibleFileName);
122 QString CnetDisplayProperties::getFileName(QString fileName,
123 bool forceFullPaths)
const {
126 if (forceFullPaths || getShowsFullPaths())
129 result = QFileInfo(fileName).fileName();
147 bool forceFullPaths)
const {
148 ASSERT(m_serialNumberToFileNameMap);
150 QString imageName = cubeSerialNumber;
152 m_readWriteLock->lockForRead();
154 if (m_serialNumberToFileNameMap && useFileNames &&
155 m_serialNumberToFileNameMap->contains(cubeSerialNumber)) {
156 QString value = m_serialNumberToFileNameMap->value(cubeSerialNumber);
157 m_readWriteLock->unlock();
159 if (value.toLower() !=
"unknown")
160 imageName = getFileName(value, forceFullPaths);
163 m_readWriteLock->unlock();
170 QString CnetDisplayProperties::getSerialNumber(QString imageId) {
171 ASSERT(m_serialNumberToFileNameMap);
173 QString sn = imageId;
175 if (m_serialNumberToFileNameMap && useFileNames) {
176 m_readWriteLock->lockForRead();
177 QMapIterator< QString, QString > i(*m_serialNumberToFileNameMap);
180 while (!found && i.hasNext()) {
182 if (i.value() == imageId) {
188 m_readWriteLock->unlock();
195 bool CnetDisplayProperties::getShowsFullPaths()
const {
196 return m_showFullPath;
200 void CnetDisplayProperties::setCubeList(QString fileName) {
201 QFile imageListFile(fileName);
203 if (!imageListFile.exists()) {
204 IString msg =
"The file [";
205 msg += (IString) fileName;
206 msg +=
"] does not exist.\n";
210 if (!imageListFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
211 IString msg =
"The file [";
212 msg += (IString) fileName;
213 msg +=
"] failed to open.\n";
218 QTextStream ts(&imageListFile);
221 imageFileNames << ts.readLine();
223 imageListFile.close();
225 m_curComposing =
true;
227 QFuture< QMap< QString, QString > > future = QtConcurrent::run(
228 this, &CnetDisplayProperties::composeSerialNumbers, imageFileNames);
230 m_composeWatcher->setFuture(future);
234 void CnetDisplayProperties::setFileNameUsage(
bool preferFileNames) {
235 useFileNames = preferFileNames;
252 void CnetDisplayProperties::setShowsFullPaths(
bool newState) {
253 m_showFullPath = newState;
259 emit composeProgressRangeChanged(0, fileNames.size() - 1);
260 m_composedCount->fetchAndStoreRelaxed(0);
264 for (
int i = 0; *m_interruptFlag == 0 && i < fileNames.size(); i++) {
265 QString fileName = fileNames[i];
272 m_composedCount->fetchAndAddRelaxed(1);
279 void CnetDisplayProperties::nullify() {
280 m_serialNumberToFileNameMap = NULL;
281 m_composeWatcher = NULL;
283 m_composedCount = NULL;
284 m_interruptFlag = NULL;
286 m_readWriteLock = NULL;
290 void CnetDisplayProperties::composeStatusUpdated() {
291 emit composeProgressChanged(*m_composedCount);
295 void CnetDisplayProperties::serialNumbersComposed() {
296 if (*m_interruptFlag) {
297 m_interruptFlag->fetchAndStoreRelaxed(0);
300 m_readWriteLock->lockForWrite();
301 *m_serialNumberToFileNameMap = m_composeWatcher->result();
303 m_readWriteLock->unlock();
306 m_curComposing =
false;
307 m_composeStatusPoller->stop();
308 emit composeProgressRangeChanged(0, 0);
309 emit composeProgressChanged(0);
310 emit compositionFinished();
QString getImageName(QString cubeSerialNumber, bool forceFullPaths=false) const
This error is for when a programmer made an API call that was illegal.
static QString Compose(Pvl &label, bool def2filename=false)
Compose a SerialNumber from a PVL.
QList< QString > getCubeList(ControlNet *cnet) const
TODO comment me.
#define _FILEINFO_
Macro for the filename and line number.
QList< QString > GetCubeSerials() const
Use this method to get a complete list of all the cube serial numbers in the network.
Namespace for ISIS/Bullet specific routines.