summaryrefslogtreecommitdiff
path: root/src/frontend/bookmarks/btbookmarkitem.cpp
blob: 952be22c3f9724e8a841d0c5cfe8c12932abc51c (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2014 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/

#include "frontend/bookmarks/btbookmarkitem.h"

#include <QSharedPointer>
#include "backend/config/btconfig.h"
#include "backend/managers/cswordbackend.h"
#include "backend/drivers/cswordmoduleinfo.h"
#include "backend/keys/cswordversekey.h"
#include "bibletimeapp.h"
#include "btglobal.h"
#include "frontend/bookmarks/btbookmarkfolder.h"
#include "frontend/bookmarks/bteditbookmarkdialog.h"
#include "util/cresmgr.h"
#include "util/geticon.h"


BtBookmarkItem::BtBookmarkItem(const CSwordModuleInfo *module,
                               const QString &key,
                               const QString &description,
                               const QString &title)
        : m_description(description),
          m_moduleName(module ? module->name() : QString::null),
          m_title(title)
{
    if (((module && (module->type() == CSwordModuleInfo::Bible)) || (module->type() == CSwordModuleInfo::Commentary))  ) {
        CSwordVerseKey vk(0);
        vk.setKey(key);
        vk.setLocale("en");
        m_key = vk.key(); //the m_key member is always the english key!
    }
    else {
        m_key = key;
    };

    update();
}

BtBookmarkItem::BtBookmarkItem(QTreeWidgetItem* parent)
        : BtBookmarkItemBase(parent) {}

BtBookmarkItem::BtBookmarkItem(const BtBookmarkItem& other)
        : BtBookmarkItemBase(0),
        m_key(other.m_key),
        m_description(other.m_description),
        m_moduleName(other.m_moduleName),
        m_title(other.m_title)
{
    update();
}

CSwordModuleInfo *BtBookmarkItem::module() const {
    return CSwordBackend::instance()->findModuleByName(m_moduleName);
}

QString BtBookmarkItem::key() const {
    const QString englishKeyName = englishKey();
    if (!module()) {
        return englishKeyName;
    }

    QString returnKeyName = englishKeyName;
    if ((module()->type() == CSwordModuleInfo::Bible) || (module()->type() == CSwordModuleInfo::Commentary)) {
        CSwordVerseKey vk(0);
        vk.setKey(englishKeyName);
        vk.setLocale(CSwordBackend::instance()->booknameLanguage().toLatin1() );

        returnKeyName = vk.key(); //the returned key is always in the currently set bookname language
    }

    return returnKeyName;
}

QString BtBookmarkItem::toolTip() const {
    if (!module()) {
        return QString::null;
    }

    FilterOptions filterOptions = btConfig().getFilterOptions();
    filterOptions.footnotes = false;
    filterOptions.scriptureReferences = false;
    CSwordBackend::instance()->setFilterOptions(filterOptions);

    QString ret;
    QSharedPointer<CSwordKey> k( CSwordKey::createInstance(module()) );
    k->setKey(key());

    // const CLanguageMgr::Language* lang = module()->language();
    // BtConfig::FontSettingsPair fontPair = getBtConfig().getFontForLanguage(lang);

    Q_ASSERT(k.data());
    QString header = QString::fromLatin1("%1 (%2)")
              .arg(key())
              .arg(module()->name());
    if (title() != header) {
        ret = QString::fromLatin1("<b>%1</b><br>%2<hr>%3")
              .arg(header)
              .arg(title())
              .arg(description())
              ;
    }
    else {
        ret = QString::fromLatin1("<b>%1</b><hr>%2")
              .arg(header)
              .arg(description())
              ;
    }

    return ret;
}

bool BtBookmarkItem::enableAction(MenuAction action) {
    if (action == EditBookmark || (module() && (action == PrintBookmarks)) || action == DeleteEntries)
        return true;

    return false;
}

void BtBookmarkItem::rename() {
    BtEditBookmarkDialog d(QString::fromLatin1("%1 (%2)").arg(key()).arg(module() ? module()->name() : QObject::tr("unknown")),
                           m_title,
                           m_description, treeWidget());

    if (d.exec() == QDialog::Accepted) {
        m_title = d.titleText();
        m_description = d.descriptionText();
        update();
    }
}

void BtBookmarkItem::update() {
    setIcon(0, util::getIcon(CResMgr::mainIndex::bookmark::icon));

    if (m_title.isEmpty()) {
      m_title = QString::fromLatin1("%1 (%2)").arg(key()).arg(module() ? module()->name() : QObject::tr("unknown"));
    }
    setText(0,m_title);
    setToolTip(0, toolTip());
}