From 7568582b056c1b32a0b9917ef483ee8ee08c9afc Mon Sep 17 00:00:00 2001 From: Andreas Piesk Date: Wed, 9 May 2012 20:29:21 +0200 Subject: [PATCH] compile with QT < 4.7 (RHEL6 an clones) --- CMakeLists.txt | 2 +- src/core/Database.cpp | 7 ++++--- src/core/Entry.cpp | 7 ++++--- src/core/Group.cpp | 9 +++++---- src/core/Metadata.cpp | 5 +++-- src/core/TimeInfo.cpp | 4 +++- src/core/Tools.cpp | 9 +++++++++ src/core/Tools.h | 2 ++ tests/TestModified.cpp | 3 ++- 9 files changed, 33 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0313ac1cb..d9b7b4ad3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ project(KeePassX) -cmake_minimum_required(VERSION 2.8.0) +cmake_minimum_required(VERSION 2.6.4) set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake ) diff --git a/src/core/Database.cpp b/src/core/Database.cpp index dbaffa981..cab479684 100644 --- a/src/core/Database.cpp +++ b/src/core/Database.cpp @@ -22,6 +22,7 @@ #include "core/Group.h" #include "core/Metadata.h" +#include "core/Tools.h" #include "crypto/Random.h" #include "format/KeePass2.h" @@ -133,7 +134,7 @@ void Database::addDeletedObject(const DeletedObject& delObj) void Database::addDeletedObject(const Uuid& uuid) { DeletedObject delObj; - delObj.deletionTime = QDateTime::currentDateTimeUtc(); + delObj.deletionTime = Tools::currentDateTimeUtc(); delObj.uuid = uuid; addDeletedObject(delObj); @@ -190,7 +191,7 @@ void Database::setKey(const CompositeKey& key, const QByteArray& transformSeed, m_transformedMasterKey = key.transform(transformSeed, transformRounds()); m_hasKey = true; if (updateChangedTime) { - m_metadata->setMasterKeyChanged(QDateTime::currentDateTimeUtc()); + m_metadata->setMasterKeyChanged(Tools::currentDateTimeUtc()); } Q_EMIT modified(); } @@ -205,7 +206,7 @@ void Database::updateKey(quint64 rounds) if (m_transformRounds != rounds) { m_transformRounds = rounds; m_transformedMasterKey = m_key.transform(m_transformSeed, transformRounds()); - m_metadata->setMasterKeyChanged(QDateTime::currentDateTimeUtc()); + m_metadata->setMasterKeyChanged(Tools::currentDateTimeUtc()); Q_EMIT modified(); } } diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index 178c5aae7..fb5926ecc 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -21,6 +21,7 @@ #include "core/DatabaseIcons.h" #include "core/Group.h" #include "core/Metadata.h" +#include "core/Tools.h" Entry::Entry() { @@ -70,8 +71,8 @@ template bool Entry::set(T& property, const T& value) void Entry::updateTimeinfo() { if (m_updateTimeinfo) { - m_data.timeInfo.setLastModificationTime(QDateTime::currentDateTimeUtc()); - m_data.timeInfo.setLastAccessTime(QDateTime::currentDateTimeUtc()); + m_data.timeInfo.setLastModificationTime(Tools::currentDateTimeUtc()); + m_data.timeInfo.setLastAccessTime(Tools::currentDateTimeUtc()); } } @@ -419,7 +420,7 @@ void Entry::setGroup(Group* group) QObject::setParent(group); if (m_updateTimeinfo) { - m_data.timeInfo.setLocationChanged(QDateTime::currentDateTimeUtc()); + m_data.timeInfo.setLocationChanged(Tools::currentDateTimeUtc()); } } diff --git a/src/core/Group.cpp b/src/core/Group.cpp index 6996725eb..93060fe4f 100644 --- a/src/core/Group.cpp +++ b/src/core/Group.cpp @@ -19,6 +19,7 @@ #include "core/DatabaseIcons.h" #include "core/Metadata.h" +#include "core/Tools.h" Group::Group() { @@ -48,7 +49,7 @@ Group::~Group() } DeletedObject delGroup; - delGroup.deletionTime = QDateTime::currentDateTimeUtc(); + delGroup.deletionTime = Tools::currentDateTimeUtc(); delGroup.uuid = m_uuid; m_db->addDeletedObject(delGroup); } @@ -69,8 +70,8 @@ template bool Group::set(P& property, const V& value) { void Group::updateTimeinfo() { if (m_updateTimeinfo) { - m_timeInfo.setLastModificationTime(QDateTime::currentDateTimeUtc()); - m_timeInfo.setLastAccessTime(QDateTime::currentDateTimeUtc()); + m_timeInfo.setLastModificationTime(Tools::currentDateTimeUtc()); + m_timeInfo.setLastAccessTime(Tools::currentDateTimeUtc()); } } @@ -302,7 +303,7 @@ void Group::setParent(Group* parent, int index) } if (m_updateTimeinfo) { - m_timeInfo.setLocationChanged(QDateTime::currentDateTimeUtc()); + m_timeInfo.setLocationChanged(Tools::currentDateTimeUtc()); } Q_EMIT modified(); diff --git a/src/core/Metadata.cpp b/src/core/Metadata.cpp index 266cf5547..ac0ba709a 100644 --- a/src/core/Metadata.cpp +++ b/src/core/Metadata.cpp @@ -20,6 +20,7 @@ #include "core/Database.h" #include "core/Entry.h" #include "core/Group.h" +#include "core/Tools.h" Metadata::Metadata(Database* parent) : QObject(parent) @@ -33,7 +34,7 @@ Metadata::Metadata(Database* parent) m_historyMaxItems = 10; m_historyMaxSize = 6291456; - QDateTime now = QDateTime::currentDateTimeUtc(); + QDateTime now = Tools::currentDateTimeUtc(); m_nameChanged = now; m_descriptionChanged = now; m_defaultUserNameChanged = now; @@ -67,7 +68,7 @@ template bool Metadata::set(P& property, const V& value, QDat if (property != value) { property = value; if (m_updateDatetime) { - dateTime = QDateTime::currentDateTimeUtc(); + dateTime = Tools::currentDateTimeUtc(); } Q_EMIT modified(); return true; diff --git a/src/core/TimeInfo.cpp b/src/core/TimeInfo.cpp index 404e2bbf1..06f2aa7d5 100644 --- a/src/core/TimeInfo.cpp +++ b/src/core/TimeInfo.cpp @@ -17,12 +17,14 @@ #include "TimeInfo.h" +#include "core/Tools.h" + TimeInfo::TimeInfo() { m_expires = false; m_usageCount = 0; - QDateTime now = QDateTime::currentDateTimeUtc(); + QDateTime now = Tools::currentDateTimeUtc(); m_lastModificationTime = now; m_creationTime = now; m_lastAccessTime = now; diff --git a/src/core/Tools.cpp b/src/core/Tools.cpp index 77a7df910..a4a017fcf 100644 --- a/src/core/Tools.cpp +++ b/src/core/Tools.cpp @@ -75,4 +75,13 @@ bool readAllFromDevice(QIODevice* device, QByteArray& data) } } +QDateTime currentDateTimeUtc () +{ +#if QT_VERSION >= 0x040700 + return QDateTime::currentDateTimeUtc(); +#else + return QDateTime::currentDateTime().toUTC(); +#endif +} + } // namespace Tools diff --git a/src/core/Tools.h b/src/core/Tools.h index 75cd6dd67..b1e0b1ada 100644 --- a/src/core/Tools.h +++ b/src/core/Tools.h @@ -20,6 +20,7 @@ #include #include +#include class QIODevice; @@ -28,6 +29,7 @@ namespace Tools { QString humanReadableFileSize(qint64 bytes); bool hasChild(const QObject* parent, const QObject* child); bool readAllFromDevice(QIODevice* device, QByteArray& data); +QDateTime currentDateTimeUtc(); } // namespace Tools diff --git a/tests/TestModified.cpp b/tests/TestModified.cpp index 6f3615f60..4551485a6 100644 --- a/tests/TestModified.cpp +++ b/tests/TestModified.cpp @@ -23,6 +23,7 @@ #include "tests.h" #include "core/Database.h" #include "core/Group.h" +#include "core/Tools.h" #include "crypto/Crypto.h" void TestModified::initTestCase() @@ -233,7 +234,7 @@ void TestModified::testEntrySets() entry->setExpires(entry->timeInfo().expires()); QCOMPARE(spyModified.count(), spyCount); - entry->setExpiryTime(QDateTime::currentDateTimeUtc().addYears(1)); + entry->setExpiryTime(Tools::currentDateTimeUtc().addYears(1)); QCOMPARE(spyModified.count(), ++spyCount); entry->setExpiryTime(entry->timeInfo().expiryTime()); QCOMPARE(spyModified.count(), spyCount);