Commit 1e586ed4 authored by Karel Slaný's avatar Karel Slaný
Browse files

Showing only last update date or time.

parent a05f3223
......@@ -212,10 +212,10 @@ int main(int argc, char *argv[])
/* OpenSSL support test */
if (QSslSocket::supportsSsl()) {
/* set last update text to status bar */
if (!globSet.lastUpdate.isEmpty() && globSet.pinCode.isEmpty()) {
if (!globSet.lastUpdateStr().isEmpty() && globSet.pinCode.isEmpty()) {
emit isds.statusBarTextChanged(
QObject::tr("Last synchronisation: %1").
arg(globSet.lastUpdate), false);
arg(globSet.lastUpdateStr()), false);
}
} else {
emit isds.showErrorMessageBox(QObject::tr("Security problem"),
......
......@@ -197,8 +197,7 @@ bool IsdsWrapper::syncSingleAccountReceived(const QString &userName)
m_isdsSession.isdsCtxMap[userName].last_isds_msg, false);
}
globSet.lastUpdate =
QDateTime::currentDateTime().toString("dd.MM.yyyy HH:mm:ss");
globSet.setLastUpdateToNow();
saveAllSettings();
if (globSet.downloadCompleteMsgs) {
......
......@@ -21,6 +21,7 @@
* the two.
*/
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QStandardPaths>
......@@ -44,8 +45,8 @@ Settings::Settings(void)
pinAlg(),
pinSalt(),
pinCode(),
lastUpdate(""),
dbsLocation("")
dbsLocation(""),
m_lastUpdate()
{
}
......@@ -81,7 +82,7 @@ void Settings::saveToSettings(QSettings &settings) const
QString::fromUtf8(pinCode.toBase64()));
}
settings.setValue(SETTINGS_LAST_UPDATE, lastUpdate);
settings.setValue(SETTINGS_LAST_UPDATE, m_lastUpdate);
if (dbsLocation != getDefaultDbAndConfigLocation()) {
settings.setValue(SETTINGS_DBS_LOCATION, dbsLocation);
......@@ -124,8 +125,8 @@ void Settings::loadFromSettings(const QSettings &settings)
SETTINGS_GLOBAL_GROUP "/" SETTINGS_PIN_CODE,
QString()).toString().toUtf8());
lastUpdate = settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_LAST_UPDATE).toString();
setLastUpdate(settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_LAST_UPDATE).toString());
dbsLocation = settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_DBS_LOCATION).toString();
......@@ -153,6 +154,42 @@ QString Settings::settingsPath(void)
QStringLiteral(SETTINGS_FILE_NAME);
}
void Settings::setLastUpdate(const QString &str)
{
QDateTime dateTime(QDateTime::fromString(str, Qt::ISODate));
if (dateTime.isValid()) {
m_lastUpdate = dateTime.toString(Qt::ISODate);
} else {
m_lastUpdate.clear();
}
}
void Settings::setLastUpdateToNow(void)
{
m_lastUpdate = QDateTime::currentDateTime().toString(Qt::ISODate);
}
QString Settings::lastUpdateStr(void) const
{
#define DATE_FMT QStringLiteral("yyyy-MM-dd")
QDateTime lastUpdateDateTime(
QDateTime::fromString(m_lastUpdate, Qt::ISODate));
if (!lastUpdateDateTime.isValid()) {
return QString();
}
QDateTime currentDateTime(QDateTime::currentDateTime());
if (lastUpdateDateTime.toString(DATE_FMT) ==
currentDateTime.toString(DATE_FMT)) {
/* Only time. */
return lastUpdateDateTime.toString("HH:mm:ss");
} else {
/* Only date. */
return lastUpdateDateTime.toString("dd.MM.yyyy");
}
#undef DATE_FMT
}
void saveAllSettings(void)
{
QSettings settings(Settings::settingsPath(), QSettings::IniFormat);
......
......@@ -90,6 +90,27 @@ public:
static
QString settingsPath(void);
/*!
* @brief Set last update time from string.
*
* @param[in] str Time in ISO 8601 format.
*/
void setLastUpdate(const QString &str);
/*!
* @brief Set last update time to current time.
*/
void setLastUpdateToNow(void);
/*!
* @brief Returns last update time string.
*
* @return Hours minutes and seconds if last update performed today,
* date if last update performed yesterday or earlier,
* empty string if no time could be determined.
*/
QString lastUpdateStr(void) const;
/*!
* @brief Holds global settings data.
*/
......@@ -103,8 +124,10 @@ public:
QString pinAlg; /*!< PIN algorithm identifier. */
QByteArray pinSalt; /*!< Salt value used to generate PIN hash. */
QByteArray pinCode; /*!< Hashed PIN code. */
QString lastUpdate;
QString dbsLocation;
private:
QString m_lastUpdate;
};
......
......@@ -230,9 +230,9 @@ void GlobalSettingsQmlWrapper::verifyPin(const QString &pinValue)
emit sendPinReply(verResult);
if (verResult && !globSet.lastUpdate.isEmpty()) {
if (verResult && !globSet.lastUpdateStr().isEmpty()) {
emit statusBarTextChanged(tr("Last synchronisation: %1")
.arg(globSet.lastUpdate), false);
.arg(globSet.lastUpdateStr()), false);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment