3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
5
* Copyright 1999-2006 by the BibleTime developers.
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
12
#include "cswordsetupmodulelistview.h"
13
#include "btinstallmgr.h"
15
#include "backend/cswordbackend.h"
16
#include "backend/cswordmoduleinfo.h"
18
#include "util/cresmgr.h"
19
#include "util/ctoolclass.h"
26
#include <kiconloader.h>
28
using namespace sword;
30
namespace BookshelfManager {
32
/** Tooltip implementation for QListView widgets.
33
* @short Tooltip for InstallationManager listviews
34
* @author Joachim Ansorg
36
class ToolTip : public QToolTip {
38
/** Constructor which takes the listview to operate on.
39
* @param listview We operate on this widget to request tooltips from it'd child items.
42
ToolTip(CSwordSetupModuleListView* listview)
43
: QToolTip( listview->viewport() ),
44
m_parent( listview ) {}
46
/** Reimplementation of QToolTip::maybeTip. It's requested if a new tooltip may be displayed.
47
* @short Display a tooltip if we're over an item
49
virtual void maybeTip(const QPoint& pos) {
50
QListViewItem* i = m_parent->itemAt(pos);
53
const QRect rect = m_parent->itemRect(i);
54
if (m_parent->showTooltip(i, pos, 0)) {
55
const QString tipText = m_parent->tooltip(i, 0);
61
CSwordSetupModuleListView* m_parent;
64
/** Listview specially made for the installation manager.
65
* @short InstallationManager module listviews
66
* @author Martin Gruner
68
CSwordSetupModuleListView::CSwordSetupModuleListView(QWidget *parent, bool is_remote, sword::InstallSource* installSource)
69
: KListView(parent), m_is_remote( is_remote ) {
70
Q_ASSERT(installSource);
71
new BookshelfManager::ToolTip(this);
72
m_backend = installSource ? BTInstallMgr::Tool::backend(installSource) : CPointers::backend();
74
addColumn(i18n("Name"));
75
setColumnWidthMode( 0, QListView::Maximum );
76
setColumnWidth( 0, 200 ); //don`t get too broad
78
addColumn(i18n("Status"));
79
setColumnAlignment(1, Qt::AlignRight);
80
addColumn(i18n("Installed version")); //version
81
setColumnAlignment(2, Qt::AlignHCenter);
84
addColumn(i18n("Remote version")); //version
86
addColumn(i18n("Location"));
88
setColumnAlignment(3, Qt::AlignLeft);
90
setAllColumnsShowFocus(true);
92
setRootIsDecorated(true);
93
setResizeMode(QListView::LastColumn);
99
CSwordSetupModuleListView::~CSwordSetupModuleListView() {
105
void CSwordSetupModuleListView::init() {
106
#if QT_VERSION >= 0x030200
107
m_categoryBible = new QCheckListItem(this, i18n("Bibles"), QCheckListItem::CheckBoxController);
108
m_categoryCommentary = new QCheckListItem(this, i18n("Commentaries"), QCheckListItem::CheckBoxController);
109
m_categoryLexicon = new QCheckListItem(this, i18n("Lexicons"), QCheckListItem::CheckBoxController);
110
m_categoryBook = new QCheckListItem(this, i18n("Books"), QCheckListItem::CheckBoxController);
111
m_categoryDevotionals = new QCheckListItem(this, i18n("Daily Devotionals"), QCheckListItem::CheckBoxController);
112
m_categoryGlossaries = new QCheckListItem(this, i18n("Glossaries"), QCheckListItem::CheckBoxController);
114
// Qt <= 3.1.x doesn't support the CheckBoxController!, remove the define as soon as we switch to the new Qt
115
m_categoryBible = new QCheckListItem(this, i18n("Bibles"), QCheckListItem::Controller);
116
m_categoryCommentary = new QCheckListItem(this, i18n("Commentaries"), QCheckListItem::Controller);
117
m_categoryLexicon = new QCheckListItem(this, i18n("Lexicons"), QCheckListItem::Controller);
118
m_categoryBook = new QCheckListItem(this, i18n("Books"), QCheckListItem::Controller);
119
m_categoryDevotionals = new QCheckListItem(this, i18n("Daily Devotionals"), QCheckListItem::Controller);
120
m_categoryGlossaries = new QCheckListItem(this, i18n("Glossaries"), QCheckListItem::Controller);
123
m_categoryBible->setPixmap(0, SmallIcon(CResMgr::mainIndex::closedFolder::icon, 16));
124
m_categoryCommentary->setPixmap(0, SmallIcon(CResMgr::mainIndex::closedFolder::icon, 16));
125
m_categoryLexicon->setPixmap(0, SmallIcon(CResMgr::mainIndex::closedFolder::icon, 16));
126
m_categoryBook->setPixmap(0, SmallIcon(CResMgr::mainIndex::closedFolder::icon, 16));
127
m_categoryDevotionals->setPixmap(0, SmallIcon(CResMgr::mainIndex::closedFolder::icon, 16));
128
m_categoryGlossaries->setPixmap(0, SmallIcon(CResMgr::mainIndex::closedFolder::icon, 16));
130
m_categoryBible->setOpen(true);
131
m_categoryCommentary->setOpen(true);
132
m_categoryLexicon->setOpen(true);
133
m_categoryBook->setOpen(true);
134
m_categoryDevotionals->setOpen(true);
135
m_categoryGlossaries->setOpen(true);
137
// connect(this, SIGNAL(executed(QListViewItem*)), SLOT(slotItemClicked(QListViewItem*)));
138
connect(this, SIGNAL(clicked(QListViewItem*)), SLOT(slotItemClicked(QListViewItem*))); //items have to be clicked only once in double click mode
139
connect(this, SIGNAL(spacePressed(QListViewItem*)), SLOT(slotItemClicked(QListViewItem*)));
142
void CSwordSetupModuleListView::finish() {
143
if (!m_categoryBible->childCount())
144
delete m_categoryBible;
145
if (!m_categoryCommentary->childCount())
146
delete m_categoryCommentary;
147
if (!m_categoryBook->childCount())
148
delete m_categoryBook;
149
if (!m_categoryLexicon->childCount())
150
delete m_categoryLexicon;
151
if (!m_categoryDevotionals->childCount())
152
delete m_categoryDevotionals;
153
if (!m_categoryGlossaries->childCount())
154
delete m_categoryGlossaries;
157
void CSwordSetupModuleListView::clear() {
162
void CSwordSetupModuleListView::addModule(CSwordModuleInfo* module, QString localVersion) {
164
QListViewItem* parent = 0;
165
switch ( module->type() ) {
166
case CSwordModuleInfo::Bible:
167
parent = m_categoryBible;
169
case CSwordModuleInfo::Commentary:
170
parent = m_categoryCommentary;
172
case CSwordModuleInfo::Lexicon:
173
parent = m_categoryLexicon;
175
case CSwordModuleInfo::GenericBook:
176
parent = m_categoryBook;
183
//handling for special module types
184
if ((parent == m_categoryLexicon) && (module->category() == CSwordModuleInfo::Glossary)) {
185
parent = m_categoryGlossaries;
187
if ((parent == m_categoryLexicon) && (module->category() == CSwordModuleInfo::DailyDevotional)) {
188
parent = m_categoryDevotionals;
191
//now we know the category, find the right language group in that category
192
const CLanguageMgr::Language* const lang = module->language();
193
QString langName = lang->translatedName();
194
if (!lang->isValid()) {
195
langName = QString(module->module()->Lang());
198
QListViewItem * langFolder = 0;
200
langFolder = parent->firstChild();
202
while( langFolder ) { //try to find language folder if it exsists
203
if (langFolder->text(0) == langName) { //found right folder
207
langFolder = langFolder->nextSibling();
211
if (!langFolder) { //not yet there
212
#if QT_VERSION >= 0x030200
213
langFolder = new QCheckListItem(parent, langName, QCheckListItem::CheckBoxController);
216
langFolder = new QCheckListItem(parent, langName, QCheckListItem::Controller);
219
langFolder->setPixmap(0, SmallIcon(CResMgr::mainIndex::closedFolder::icon, 16));
220
langFolder->setOpen(false);
223
Q_ASSERT(langFolder);
225
QListViewItem* newItem = 0;
227
newItem = new QCheckListItem(langFolder, module->name(), QCheckListItem::CheckBox);
228
} else { //shouldn't happen
229
newItem = new QCheckListItem(this, module->name(), QCheckListItem::CheckBox);
232
newItem->setPixmap(0, CToolClass::getIconForModule(module));
234
newItem->setText(1, localVersion.isEmpty() ? i18n("New") : i18n("Updated"));
236
newItem->setText(1, i18n("Installed") );
239
newItem->setText(2, localVersion);
241
newItem->setText(3, module->config(CSwordModuleInfo::ModuleVersion));
243
newItem->setText(3, module->config(CSwordModuleInfo::AbsoluteDataPath));
247
QStringList CSwordSetupModuleListView::selectedModules() {
248
QStringList moduleList;
250
QListViewItemIterator list_it( this );
251
while ( list_it.current() ) {
252
QCheckListItem* i = dynamic_cast<QCheckListItem*>( list_it.current() );
253
if (i && i->isOn() && i->type() == QCheckListItem::CheckBox ) {
254
moduleList << i->text(0);
262
void CSwordSetupModuleListView::slotItemClicked(QListViewItem*) {
263
emit selectedModulesChanged();
266
bool CSwordSetupModuleListView::showTooltip(QListViewItem* i, const QPoint&, int) const {
267
QCheckListItem* checkItem = dynamic_cast<QCheckListItem*>( i );
270
return (checkItem && (checkItem->type() == QCheckListItem::CheckBox));
273
QString CSwordSetupModuleListView::tooltip(QListViewItem* i, int /*column*/) const {
275
QCheckListItem* checkItem = dynamic_cast<QCheckListItem*>( i );
277
if (checkItem && (checkItem->type() == QCheckListItem::CheckBox)) {
278
const QString moduleName = checkItem->text(0);
279
CSwordModuleInfo* module = m_backend->findModuleByName(moduleName);
281
ret = CToolClass::moduleToolTip(module);