Qt6: Avoid timestamp string conversion
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Syping 2020-11-05 18:32:20 +01:00
parent 699f5b8f55
commit 4d9cd2d9ff
3 changed files with 48 additions and 11 deletions

View file

@ -61,6 +61,7 @@
#include <QUrl>
#include <QDir>
#include <cstdint>
#include <random>
#include <ctime>
@ -760,7 +761,11 @@ bool ProfileInterface::importFile(QString selectedFile, QDateTime importDateTime
}
spJson.createdDateTime = importDateTime;
#if QT_VERSION >= 0x060000
spJson.createdTimestamp = QString::number(spJson.createdDateTime.toSecsSinceEpoch()).toUInt();
quint64 timestamp = spJson.createdDateTime.toSecsSinceEpoch();
if (timestamp > UINT32_MAX) {
timestamp = UINT32_MAX;
}
spJson.createdTimestamp = (quint32)timestamp;
#else
spJson.createdTimestamp = spJson.createdDateTime.toTime_t();
#endif
@ -818,7 +823,11 @@ bool ProfileInterface::importFile(QString selectedFile, QDateTime importDateTime
}
spJson.createdDateTime = importDateTime;
#if QT_VERSION >= 0x060000
spJson.createdTimestamp = QString::number(spJson.createdDateTime.toSecsSinceEpoch()).toUInt();
quint64 timestamp = spJson.createdDateTime.toSecsSinceEpoch();
if (timestamp > UINT32_MAX) {
timestamp = UINT32_MAX;
}
spJson.createdTimestamp = (quint32)timestamp;
#else
spJson.createdTimestamp = spJson.createdDateTime.toTime_t();
#endif
@ -1067,7 +1076,11 @@ bool ProfileInterface::importImage(QImage *snapmaticImage, QDateTime importDateT
}
spJson.createdDateTime = importDateTime;
#if QT_VERSION >= 0x060000
spJson.createdTimestamp = QString::number(spJson.createdDateTime.toSecsSinceEpoch()).toUInt();
quint64 timestamp = spJson.createdDateTime.toSecsSinceEpoch();
if (timestamp > UINT32_MAX) {
timestamp = UINT32_MAX;
}
spJson.createdTimestamp = (quint32)timestamp;
#else
spJson.createdTimestamp = spJson.createdDateTime.toTime_t();
#endif
@ -1115,7 +1128,11 @@ bool ProfileInterface::importSnapmaticPicture(SnapmaticPicture *picture, bool wa
snapmaticProperties.uid = getRandomUid();
snapmaticProperties.createdDateTime = QDateTime::currentDateTime();
#if QT_VERSION >= 0x060000
snapmaticProperties.createdTimestamp = QString::number(snapmaticProperties.createdDateTime.toSecsSinceEpoch()).toUInt();
quint64 timestamp = snapmaticProperties.createdDateTime.toSecsSinceEpoch();
if (timestamp > UINT32_MAX) {
timestamp = UINT32_MAX;
}
snapmaticProperties.createdTimestamp = (quint32)timestamp;
#else
snapmaticProperties.createdTimestamp = snapmaticProperties.createdDateTime.toTime_t();
#endif
@ -1156,7 +1173,11 @@ bool ProfileInterface::importSnapmaticPicture(SnapmaticPicture *picture, bool wa
snapmaticProperties.uid = getRandomUid();
snapmaticProperties.createdDateTime = QDateTime::currentDateTime();
#if QT_VERSION >= 0x060000
snapmaticProperties.createdTimestamp = QString::number(snapmaticProperties.createdDateTime.toSecsSinceEpoch()).toUInt();
quint64 timestamp = snapmaticProperties.createdDateTime.toSecsSinceEpoch();
if (timestamp > UINT32_MAX) {
timestamp = UINT32_MAX;
}
snapmaticProperties.createdTimestamp = (quint32)timestamp;
#else
snapmaticProperties.createdTimestamp = snapmaticProperties.createdDateTime.toTime_t();
#endif

View file

@ -41,10 +41,10 @@ void ProfileLoader::run()
profileDir.setPath(profileFolder);
// Seek pictures and savegames
profileDir.setNameFilters(QStringList("SGTA*"));
profileDir.setNameFilters(QStringList("SGTA5*"));
QStringList SavegameFiles = profileDir.entryList(QDir::Files | QDir::NoDot, QDir::NoSort);
QStringList BackupFiles = SavegameFiles.filter(".bak", Qt::CaseInsensitive);
profileDir.setNameFilters(QStringList("PGTA*"));
profileDir.setNameFilters(QStringList("PGTA5*"));
QStringList SnapmaticPics = profileDir.entryList(QDir::Files | QDir::NoDot, QDir::NoSort);
BackupFiles += SnapmaticPics.filter(".bak", Qt::CaseInsensitive);

View file

@ -998,7 +998,7 @@ void SnapmaticPicture::parseJsonContent()
QDateTime createdTimestamp;
localProperties.createdTimestamp = jsonMap["creat"].toUInt(&timestampOk);
#if QT_VERSION >= 0x060000
createdTimestamp.setSecsSinceEpoch(QString::number(localProperties.createdTimestamp).toLongLong());
createdTimestamp.setSecsSinceEpoch(localProperties.createdTimestamp);
#else
createdTimestamp.setTime_t(localProperties.createdTimestamp);
#endif
@ -1280,9 +1280,25 @@ void SnapmaticPicture::setPicFilePath(const QString &picFilePath_)
bool SnapmaticPicture::deletePicFile()
{
if (!QFile::exists(picFilePath)) return true;
if (QFile::remove(picFilePath)) return true;
return false;
bool success = false;
if (!QFile::exists(picFilePath))
{
success = true;
}
else if (QFile::remove(picFilePath))
{
success = true;
}
if (isHidden())
{
const QString picBakPath = QString(picFilePath).remove(picFilePath.length() - 7, 7) % ".bak";
if (QFile::exists(picBakPath)) QFile::remove(picBakPath);
}
else {
const QString picBakPath = picFilePath % ".bak";
if (QFile::exists(picBakPath)) QFile::remove(picBakPath);
}
return success;
}
// VISIBILITY