summaryrefslogtreecommitdiff
path: root/src/dictionary/IDictionary.cpp
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2021-07-14 11:49:10 +1200
committerJedidiah Barber <contact@jedbarber.id.au>2021-07-14 11:49:10 +1200
commitd24f813f3f2a05c112e803e4256b53535895fc98 (patch)
tree601e6ae9a1cd44bcfdcf91739a5ca36aedd827c9 /src/dictionary/IDictionary.cpp
Initial mirror commitHEADmaster
Diffstat (limited to 'src/dictionary/IDictionary.cpp')
-rw-r--r--src/dictionary/IDictionary.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/dictionary/IDictionary.cpp b/src/dictionary/IDictionary.cpp
new file mode 100644
index 0000000..20bac26
--- /dev/null
+++ b/src/dictionary/IDictionary.cpp
@@ -0,0 +1,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;
+ }