~ubuntu-branches/ubuntu/intrepid/bibletime/intrepid

« back to all changes in this revision

Viewing changes to bibletime/frontend/displaywindow/cdisplaywindow.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
//BibleTime includes
 
13
#include "cdisplaywindow.h"
 
14
#include "creadwindow.h"
 
15
#include "cbiblereadwindow.h"
 
16
#include "ccommentaryreadwindow.h"
 
17
#include "clexiconreadwindow.h"
 
18
#include "cbookreadwindow.h"
 
19
 
 
20
#include "cwritewindow.h"
 
21
#include "cplainwritewindow.h"
 
22
#include "chtmlwritewindow.h"
 
23
 
 
24
#include "cmodulechooserbar.h"
 
25
#include "cbuttons.h"
 
26
 
 
27
#include "backend/cswordkey.h"
 
28
 
 
29
#include "frontend/keychooser/ckeychooser.h"
 
30
 
 
31
#include "frontend/display/cdisplay.h"
 
32
 
 
33
#include "frontend/cmdiarea.h"
 
34
#include "frontend/cprofilewindow.h"
 
35
#include "frontend/cbtconfig.h"
 
36
 
 
37
#include "frontend/searchdialog/csearchdialog.h"
 
38
 
 
39
#include "util/cresmgr.h"
 
40
 
 
41
 
 
42
//Qt includes
 
43
 
 
44
//KDE includes
 
45
#include <kdeversion.h>
 
46
#include <kaccel.h>
 
47
#include <klocale.h>
 
48
 
 
49
using namespace Profile;
 
50
 
 
51
CReadWindow* CDisplayWindow::createReadInstance(ListCSwordModuleInfo modules, CMDIArea* parent, const char* name) {
 
52
        switch (modules.first()->type()) {
 
53
                case CSwordModuleInfo::Bible:
 
54
                        return new CBibleReadWindow(modules, parent, name);
 
55
                case CSwordModuleInfo::Commentary:
 
56
                        return new CCommentaryReadWindow(modules, parent, name);
 
57
                case CSwordModuleInfo::Lexicon:
 
58
                        return new CLexiconReadWindow(modules, parent, name);
 
59
                case CSwordModuleInfo::GenericBook:
 
60
                        return new CBookReadWindow(modules, parent, name);
 
61
                default:
 
62
                        qWarning("unknown module type");
 
63
                break;
 
64
        }
 
65
        return 0;
 
66
}
 
67
 
 
68
 
 
69
CWriteWindow* CDisplayWindow::createWriteInstance(ListCSwordModuleInfo modules, CMDIArea* parent, const CDisplayWindow::WriteWindowType type, const char* name) {
 
70
        if (type == HTMLWindow) {
 
71
                return new CHTMLWriteWindow(modules, parent, name);
 
72
        }
 
73
        else {
 
74
                return new CPlainWriteWindow(modules, parent, name);
 
75
        }
 
76
        return 0;
 
77
}
 
78
 
 
79
CDisplayWindow::CDisplayWindow(ListCSwordModuleInfo modules, CMDIArea *parent, const char *name )
 
80
#if KDE_VERSION >= 0x030200
 
81
: KMainWindow(KMainWindow::NoDCOPObject, parent, name, WDestructiveClose),
 
82
#else
 
83
: KMainWindow(parent, name, WDestructiveClose),
 
84
#endif
 
85
m_mdi(parent),
 
86
m_filterOptions(),
 
87
m_displayOptions(),
 
88
m_displaySettingsButton(0),
 
89
m_keyChooser(0),
 
90
m_swordKey(0),
 
91
m_isReady(false),
 
92
m_moduleChooserBar(0),
 
93
m_mainToolBar(0),
 
94
m_popupMenu(0),
 
95
m_displayWidget(0) {
 
96
        setModules(modules);
 
97
}
 
98
 
 
99
CDisplayWindow::~CDisplayWindow() {
 
100
        delete m_swordKey;
 
101
        m_swordKey = 0;
 
102
}
 
103
 
 
104
CMDIArea* const CDisplayWindow::mdi() const {
 
105
        return m_mdi;
 
106
}
 
107
 
 
108
/** Returns the right window caption. */
 
109
const QString CDisplayWindow::windowCaption() {
 
110
        if (!m_modules.count()) {
 
111
                return QString::null;
 
112
        }
 
113
        
 
114
        return QString(key()->key()).append(" (").append(m_modules.join(" | ")).append(")");
 
115
}
 
116
 
 
117
/** Returns the used modules as a QPtrList */
 
118
ListCSwordModuleInfo CDisplayWindow::modules() {
 
119
        ListCSwordModuleInfo mods;
 
120
 
 
121
        for (QStringList::iterator it = m_modules.begin(); it != m_modules.end(); ++it) {
 
122
                Q_ASSERT(backend()->findModuleByName(*it));
 
123
                if (CSwordModuleInfo* m = backend()->findModuleByName(*it)) {
 
124
                        mods.append(m);
 
125
                }
 
126
        }
 
127
 
 
128
        return mods;
 
129
}
 
130
 
 
131
/** Set the window caption. */
 
132
void CDisplayWindow::setCaption( const QString&  ) {
 
133
        QWidget::setCaption( windowCaption() );
 
134
        m_mdi->emitWindowCaptionChanged();
 
135
}
 
136
 
 
137
void CDisplayWindow::insertKeyboardActions( KActionCollection* const a ) {
 
138
        KStdAction::zoomIn(0, 0, a, "zoomIn"); //no slot
 
139
        KStdAction::zoomOut(0, 0, a, "zoomOut"); //no slot
 
140
        KStdAction::close(0, 0, a, "closeWindow"); //no slot
 
141
        KStdAction::selectAll(0, 0, a, "selectAll");
 
142
        KStdAction::copy(0, 0, a, "copySelectedText");
 
143
        KStdAction::find(0, 0, a, "findText");
 
144
 
 
145
        new KToolBarPopupAction(
 
146
                i18n("Back in history"),
 
147
                CResMgr::displaywindows::general::backInHistory::icon,
 
148
                CResMgr::displaywindows::general::backInHistory::accel,
 
149
                a,
 
150
                CResMgr::displaywindows::general::backInHistory::actionName
 
151
        );
 
152
        new KToolBarPopupAction(
 
153
                i18n("Forward in history"),
 
154
                CResMgr::displaywindows::general::forwardInHistory::icon,
 
155
                CResMgr::displaywindows::general::forwardInHistory::accel,
 
156
                a, CResMgr::displaywindows::general::forwardInHistory::actionName
 
157
        );
 
158
}
 
159
 
 
160
void CDisplayWindow::initActions() {
 
161
        new KAction(i18n("Search"),
 
162
                                CResMgr::displaywindows::general::search::icon,
 
163
                                CResMgr::displaywindows::general::search::accel,
 
164
                                this, SLOT(slotSearchInModules()),
 
165
                                actionCollection(), CResMgr::displaywindows::general::search::actionName
 
166
                           );
 
167
 
 
168
        KStdAction::zoomIn(
 
169
                displayWidget()->connectionsProxy(), SLOT(zoomIn()),
 
170
                actionCollection(), "zoomIn"
 
171
        );
 
172
        KStdAction::zoomOut(
 
173
                displayWidget()->connectionsProxy(), SLOT(zoomOut()),
 
174
                actionCollection(), "zoomOut"
 
175
        );
 
176
        KStdAction::close(
 
177
                this, SLOT(close()),
 
178
                actionCollection(), "closeWindow"
 
179
        );
 
180
 
 
181
        KStdAction::selectAll(
 
182
                displayWidget()->connectionsProxy(), SLOT(selectAll()),
 
183
                actionCollection(), "selectAll"
 
184
        );
 
185
 
 
186
        KStdAction::copy(
 
187
                displayWidget()->connectionsProxy(), SLOT(copySelection()),
 
188
                actionCollection(), "copySelectedText"
 
189
        );
 
190
 
 
191
        KStdAction::find(
 
192
                displayWidget()->connectionsProxy(), SLOT(openFindTextDialog()),
 
193
                actionCollection(), "findText"
 
194
        );
 
195
 
 
196
        new KToolBarPopupAction(
 
197
                i18n("Back in history"), CResMgr::displaywindows::general::backInHistory::icon, CResMgr::displaywindows::general::backInHistory::accel,
 
198
                keyChooser(), SLOT( backInHistory() ),
 
199
                actionCollection(), CResMgr::displaywindows::general::backInHistory::actionName
 
200
        );
 
201
 
 
202
        new KToolBarPopupAction(
 
203
                i18n("Forward in history"), CResMgr::displaywindows::general::forwardInHistory::icon, CResMgr::displaywindows::general::forwardInHistory::accel,
 
204
                keyChooser(), SLOT( forwardInHistory() ),
 
205
                actionCollection(), CResMgr::displaywindows::general::forwardInHistory::actionName
 
206
        );
 
207
 
 
208
        CBTConfig::setupAccelSettings(CBTConfig::allWindows, actionCollection());
 
209
}
 
210
 
 
211
/** Is called when this window gets the focus or looses the focus. */
 
212
void CDisplayWindow::windowActivated( const bool hasFocus ) {
 
213
        if (accel()) {
 
214
                accel()->setEnabled(hasFocus);
 
215
        }
 
216
}
 
217
 
 
218
/** Refresh the settings of this window. */
 
219
void CDisplayWindow::reload() {
 
220
        //first make sure all used Sword modules are still present
 
221
        for (QStringList::iterator it = m_modules.begin(); it != m_modules.end(); ++it) {
 
222
                if (!backend()->findModuleByName(*it)) {
 
223
                        it = m_modules.remove(it);
 
224
                        if (it == m_modules.end()) {
 
225
                                break;
 
226
                        }
 
227
                }
 
228
        }
 
229
        if (m_modules.count() == 0){
 
230
                close();
 
231
                return;
 
232
        }
 
233
 
 
234
        if (keyChooser()) keyChooser()->setModules( modules(), false );
 
235
        
 
236
        if (m_moduleChooserBar) { //necessary for edit windows which have now chooser bar
 
237
                m_moduleChooserBar->setModules(modules());
 
238
        }
 
239
        modulesChanged();
 
240
        lookup();
 
241
}
 
242
 
 
243
/** Returns the filter options used by this window. */
 
244
CSwordBackend::FilterOptions& CDisplayWindow::filterOptions() {
 
245
        return m_filterOptions;
 
246
}
 
247
 
 
248
/** Returns the display options used by this display window. */
 
249
CSwordBackend::DisplayOptions& CDisplayWindow::displayOptions() {
 
250
        return m_displayOptions;
 
251
}
 
252
 
 
253
/** Sets the new display options for this window. */
 
254
void CDisplayWindow::setDisplayOptions( const CSwordBackend::DisplayOptions& displayOptions ) {
 
255
        m_displayOptions = displayOptions;
 
256
}
 
257
 
 
258
/** Sets the new filter options of this window. */
 
259
void CDisplayWindow::setFilterOptions( CSwordBackend::FilterOptions& filterOptions ) {
 
260
        m_filterOptions = filterOptions;
 
261
}
 
262
 
 
263
/** Returns true if the widget is ready for use. */
 
264
const bool CDisplayWindow::isReady() const {
 
265
        return m_isReady;
 
266
}
 
267
 
 
268
/** Set the ready status */
 
269
void CDisplayWindow::setReady( const bool& ready ) {
 
270
        m_isReady = ready;
 
271
}
 
272
 
 
273
/** Returns true if the window may be closed. */
 
274
bool CDisplayWindow::queryClose() {
 
275
        return true;
 
276
}
 
277
 
 
278
/** Returns the keychooser widget of this display window. */
 
279
CKeyChooser* const CDisplayWindow::keyChooser() const {
 
280
        return m_keyChooser;
 
281
}
 
282
 
 
283
/** Sets the keychooser widget for this display window. */
 
284
void CDisplayWindow::setKeyChooser( CKeyChooser* ck ) {
 
285
        m_keyChooser = ck;
 
286
}
 
287
 
 
288
/** Returns the key of this display window. */
 
289
CSwordKey* CDisplayWindow::key() const {
 
290
        Q_ASSERT( m_swordKey );
 
291
        return m_swordKey;
 
292
}
 
293
 
 
294
/** Sets the new sword key. */
 
295
void CDisplayWindow::setKey( CSwordKey* key ) {
 
296
        Q_ASSERT( key );
 
297
        m_swordKey = key;
 
298
}
 
299
 
 
300
void CDisplayWindow::modulesChanged() {
 
301
        if (moduleChooserBar()) { //necessary for write windows
 
302
                setModules( m_moduleChooserBar->getModuleList() );
 
303
        }
 
304
 
 
305
        if (!modules().count()) {
 
306
                close();
 
307
        }
 
308
        else {
 
309
                if (displaySettingsButton()) {
 
310
                        displaySettingsButton()->reset(modules());
 
311
                }
 
312
 
 
313
                key()->module(modules().first());
 
314
                keyChooser()->setModules(modules());
 
315
        }
 
316
}
 
317
 
 
318
/** Returns the module chooser bar. */
 
319
CModuleChooserBar* const CDisplayWindow::moduleChooserBar() const {
 
320
        return m_moduleChooserBar;
 
321
}
 
322
 
 
323
/** Sets the module chooser bar. */
 
324
void CDisplayWindow::setModuleChooserBar( CModuleChooserBar* bar ) {
 
325
        if (m_moduleChooserBar) {
 
326
                disconnect(m_moduleChooserBar, SIGNAL(sigChanged()), this, SLOT(modulesChanged()));
 
327
        }
 
328
        
 
329
        //if a new bar should be set!
 
330
        if (bar) {
 
331
                m_moduleChooserBar = bar;
 
332
                connect(bar, SIGNAL(sigChanged()), SLOT(modulesChanged()));
 
333
        }
 
334
}
 
335
 
 
336
/** Sets the modules. */
 
337
void CDisplayWindow::setModules( const ListCSwordModuleInfo& newModules ) {
 
338
        m_modules.clear();
 
339
 
 
340
        ListCSwordModuleInfo::const_iterator end_it = newModules.end();
 
341
        for (ListCSwordModuleInfo::const_iterator it(newModules.begin()); it != end_it; ++it) {
 
342
                m_modules.append((*it)->name());
 
343
        }
 
344
}
 
345
 
 
346
/** Initialize the window. Call this method from the outside, because calling this in the constructor is not possible! */
 
347
const bool CDisplayWindow::init() {
 
348
        //BibleTime::createReadDisplayWindow calls the show() method
 
349
        initView();
 
350
        setMinimumSize( 250,200 );
 
351
 
 
352
        setCaption(windowCaption());
 
353
        //setup focus stuff.
 
354
        setFocusPolicy(QWidget::ClickFocus);
 
355
        parentWidget()->setFocusPolicy(QWidget::ClickFocus);
 
356
 
 
357
        initActions();
 
358
        initToolbars();
 
359
        initConnections();
 
360
        setupPopupMenu();
 
361
 
 
362
        m_filterOptions = CBTConfig::getFilterOptionDefaults();
 
363
        m_displayOptions = CBTConfig::getDisplayOptionDefaults();
 
364
        if (displaySettingsButton()) {
 
365
                displaySettingsButton()->reset(modules());
 
366
        }
 
367
 
 
368
        setReady(true);
 
369
        return true;
 
370
}
 
371
 
 
372
/** Returns the main toolbar. */
 
373
KToolBar* const CDisplayWindow::mainToolBar() const {
 
374
        return m_mainToolBar;
 
375
}
 
376
 
 
377
/** Returns the main toolbar. */
 
378
KToolBar* const CDisplayWindow::buttonsToolBar() const {
 
379
        return m_buttonsToolBar;
 
380
}
 
381
 
 
382
/** Sets the main toolbar. */
 
383
void CDisplayWindow::setMainToolBar( KToolBar* bar ) {
 
384
        m_mainToolBar = bar;
 
385
}
 
386
 
 
387
/** Sets the main toolbar. */
 
388
void CDisplayWindow::setButtonsToolBar( KToolBar* bar ) {
 
389
        m_buttonsToolBar = bar;
 
390
}
 
391
 
 
392
/** Returns the display settings button */
 
393
CDisplaySettingsButton* const CDisplayWindow::displaySettingsButton() const {
 
394
        return m_displaySettingsButton;
 
395
}
 
396
 
 
397
/** Sets the display settings button. */
 
398
void CDisplayWindow::setDisplaySettingsButton( CDisplaySettingsButton* button ) {
 
399
        if (m_displaySettingsButton)
 
400
                disconnect(m_displaySettingsButton, SIGNAL( sigChanged() ),this, SLOT(lookup() ));
 
401
 
 
402
        m_displaySettingsButton = button;
 
403
        connect(m_displaySettingsButton, SIGNAL(sigChanged()),this, SLOT(lookup()));
 
404
}
 
405
 
 
406
/** Lookup the current key. Used to refresh the display. */
 
407
void CDisplayWindow::lookup() {
 
408
        lookup( key() );
 
409
}
 
410
 
 
411
void CDisplayWindow::lookup( const QString& moduleName, const QString& keyName ) {
 
412
        Q_ASSERT(isReady());
 
413
        if (!isReady()) {
 
414
                return;
 
415
        }
 
416
 
 
417
        CSwordModuleInfo* m = backend()->findModuleByName(moduleName);
 
418
        Q_ASSERT(m);
 
419
        if (!m) {
 
420
                return;
 
421
        }
 
422
 
 
423
        //ToDo: check for containsRef compat
 
424
        if (m && modules().contains(m)) {
 
425
                key()->key(keyName);
 
426
                keyChooser()->setKey(key()); //the key chooser does send an update signal
 
427
        }
 
428
        else { //given module not displayed in this window
 
429
                //if the module is displayed in another display window we assume a wrong drop
 
430
                bool found = false;
 
431
                //create a new window for the given module
 
432
                ListCSwordModuleInfo mList;
 
433
                mList.append(m);
 
434
                mdi()->emitCreateDisplayWindow(mList, keyName);
 
435
        }
 
436
}
 
437
 
 
438
void CDisplayWindow::lookup( const QString& keyName ) {
 
439
        /* This function is called for example after a bookmark was dropped on this window
 
440
        */
 
441
        Q_ASSERT(modules().first());
 
442
 
 
443
        //qDebug("CDisplayWindow::lookup: %s", keyName.latin1());
 
444
        lookup(modules().first()->name(), keyName);
 
445
}
 
446
 
 
447
/** Update the status of the popup menu entries. */
 
448
void CDisplayWindow::updatePopupMenu() {}
 
449
 
 
450
 
 
451
///** Returns the installed popup menu. */
 
452
KPopupMenu* const CDisplayWindow::popup() {
 
453
        // qWarning("CReadWindow::popup()");
 
454
        if (!m_popupMenu) {
 
455
                m_popupMenu = new KPopupMenu(this);
 
456
                connect(m_popupMenu, SIGNAL(aboutToShow()), this, SLOT(updatePopupMenu()));
 
457
                if (displayWidget()) {
 
458
                        displayWidget()->installPopup(m_popupMenu);
 
459
                }
 
460
                /*   else {
 
461
                    qWarning("CDisplayWindow:: can't instal popup menu");
 
462
                    }*/
 
463
        }
 
464
        return m_popupMenu;
 
465
}
 
466
 
 
467
/** Returns the display widget used by this implementation of CDisplayWindow. */
 
468
CDisplay* const CDisplayWindow::displayWidget() const {
 
469
        Q_ASSERT(m_displayWidget);
 
470
        return m_displayWidget;
 
471
}
 
472
 
 
473
/** Sets the display widget used by this display window. */
 
474
void CDisplayWindow::setDisplayWidget( CDisplay* newDisplay ) {
 
475
        m_displayWidget = newDisplay;
 
476
}
 
477
 
 
478
void CDisplayWindow::closeEvent(QCloseEvent* e) {
 
479
        if (!queryClose()) {
 
480
                e->ignore();
 
481
        }
 
482
        else {
 
483
                e->accept();
 
484
        }
 
485
}
 
486
 
 
487
void CDisplayWindow::slotSearchInModules() {
 
488
        Search::CSearchDialog::openDialog(modules());
 
489
}
 
490
 
 
491
void CDisplayWindow::printAll() {
 
492
        m_displayWidget->connectionsProxy()->printAll( m_displayOptions, m_filterOptions);
 
493
}
 
494
 
 
495
void CDisplayWindow::printAnchorWithText() {
 
496
        m_displayWidget->connectionsProxy()->printAnchorWithText( m_displayOptions, m_filterOptions);
 
497
}
 
498