Commit 85ac5026 authored by Martin Straka's avatar Martin Straka
Browse files

Merge branch 'shorter-last-update-notification' into 'develop'

Shorter Last Update Notification

Only last update time is shown, when last update performed in the same day. Only date is shown if last update has been performed a day ago or earlier.

Addresses issue #41 .

See merge request !31
parents 1e11ade0 1e586ed4
......@@ -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()
{
}
......@@ -58,35 +59,33 @@ void Settings::saveToSettings(QSettings &settings) const
qDebug("%s()", __func__);
settings.beginGroup(SETTINGS_GLOBAL_GROUP);
settings.setValue(SETTINGS_LANGUAGE, globSet.language);
settings.setValue(SETTINGS_FONTSIZE, globSet.fontSize);
settings.setValue(SETTINGS_ONLY_NEW_MSGS, globSet.downloadOnlyNewMsgs);
settings.setValue(SETTINGS_COMPLETE_MSG, globSet.downloadCompleteMsgs);
settings.setValue(SETTINGS_MSG_LIFETIME_IN_DAYS, globSet.msgLifeTimeInDays);
settings.setValue(SETTINGS_FILE_LIFETIME_IN_DAYS,
globSet.fileLifeTimeInDays);
if (!globSet._pinVal.isEmpty()) {
settings.setValue(SETTINGS_LANGUAGE, language);
settings.setValue(SETTINGS_FONTSIZE, fontSize);
settings.setValue(SETTINGS_ONLY_NEW_MSGS, downloadOnlyNewMsgs);
settings.setValue(SETTINGS_COMPLETE_MSG, downloadCompleteMsgs);
settings.setValue(SETTINGS_MSG_LIFETIME_IN_DAYS, msgLifeTimeInDays);
settings.setValue(SETTINGS_FILE_LIFETIME_IN_DAYS, fileLifeTimeInDays);
if (!_pinVal.isEmpty()) {
//settings.setValue(SETTINGS_PIN_VAL,
// QString::fromUtf8(globSet._pinVal.toUtf8().toBase64()));
// QString::fromUtf8(_pinVal.toUtf8().toBase64()));
Q_ASSERT(!globSet.pinAlg.isEmpty());
settings.setValue(SETTINGS_PIN_ALG,
globSet.pinAlg);
Q_ASSERT(!pinAlg.isEmpty());
settings.setValue(SETTINGS_PIN_ALG, pinAlg);
Q_ASSERT(!globSet.pinSalt.isEmpty());
Q_ASSERT(!pinSalt.isEmpty());
settings.setValue(SETTINGS_PIN_SALT,
QString::fromUtf8(globSet.pinSalt.toBase64()));
QString::fromUtf8(pinSalt.toBase64()));
Q_ASSERT(!globSet.pinCode.isEmpty());
Q_ASSERT(!pinCode.isEmpty());
settings.setValue(SETTINGS_PIN_CODE,
QString::fromUtf8(globSet.pinCode.toBase64()));
QString::fromUtf8(pinCode.toBase64()));
}
settings.setValue(SETTINGS_LAST_UPDATE, globSet.lastUpdate);
settings.setValue(SETTINGS_LAST_UPDATE, m_lastUpdate);
if (globSet.dbsLocation != getDefaultDbAndConfigLocation()) {
settings.setValue(SETTINGS_DBS_LOCATION, globSet.dbsLocation);
if (dbsLocation != getDefaultDbAndConfigLocation()) {
settings.setValue(SETTINGS_DBS_LOCATION, dbsLocation);
}
settings.endGroup();
......@@ -96,47 +95,44 @@ void Settings::loadFromSettings(const QSettings &settings)
{
qDebug("%s()", __func__);
globSet.language = settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_LANGUAGE,
language = settings.value(SETTINGS_GLOBAL_GROUP "/" SETTINGS_LANGUAGE,
LANGUAGE_SYSTEM).toString();
globSet.fontSize = settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_FONTSIZE,
fontSize = settings.value(SETTINGS_GLOBAL_GROUP "/" SETTINGS_FONTSIZE,
DEFAULT_FONT_SIZE).toInt();
globSet.downloadOnlyNewMsgs = settings.value(
downloadOnlyNewMsgs = settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_ONLY_NEW_MSGS, true).toBool();
globSet.downloadCompleteMsgs = settings.value(
downloadCompleteMsgs = settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_COMPLETE_MSG, false).toBool();
globSet.msgLifeTimeInDays = settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_MSG_LIFETIME_IN_DAYS, DEFAULT_MSG_LIFETIME).toInt();
globSet.fileLifeTimeInDays = settings.value(
msgLifeTimeInDays = settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_MSG_LIFETIME_IN_DAYS,
DEFAULT_MSG_LIFETIME).toInt();
fileLifeTimeInDays = settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_FILE_LIFETIME_IN_DAYS,
DEFAULT_FILE_LIFETIME).toInt();
//globSet._pinVal = QString::fromUtf8(QByteArray::fromBase64(
//_pinVal = QString::fromUtf8(QByteArray::fromBase64(
// settings.value(SETTINGS_GLOBAL_GROUP "/" SETTINGS_PIN_VAL,
// QString()).toString().toUtf8()));
globSet.pinAlg = settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_PIN_ALG, QString()).toString();
pinAlg = settings.value(SETTINGS_GLOBAL_GROUP "/" SETTINGS_PIN_ALG,
QString()).toString();
globSet.pinSalt = QByteArray::fromBase64(
settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_PIN_SALT,
QString()).toString().toUtf8());
pinSalt = QByteArray::fromBase64(settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_PIN_SALT,
QString()).toString().toUtf8());
globSet.pinCode = QByteArray::fromBase64(
settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_PIN_CODE,
QString()).toString().toUtf8());
pinCode = QByteArray::fromBase64(settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_PIN_CODE,
QString()).toString().toUtf8());
globSet.lastUpdate = settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_LAST_UPDATE).toString();
setLastUpdate(settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_LAST_UPDATE).toString());
globSet.dbsLocation = settings.value(
dbsLocation = settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_DBS_LOCATION).toString();
if (globSet.dbsLocation.isEmpty()) {
globSet.dbsLocation = getDefaultDbAndConfigLocation();
if (dbsLocation.isEmpty()) {
dbsLocation = getDefaultDbAndConfigLocation();
}
}
......@@ -158,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