Ref T292, Ref T285 function to set file timestamp

This commit is contained in:
Klaus Basan
2018-07-26 02:13:53 +02:00
parent 77f10938d9
commit 338c5b344a
4 changed files with 36 additions and 10 deletions

View File

@@ -449,12 +449,29 @@ namespace BlackMisc
void CAircraftModel::setFileTimestamp(const QDateTime &timestampUtc)
{
m_fileTimestamp = timestampUtc.toMSecsSinceEpoch();
m_fileTimestamp = timestampUtc.isValid() ? timestampUtc.toMSecsSinceEpoch() : -1;
}
void CAircraftModel::setFileTimestamp(qint64 timestamp)
{
m_fileTimestamp = timestamp;
m_fileTimestamp = (timestamp < 0) ? -1 : timestamp;
}
void CAircraftModel::setFileDetailsAndTimestamp(const QFileInfo &fileInfo)
{
this->setFileName(fileInfo.absoluteFilePath());
const QDateTime modified = fileInfo.lastModified();
if (modified.isValid())
{
this->setFileTimestamp(modified);
this->setUtcTimestamp(modified);
}
else
{
const QDateTime created = fileInfo.lastModified();
this->setFileTimestamp(created);
this->setUtcTimestamp(created);
}
}
CPixmap CAircraftModel::loadIcon(CStatusMessage &success) const
@@ -504,6 +521,7 @@ namespace BlackMisc
this->setSimulator(otherModel.getSimulator());
}
ITimestampBased::updateMissingParts(otherModel);
m_livery.updateMissingParts(otherModel.getLivery());
m_aircraftIcao.updateMissingParts(otherModel.getAircraftIcaoCode());
m_distributor.updateMissingParts(otherModel.getDistributor());

View File

@@ -40,6 +40,7 @@
#include <QString>
#include <QStringList>
#include <Qt>
#include <QFileInfo>
#include <tuple>
namespace BlackMisc
@@ -397,6 +398,9 @@ namespace BlackMisc
//! Set file timestamp
void setFileTimestamp(qint64 timestamp);
//! Set file timestamp, timestamp and file name
void setFileDetailsAndTimestamp(const QFileInfo &fileInfo);
//! Load icon from disk
CPixmap loadIcon(CStatusMessage &success) const;

View File

@@ -74,14 +74,7 @@ namespace BlackMisc
void ITimestampBased::setUtcTimestamp(const QDateTime &timestamp)
{
if (timestamp.isValid())
{
m_timestampMSecsSinceEpoch = timestamp.toMSecsSinceEpoch();
}
else
{
m_timestampMSecsSinceEpoch = -1; // invalid
}
m_timestampMSecsSinceEpoch = timestamp.isValid() ? timestamp.toMSecsSinceEpoch() : -1;
}
bool ITimestampBased::isNewerThan(const ITimestampBased &otherTimestampObj) const
@@ -266,6 +259,14 @@ namespace BlackMisc
return Compare::compare(m_timestampMSecsSinceEpoch, compareValue.m_timestampMSecsSinceEpoch);
}
void ITimestampBased::updateMissingParts(const ITimestampBased &other)
{
if (m_timestampMSecsSinceEpoch < 0)
{
m_timestampMSecsSinceEpoch = other.m_timestampMSecsSinceEpoch;
}
}
QString ITimestampWithOffsetBased::getTimestampAndOffset(bool formatted) const
{
static const QString ts("%1 (%2)");

View File

@@ -143,6 +143,9 @@ namespace BlackMisc
//! Compare for index
int comparePropertyByIndex(const CPropertyIndex &index, const ITimestampBased &compareValue) const;
//! Update missing parts
void updateMissingParts(const ITimestampBased &other);
qint64 m_timestampMSecsSinceEpoch = -1; //!< timestamp value
};