summaryrefslogtreecommitdiff
path: root/src/dictionary/IDictionary.cpp
blob: 20bac26deba7cf41885a5d27daf9c8dc8ba006f9 (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
#include "IDictionary.h"
#include "DicRecord.h"
#include "CardPack.h"

IDictionary::~IDictionary()
{
    foreach(DicRecord* record, records)
        delete record;
}

void IDictionary::addRecord(DicRecord* record)
{
    records << record;
    notifyRecordsInserted(records.size() - 1, 1);
}

void IDictionary::addRecords(const QList<DicRecord*>& records)
{
    this->records << records;
    notifyRecordsInserted(records.size() - records.size(), records.size());
}

QString IDictionary::extendImagePaths(QString text) const
{
    text = replaceImagePaths(text, "%", QFileInfo(filePath).path());
    text = replaceImagePaths(text, "%%", getImagesPath());
    return text;
}

QString IDictionary::getImagesPath() const
{
    QString path = QFileInfo(filePath).path();
    QString baseName = QFileInfo(filePath).completeBaseName();
    return QDir(path).filePath(baseName);
}

QString IDictionary::replaceImagePaths(QString text, const QString& shortDir,
    const QString& replacingPath)
{
    QRegExp imgRx(QString("(<img src=\")%1([/\\\\])").arg(shortDir));
    text.replace(imgRx, QString("\\1%1\\2").arg(replacingPath));
    return text;
}

int IDictionary::countTodaysAllCards() const
    {
    int num = 0;
    foreach(CardPack* pack, m_cardPacks)
        num += pack->getTodayReviewedCardsNum();
    return num;
    }

int IDictionary::countTodaysNewCards() const
    {
    int num = 0;
    foreach(CardPack* pack, m_cardPacks)
        num += pack->getTodayNewCardsNum();
    return num;
    }