summaryrefslogtreecommitdiff
path: root/src/backend/bookshelfmodel/btbookshelfmodel.cpp
diff options
context:
space:
mode:
authorRoberto C. Sanchez <roberto@connexer.com>2014-10-21 22:48:35 -0400
committerRoberto C. Sanchez <roberto@connexer.com>2014-10-21 22:48:35 -0400
commitdf8f1d512c60a96f9041f9663b3fdc2db51cba33 (patch)
tree3d2bdbd4732d417aca73be022ae9044eac96b7d3 /src/backend/bookshelfmodel/btbookshelfmodel.cpp
parent4885bfcef4d89cf0cb391e00af617b9fd19c9cbb (diff)
Imported Upstream version 2.8.1
Diffstat (limited to 'src/backend/bookshelfmodel/btbookshelfmodel.cpp')
-rw-r--r--src/backend/bookshelfmodel/btbookshelfmodel.cpp125
1 files changed, 19 insertions, 106 deletions
diff --git a/src/backend/bookshelfmodel/btbookshelfmodel.cpp b/src/backend/bookshelfmodel/btbookshelfmodel.cpp
index ccbb5a5..c6aab1b 100644
--- a/src/backend/bookshelfmodel/btbookshelfmodel.cpp
+++ b/src/backend/bookshelfmodel/btbookshelfmodel.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 by the BibleTime developers.
+* Copyright 1999-2011 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -12,9 +12,9 @@
#include "backend/bookshelfmodel/btbookshelfmodel.h"
+#include <QIcon>
#include <QSet>
-#include "util/cresmgr.h"
-#include "util/directory.h"
+#include "util/macros.h"
BtBookshelfModel::BtBookshelfModel(QObject *parent)
@@ -37,7 +37,7 @@ QVariant BtBookshelfModel::data(CSwordModuleInfo *module, int role) const {
case ModuleNameRole: // Qt::DisplayRole
return module->name();
case ModuleIconRole: // Qt::DecorationRole
- return moduleIcon(module);
+ return CSwordModuleInfo::moduleIcon(module);
case ModulePointerRole:
return qVariantFromValue((void*) module);
case ModuleCategoryRole:
@@ -52,6 +52,8 @@ QVariant BtBookshelfModel::data(CSwordModuleInfo *module, int role) const {
return module->hasIndex();
case ModuleIndexSizeRole:
return (qulonglong) module->indexSize();
+ case ModuleDescriptionRole:
+ return module->config(CSwordModuleInfo::Description);
default:
return QVariant();
}
@@ -93,107 +95,6 @@ bool BtBookshelfModel::setData(const QModelIndex &index, const QVariant &value,
return false;
}
-QIcon BtBookshelfModel::moduleIcon(const CSwordModuleInfo *m) {
- namespace DU = util::directory;
-
- /// \todo Make CSwordModuleInfo::isLocked() const and remove const_cast:
- CSwordModuleInfo *module(const_cast<CSwordModuleInfo*>(m));
-
- CSwordModuleInfo::Category cat(module->category());
- switch (cat) {
- case CSwordModuleInfo::Bibles:
- if (module->isLocked()) {
- return DU::getIcon(CResMgr::modules::bible::icon_locked);
- }
- else {
- return DU::getIcon(CResMgr::modules::bible::icon_unlocked);
- }
- case CSwordModuleInfo::Commentaries:
- if (module->isLocked()) {
- return DU::getIcon(CResMgr::modules::commentary::icon_locked);
- }
- else {
- return DU::getIcon(CResMgr::modules::commentary::icon_unlocked);
- }
- case CSwordModuleInfo::Lexicons:
- if (module->isLocked()) {
- return DU::getIcon(CResMgr::modules::lexicon::icon_locked);
- }
- else {
- return DU::getIcon(CResMgr::modules::lexicon::icon_unlocked);
- }
- case CSwordModuleInfo::Books:
- if (module->isLocked()) {
- return DU::getIcon(CResMgr::modules::book::icon_locked);
- }
- else {
- return DU::getIcon(CResMgr::modules::book::icon_unlocked);
- }
- case CSwordModuleInfo::Cult:
- case CSwordModuleInfo::Images:
- case CSwordModuleInfo::DailyDevotional:
- case CSwordModuleInfo::Glossary:
- case CSwordModuleInfo::UnknownCategory:
- default:
- return categoryIcon(cat);
- }
-}
-
-QIcon BtBookshelfModel::categoryIcon(const CSwordModuleInfo::Category &category) {
- namespace DU = util::directory;
-
- switch (category) {
- case CSwordModuleInfo::Bibles:
- return DU::getIcon(CResMgr::categories::bibles::icon);
- case CSwordModuleInfo::Commentaries:
- return DU::getIcon(CResMgr::categories::commentaries::icon);
- case CSwordModuleInfo::Books:
- return DU::getIcon(CResMgr::categories::books::icon);
- case CSwordModuleInfo::Cult:
- return DU::getIcon(CResMgr::categories::cults::icon);
- case CSwordModuleInfo::Images:
- return DU::getIcon(CResMgr::categories::images::icon);
- case CSwordModuleInfo::DailyDevotional:
- return DU::getIcon(CResMgr::categories::dailydevotional::icon);
- case CSwordModuleInfo::Lexicons:
- return DU::getIcon(CResMgr::categories::lexicons::icon);
- case CSwordModuleInfo::Glossary:
- return DU::getIcon(CResMgr::categories::glossary::icon);
- case CSwordModuleInfo::UnknownCategory:
- default:
- return QIcon();
- }
-}
-
-QString BtBookshelfModel::categoryName(
- const CSwordModuleInfo::Category &category) {
- switch (category) {
- case CSwordModuleInfo::Bibles:
- return tr("Bibles");
- case CSwordModuleInfo::Commentaries:
- return tr("Commentaries");
- case CSwordModuleInfo::Books:
- return tr("Books");
- case CSwordModuleInfo::Cult:
- return tr("Cults/Unorthodox");
- case CSwordModuleInfo::Images:
- return tr("Maps and Images");
- case CSwordModuleInfo::DailyDevotional:
- return tr("Daily Devotionals");
- case CSwordModuleInfo::Lexicons:
- return tr("Lexicons and Dictionaries");
- case CSwordModuleInfo::Glossary:
- return tr("Glossaries");
- default:
- return tr("Unknown");
- }
-}
-
-QString BtBookshelfModel::languageName(
- const CLanguageMgr::Language *language) {
- return language->translatedName();
-}
-
void BtBookshelfModel::clear(bool destroy) {
if (m_data.size() <= 0) return;
@@ -217,6 +118,8 @@ void BtBookshelfModel::addModule(CSwordModuleInfo * const module) {
this, SLOT(moduleHidden(bool)));
connect(module, SIGNAL(hasIndexChanged(bool)),
this, SLOT(moduleIndexed(bool)));
+ connect(module, SIGNAL(unlockedChanged(bool)),
+ this, SLOT(moduleUnlocked(bool)));
endInsertRows();
}
@@ -242,6 +145,8 @@ void BtBookshelfModel::addModules(const QSet<CSwordModuleInfo *> &modules) {
this, SLOT(moduleHidden(bool)));
connect(module, SIGNAL(hasIndexChanged(bool)),
this, SLOT(moduleIndexed(bool)));
+ connect(module, SIGNAL(unlockedChanged(bool)),
+ this, SLOT(moduleUnlocked(bool)));
}
endInsertRows();
}
@@ -256,6 +161,8 @@ void BtBookshelfModel::removeModule(CSwordModuleInfo * const module,
this, SLOT(moduleHidden(bool)));
disconnect(module, SIGNAL(hasIndexChanged(bool)),
this, SLOT(moduleIndexed(bool)));
+ disconnect(module, SIGNAL(unlockedChanged(bool)),
+ this, SLOT(moduleUnlocked(bool)));
m_data.removeAt(index);
endRemoveRows();
if (destroy) delete module;
@@ -276,7 +183,7 @@ void BtBookshelfModel::removeModules(const QSet<CSwordModuleInfo *> &modules,
CSwordModuleInfo* BtBookshelfModel::getModule(const QString &name) const {
Q_FOREACH(CSwordModuleInfo *module, m_data) {
- if (module->name() == name) return module;
+ if (UNLIKELY(module->name() == name)) return module;
}
return 0;
}
@@ -293,6 +200,12 @@ void BtBookshelfModel::moduleIndexed(bool) {
moduleDataChanged(static_cast<CSwordModuleInfo*>(sender()));
}
+void BtBookshelfModel::moduleUnlocked(bool) {
+ Q_ASSERT(qobject_cast<CSwordModuleInfo*>(sender()) != 0);
+
+ moduleDataChanged(static_cast<CSwordModuleInfo*>(sender()));
+}
+
void BtBookshelfModel::moduleDataChanged(CSwordModuleInfo *module) {
Q_ASSERT(m_data.count(module) == 1);