~ubuntu-branches/ubuntu/jaunty/bibletime/jaunty

« back to all changes in this revision

Viewing changes to bibletime/frontend/cswordsetupmodulelistview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ralph Janke
  • Date: 2008-05-10 15:18:16 UTC
  • mfrom: (1.1.6 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080510151816-bqp8y1to705zd0fm
Tags: 1.6.5.1-1
* New upstream version (Closes: #441161, #271502)
* fixes for new autotools and gcc 4.3 (Closes: #407291)
* added poxml to Build-Depends
* No DFSG necessary anymore since biblestudy howto has 
  now Commons Licence 
* Added libclucene-dev to dev-depends (Closes: #436677)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********
 
2
*
 
3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
 
4
*
 
5
* Copyright 1999-2006 by the BibleTime developers.
 
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
 
7
*
 
8
**********/
 
9
 
 
10
 
 
11
 
 
12
#include "cswordsetupmodulelistview.h"
 
13
#include "btinstallmgr.h"
 
14
 
 
15
#include "backend/cswordbackend.h"
 
16
#include "backend/cswordmoduleinfo.h"
 
17
 
 
18
#include "util/cresmgr.h"
 
19
#include "util/ctoolclass.h"
 
20
 
 
21
//QT includes
 
22
#include <qtooltip.h>
 
23
 
 
24
//KDE includes
 
25
#include <klocale.h>
 
26
#include <kiconloader.h>
 
27
 
 
28
using namespace sword;
 
29
 
 
30
namespace BookshelfManager {
 
31
 
 
32
    /** Tooltip implementation for QListView widgets.
 
33
     * @short Tooltip for InstallationManager listviews
 
34
     * @author Joachim Ansorg
 
35
     */
 
36
    class ToolTip : public QToolTip {
 
37
    public:
 
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.
 
40
         * @short Constructor.
 
41
         */
 
42
        ToolTip(CSwordSetupModuleListView* listview)
 
43
                : QToolTip( listview->viewport() ),
 
44
        m_parent( listview ) {}
 
45
 
 
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
 
48
         */
 
49
        virtual void maybeTip(const QPoint& pos) {
 
50
            QListViewItem* i = m_parent->itemAt(pos);
 
51
            Q_ASSERT(i);
 
52
 
 
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);
 
56
                tip(rect, tipText);
 
57
            }
 
58
        }
 
59
 
 
60
    protected:
 
61
        CSwordSetupModuleListView* m_parent;
 
62
    };
 
63
 
 
64
    /** Listview specially made for the installation manager.
 
65
     * @short InstallationManager module listviews
 
66
     * @author Martin Gruner
 
67
     */
 
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();
 
73
 
 
74
        addColumn(i18n("Name"));
 
75
        setColumnWidthMode( 0, QListView::Maximum );
 
76
        setColumnWidth( 0, 200 ); //don`t get too broad
 
77
 
 
78
        addColumn(i18n("Status"));
 
79
        setColumnAlignment(1, Qt::AlignRight);
 
80
        addColumn(i18n("Installed version")); //version
 
81
        setColumnAlignment(2, Qt::AlignHCenter);
 
82
 
 
83
        if (m_is_remote) {
 
84
            addColumn(i18n("Remote version")); //version
 
85
        } else {
 
86
            addColumn(i18n("Location"));
 
87
        }
 
88
        setColumnAlignment(3, Qt::AlignLeft);
 
89
 
 
90
        setAllColumnsShowFocus(true);
 
91
        setFullWidth(true);
 
92
        setRootIsDecorated(true);
 
93
        setResizeMode(QListView::LastColumn);
 
94
        setTooltipColumn(0);
 
95
 
 
96
        init();
 
97
    }
 
98
 
 
99
    CSwordSetupModuleListView::~CSwordSetupModuleListView() {
 
100
        if (m_is_remote) {
 
101
            delete m_backend;
 
102
        }
 
103
    }
 
104
 
 
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);
 
113
#else
 
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);
 
121
#endif
 
122
 
 
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));
 
129
 
 
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);
 
136
 
 
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*)));
 
140
    }
 
141
 
 
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;
 
155
    }
 
156
 
 
157
    void CSwordSetupModuleListView::clear() {
 
158
        QListView::clear();
 
159
        init();
 
160
    }
 
161
 
 
162
    void CSwordSetupModuleListView::addModule(CSwordModuleInfo* module, QString localVersion) {
 
163
 
 
164
        QListViewItem* parent = 0;
 
165
        switch ( module->type() ) {
 
166
        case CSwordModuleInfo::Bible:
 
167
            parent = m_categoryBible;
 
168
            break;
 
169
        case CSwordModuleInfo::Commentary:
 
170
            parent = m_categoryCommentary;
 
171
            break;
 
172
        case CSwordModuleInfo::Lexicon:
 
173
            parent = m_categoryLexicon;
 
174
            break;
 
175
        case CSwordModuleInfo::GenericBook:
 
176
            parent = m_categoryBook;
 
177
            break;
 
178
        default:
 
179
            parent = 0;
 
180
            break;
 
181
        }
 
182
 
 
183
        //handling for special module types
 
184
        if ((parent == m_categoryLexicon) && (module->category() == CSwordModuleInfo::Glossary)) {
 
185
            parent = m_categoryGlossaries;
 
186
        }
 
187
        if ((parent == m_categoryLexicon) && (module->category() == CSwordModuleInfo::DailyDevotional)) {
 
188
            parent = m_categoryDevotionals;
 
189
        }
 
190
 
 
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());
 
196
        }
 
197
 
 
198
        QListViewItem * langFolder = 0;
 
199
        if (parent) {
 
200
            langFolder = parent->firstChild();
 
201
 
 
202
            while( langFolder ) { //try to find language folder if it exsists
 
203
                if (langFolder->text(0) == langName) { //found right folder
 
204
                    break;
 
205
                }
 
206
 
 
207
                langFolder = langFolder->nextSibling();
 
208
            }
 
209
        }
 
210
 
 
211
        if (!langFolder) { //not yet there
 
212
#if QT_VERSION >= 0x030200
 
213
            langFolder = new QCheckListItem(parent, langName, QCheckListItem::CheckBoxController);
 
214
#else
 
215
 
 
216
            langFolder = new QCheckListItem(parent, langName, QCheckListItem::Controller);
 
217
#endif
 
218
 
 
219
            langFolder->setPixmap(0, SmallIcon(CResMgr::mainIndex::closedFolder::icon, 16));
 
220
            langFolder->setOpen(false);
 
221
        }
 
222
 
 
223
        Q_ASSERT(langFolder);
 
224
 
 
225
        QListViewItem* newItem = 0;
 
226
        if (langFolder) {
 
227
            newItem = new QCheckListItem(langFolder, module->name(), QCheckListItem::CheckBox);
 
228
        } else { //shouldn't happen
 
229
            newItem = new QCheckListItem(this, module->name(), QCheckListItem::CheckBox);
 
230
        }
 
231
 
 
232
        newItem->setPixmap(0, CToolClass::getIconForModule(module));
 
233
        if (m_is_remote) {
 
234
            newItem->setText(1, localVersion.isEmpty() ? i18n("New") : i18n("Updated"));
 
235
        } else {
 
236
            newItem->setText(1, i18n("Installed") );
 
237
        }
 
238
 
 
239
        newItem->setText(2, localVersion);
 
240
        if (m_is_remote) {
 
241
            newItem->setText(3, module->config(CSwordModuleInfo::ModuleVersion));
 
242
        } else {
 
243
            newItem->setText(3, module->config(CSwordModuleInfo::AbsoluteDataPath));
 
244
        }
 
245
    }
 
246
 
 
247
    QStringList CSwordSetupModuleListView::selectedModules() {
 
248
        QStringList moduleList;
 
249
 
 
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);
 
255
            }
 
256
            ++list_it;
 
257
        }
 
258
 
 
259
        return moduleList;
 
260
    }
 
261
 
 
262
    void CSwordSetupModuleListView::slotItemClicked(QListViewItem*) {
 
263
        emit selectedModulesChanged();
 
264
    }
 
265
 
 
266
    bool CSwordSetupModuleListView::showTooltip(QListViewItem* i, const QPoint&, int) const {
 
267
        QCheckListItem* checkItem = dynamic_cast<QCheckListItem*>( i );
 
268
        Q_ASSERT(checkItem);
 
269
 
 
270
        return (checkItem && (checkItem->type() == QCheckListItem::CheckBox));
 
271
    }
 
272
 
 
273
    QString CSwordSetupModuleListView::tooltip(QListViewItem* i, int /*column*/) const {
 
274
        QString ret;
 
275
        QCheckListItem* checkItem = dynamic_cast<QCheckListItem*>( i );
 
276
 
 
277
        if (checkItem && (checkItem->type() == QCheckListItem::CheckBox)) {
 
278
            const QString moduleName = checkItem->text(0);
 
279
            CSwordModuleInfo* module = m_backend->findModuleByName(moduleName);
 
280
 
 
281
            ret = CToolClass::moduleToolTip(module);
 
282
        }
 
283
 
 
284
        return ret;
 
285
    }
 
286
 
 
287
} //NAMESPACE
 
288