Line data Source code
1 : #ifndef DBSETTINGSKEY_H
2 : #define DBSETTINGSKEY_H
3 :
4 : #include <QString>
5 : #include <QDateTime>
6 : #include "../utilities/ErrorHandling.h"
7 :
8 : const QString TWO_WEEKS = "2WEEK";
9 : const QString THREE_MONTH = "3MONTH";
10 : const QString SIX_MONTH = "6MONTH";
11 : const QString ONE_YEAR = "1YEAR";
12 :
13 : enum DBSettingsKey
14 : {
15 : CACHE_LENGTH
16 : };
17 :
18 7 : inline QString DBSettingsKeyDefaultValue(DBSettingsKey key) {
19 7 : switch (key) {
20 7 : case CACHE_LENGTH:
21 7 : return TWO_WEEKS;
22 0 : default:
23 0 : FANG_UNREACHABLE("Unknown DBSettingsKey");
24 : return "";
25 : }
26 : }
27 :
28 : /*!
29 : \brief Asserts if the value isn't valid for this key.
30 : \param key
31 : \param value
32 : */
33 : inline void DBSettingsKeyAssert(DBSettingsKey key, const QString& value) {
34 : switch (key) {
35 : case CACHE_LENGTH:
36 : FANG_CHECK(value == TWO_WEEKS || value == THREE_MONTH ||
37 : value == SIX_MONTH || value == ONE_YEAR,
38 : "DBSettingsKeyAssert: Invalid CACHE_LENGTH value");
39 : break;
40 :
41 : default:
42 : FANG_UNREACHABLE("Unknown DBSettingsKey");
43 : break;
44 : }
45 : }
46 :
47 : inline QDateTime DBSettingsCacheLengthToDateTime(const QString& value) {
48 : if (TWO_WEEKS == value) {
49 : return QDateTime::currentDateTime().addDays(-14);
50 : } else if (THREE_MONTH == value) {
51 : return QDateTime::currentDateTime().addMonths(-3);
52 : } else if (SIX_MONTH == value) {
53 : return QDateTime::currentDateTime().addMonths(-6);
54 : } else if (ONE_YEAR == value) {
55 : return QDateTime::currentDateTime().addYears(-1);
56 : } else {
57 : FANG_UNREACHABLE("Unknown cache length value");
58 : return QDateTime::fromMSecsSinceEpoch(0); // Hella old so we don't delete anything.
59 : }
60 : }
61 :
62 : #endif // DBSETTINGSKEY_H
63 :
|