diff options
author | Javier S. Pedro <maemo@javispedro.com> | 2013-04-02 14:25:56 +0200 |
---|---|---|
committer | Javier S. Pedro <maemo@javispedro.com> | 2013-04-02 14:25:56 +0200 |
commit | 70afca89b21dda18dc5e94858bec472da9130cda (patch) | |
tree | 9158cd9979f3c41c704f86ee6ea0da4274994e54 /board.cpp | |
parent | 226690b61e546294ae102c4a4b48b56555609c57 (diff) | |
download | tapasboard-70afca89b21dda18dc5e94858bec472da9130cda.tar.gz tapasboard-70afca89b21dda18dc5e94858bec472da9130cda.zip |
preparing smilies support
Diffstat (limited to 'board.cpp')
-rw-r--r-- | board.cpp | 37 |
1 files changed, 33 insertions, 4 deletions
@@ -72,6 +72,14 @@ void Board::enqueueAction(Action *action) QString Board::getConfig(const QString &key) const { + // Try config cache first + QHash<QString, QString>::const_iterator i = _config.find(key); + if (i != _config.end()) { + // Cache hit + return i.value(); + } + + // Try database QSqlQuery query(_db); query.prepare("SELECT key, value FROM config WHERE key = :key"); query.bindValue(":key", key); @@ -80,13 +88,27 @@ QString Board::getConfig(const QString &key) const return QString(); } if (query.next()) { - return query.value(1).toString(); + QString value = query.value(1).toString(); + _config[key] = value; // Store in cache + return value; } return QString(); } void Board::setConfig(const QString &key, const QString &value) { + + // Try config cache first + QHash<QString, QString>::const_iterator i = _config.find(key); + if (i != _config.end()) { + QString old_value = i.value(); + if (old_value == value) { + // It's in the cache, and it's the same value: don't change. + return; + } + } + + // Update value in DB QSqlQuery query(_db); query.prepare("INSERT OR REPLACE INTO config (key, value) VALUES (:key, :value)"); query.bindValue(":key", key); @@ -94,7 +116,8 @@ void Board::setConfig(const QString &key, const QString &value) if (!query.exec()) { qWarning() << "Could not set configuration key" << key << ":" << query.lastError().text(); } - notifyConfigChanged(); + _config.insert(key, value); + notifyConfigChanged(key); } QString Board::removeHtml(QString text) const @@ -141,9 +164,15 @@ QString Board::renderHumanTime(const QDateTime &dateTime) return dateTime.toLocalTime().time().toString(Qt::DefaultLocaleShortDate); } -void Board::notifyConfigChanged() +void Board::notifyConfigChanged(const QString& key) { - emit configChanged(); + if (!key.isEmpty()) { + _config.remove(key); + } else { + // Must assume all keys were changed + _config.clear(); + } + emit configChanged(key); } void Board::notifyForumsChanged() |