summaryrefslogtreecommitdiff
path: root/src/study/StudySettings.cpp
blob: c680f8e114847eca94b0bef9249dd086a26e5a7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "StudySettings.h"

#include <QCoreApplication>
#include <QStringList>
#include <QtDebug>

StudySettings::StudySettings()
{
    initDefaultStudy();
}

void StudySettings::initDefaultStudy()
{
    showRandomly = true;
    newCardsShare = 0.2;
    schedRandomness = 0.1;
    cardsDayLimit = 80;
    newCardsDayLimit = 10;
    limitForAddingNewCards = 70;
    dayShift = 3;

    initEasiness = 2.5;
    minEasiness = 1.3;
    maxEasiness = 3.2;
    difficultDelta = -0.14;
    easyDelta = 0.1;

    unknownInterval = 20./(24*60*60);
    incorrectInterval = 1./(24*60);
    learningInterval = 10./(24*60);
    nextDayInterval = 0.9;
    twoDaysInterval = 1.9;
}

StudySettings* StudySettings::inst()
    {
    static StudySettings instance;
    return &instance;
    }

void StudySettings::load()
    {
    QSettings settings;
    settings.beginGroup("Study");
    loadStudy(settings);
    settings.endGroup();
    }

void StudySettings::loadStudy(const QSettings& settings)
{
    showRandomly = settings.value("random", showRandomly).toBool();
    newCardsShare = settings.value("new-cards-share", newCardsShare).toDouble();
    schedRandomness =
        settings.value("scheduling-randomness", schedRandomness).toDouble();
    cardsDayLimit = settings.value("cards-daylimit", cardsDayLimit).toInt();
    newCardsDayLimit = settings.value("new-cards-daylimit", newCardsDayLimit).toInt();
    limitForAddingNewCards = settings.value("limit-for-adding-new-cards", limitForAddingNewCards).toInt();
    dayShift = settings.value("dayshift", dayShift).toInt();

    initEasiness = settings.value("init-easiness", initEasiness).toDouble();
    minEasiness = settings.value("min-easiness", minEasiness).toDouble();
    maxEasiness = settings.value("max-easiness", maxEasiness).toDouble();
    difficultDelta = settings.value("difficult-delta", difficultDelta).toDouble();
    easyDelta = settings.value("easy-delta", easyDelta).toDouble();
    unknownInterval = settings.value("unknown-interval", unknownInterval).toDouble();
    incorrectInterval = settings.value("incorrect-interval", incorrectInterval).toDouble();
    learningInterval = settings.value("learning-interval", learningInterval).toDouble();
    nextDayInterval = settings.value("next-day-interval", nextDayInterval).toDouble();
}

void StudySettings::save()
    {
    QSettings settings;
    settings.beginGroup("Study");
    settings.remove("");    // Remove old user settings
    StudySettings defaults;
    if(showRandomly != defaults.showRandomly)
        settings.setValue( "random", showRandomly );
    if(newCardsShare != defaults.newCardsShare)
        settings.setValue( "new-cards-share", newCardsShare );
    if(schedRandomness != defaults.schedRandomness)
        settings.setValue( "scheduling-randomness", schedRandomness );
    if(cardsDayLimit != defaults.cardsDayLimit)
        settings.setValue( "cards-daylimit",cardsDayLimit );
    if(newCardsDayLimit != defaults.newCardsDayLimit)
        settings.setValue( "new-cards-daylimit", newCardsDayLimit );
    if(limitForAddingNewCards != defaults.limitForAddingNewCards)
        settings.setValue( "limit-for-adding-new-cards", limitForAddingNewCards );
    if(dayShift != defaults.dayShift)
        settings.setValue( "dayshift", dayShift );
    settings.endGroup();
}