summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoberto C. Sanchez <roberto@connexer.com>2014-10-21 22:48:19 -0400
committerRoberto C. Sanchez <roberto@connexer.com>2014-10-21 22:48:19 -0400
commit1af3b165c9377702ca62a64112bc089a6f575c30 (patch)
tree4df9cca5543b2cab5ca56dbb1214d7d3b1f291e3 /src
parent5b5fd0dce407556f98ed8edee89dc830bf1437b1 (diff)
Imported Upstream version 2.0~beta2
Diffstat (limited to 'src')
-rw-r--r--src/backend/btmoduletreeitem.cpp272
-rw-r--r--src/backend/btmoduletreeitem.h166
-rw-r--r--src/backend/config/cbtconfig.cpp720
-rw-r--r--src/backend/config/cbtconfig.h197
-rw-r--r--src/backend/cswordmodulesearch.cpp123
-rw-r--r--src/backend/cswordmodulesearch.h98
-rw-r--r--src/backend/drivers/cswordbiblemoduleinfo.cpp261
-rw-r--r--src/backend/drivers/cswordbiblemoduleinfo.h126
-rw-r--r--src/backend/drivers/cswordbookmoduleinfo.cpp68
-rw-r--r--src/backend/drivers/cswordbookmoduleinfo.h64
-rw-r--r--src/backend/drivers/cswordcommentarymoduleinfo.cpp32
-rw-r--r--src/backend/drivers/cswordcommentarymoduleinfo.h43
-rw-r--r--src/backend/drivers/cswordlexiconmoduleinfo.cpp170
-rw-r--r--src/backend/drivers/cswordlexiconmoduleinfo.h71
-rw-r--r--src/backend/drivers/cswordmoduleinfo.cpp955
-rw-r--r--src/backend/drivers/cswordmoduleinfo.h384
-rw-r--r--src/backend/filters/bt_gbfhtml.cpp296
-rw-r--r--src/backend/filters/bt_gbfhtml.h55
-rw-r--r--src/backend/filters/bt_osishtml.cpp619
-rw-r--r--src/backend/filters/bt_osishtml.h67
-rw-r--r--src/backend/filters/bt_plainhtml.cpp72
-rw-r--r--src/backend/filters/bt_plainhtml.h33
-rw-r--r--src/backend/filters/bt_thmlhtml.cpp385
-rw-r--r--src/backend/filters/bt_thmlhtml.h53
-rw-r--r--src/backend/filters/bt_thmlplain.cpp221
-rw-r--r--src/backend/filters/bt_thmlplain.h28
-rw-r--r--src/backend/filters/osismorphsegmentation.cpp83
-rw-r--r--src/backend/filters/osismorphsegmentation.h36
-rw-r--r--src/backend/keys/cswordkey.cpp185
-rw-r--r--src/backend/keys/cswordkey.h111
-rw-r--r--src/backend/keys/cswordldkey.cpp118
-rw-r--r--src/backend/keys/cswordldkey.h110
-rw-r--r--src/backend/keys/cswordtreekey.cpp93
-rw-r--r--src/backend/keys/cswordtreekey.h79
-rw-r--r--src/backend/keys/cswordversekey.cpp303
-rw-r--r--src/backend/keys/cswordversekey.h122
-rw-r--r--src/backend/managers/btstringmgr.cpp139
-rw-r--r--src/backend/managers/btstringmgr.h53
-rw-r--r--src/backend/managers/cdisplaytemplatemgr.cpp170
-rw-r--r--src/backend/managers/cdisplaytemplatemgr.h91
-rw-r--r--src/backend/managers/clanguagemgr.cpp546
-rw-r--r--src/backend/managers/clanguagemgr.h151
-rw-r--r--src/backend/managers/creferencemanager.cpp422
-rw-r--r--src/backend/managers/creferencemanager.h110
-rw-r--r--src/backend/managers/cswordbackend.cpp555
-rw-r--r--src/backend/managers/cswordbackend.h273
-rw-r--r--src/backend/rendering/cbookdisplay.cpp136
-rw-r--r--src/backend/rendering/cbookdisplay.h45
-rw-r--r--src/backend/rendering/cchapterdisplay.cpp59
-rw-r--r--src/backend/rendering/cchapterdisplay.h37
-rw-r--r--src/backend/rendering/cdisplayrendering.cpp158
-rw-r--r--src/backend/rendering/cdisplayrendering.h38
-rw-r--r--src/backend/rendering/centrydisplay.cpp63
-rw-r--r--src/backend/rendering/centrydisplay.h51
-rw-r--r--src/backend/rendering/chtmlexportrendering.cpp234
-rw-r--r--src/backend/rendering/chtmlexportrendering.h58
-rw-r--r--src/backend/rendering/cplaintextexportrendering.cpp53
-rw-r--r--src/backend/rendering/cplaintextexportrendering.h40
-rw-r--r--src/backend/rendering/ctextrendering.cpp263
-rw-r--r--src/backend/rendering/ctextrendering.h128
-rw-r--r--src/bibletime.cpp314
-rw-r--r--src/bibletime.h380
-rw-r--r--src/bibletime_dbus.cpp208
-rw-r--r--src/bibletime_dbus_adaptor.cpp71
-rw-r--r--src/bibletime_dbus_adaptor.h110
-rw-r--r--src/bibletime_init.cpp481
-rw-r--r--src/bibletime_slots.cpp510
-rw-r--r--src/bibletimeapp.cpp43
-rw-r--r--src/bibletimeapp.h30
-rw-r--r--src/display-templates/Blue.tmpl338
-rw-r--r--src/display-templates/Crazy.tmpl311
-rw-r--r--src/display-templates/Green.tmpl320
-rw-r--r--src/display-templates/HighContrast.tmpl332
-rw-r--r--src/display-templates/Simple.tmpl134
-rw-r--r--src/display-templates/basic_template.txt205
-rw-r--r--src/frontend/bookshelfmanager/btconfigdialog.cpp122
-rw-r--r--src/frontend/bookshelfmanager/btconfigdialog.h90
-rw-r--r--src/frontend/bookshelfmanager/btinstallmgr.cpp94
-rw-r--r--src/frontend/bookshelfmanager/btinstallmgr.h75
-rw-r--r--src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp73
-rw-r--r--src/frontend/bookshelfmanager/btmodulemanagerdialog.h43
-rw-r--r--src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp184
-rw-r--r--src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h46
-rw-r--r--src/frontend/bookshelfmanager/indexpage/btindexpage.cpp216
-rw-r--r--src/frontend/bookshelfmanager/indexpage/btindexpage.h87
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp232
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h53
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpage.cpp207
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpage.h66
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp170
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h44
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp261
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h70
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallthread.cpp199
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallthread.h99
-rw-r--r--src/frontend/bookshelfmanager/installpage/btsourcearea.cpp298
-rw-r--r--src/frontend/bookshelfmanager/installpage/btsourcearea.h97
-rw-r--r--src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp403
-rw-r--r--src/frontend/bookshelfmanager/installpage/btsourcewidget.h86
-rw-r--r--src/frontend/bookshelfmanager/instbackend.cpp280
-rw-r--r--src/frontend/bookshelfmanager/instbackend.h74
-rw-r--r--src/frontend/bookshelfmanager/removepage/btremovepage.cpp229
-rw-r--r--src/frontend/bookshelfmanager/removepage/btremovepage.h67
-rw-r--r--src/frontend/btaboutmoduledialog.cpp45
-rw-r--r--src/frontend/btaboutmoduledialog.h30
-rw-r--r--src/frontend/cdragdrop.cpp57
-rw-r--r--src/frontend/cdragdrop.h85
-rw-r--r--src/frontend/cdragdropmgr.cpp262
-rw-r--r--src/frontend/cdragdropmgr.h160
-rw-r--r--src/frontend/cexportmanager.cpp546
-rw-r--r--src/frontend/cexportmanager.h95
-rw-r--r--src/frontend/cinfodisplay.cpp466
-rw-r--r--src/frontend/cinfodisplay.h71
-rw-r--r--src/frontend/cinputdialog.cpp95
-rw-r--r--src/frontend/cinputdialog.h43
-rw-r--r--src/frontend/cmdiarea.cpp244
-rw-r--r--src/frontend/cmdiarea.h116
-rw-r--r--src/frontend/cmodulechooserdialog.cpp156
-rw-r--r--src/frontend/cmodulechooserdialog.h103
-rw-r--r--src/frontend/cmoduleindexdialog.cpp104
-rw-r--r--src/frontend/cmoduleindexdialog.h61
-rw-r--r--src/frontend/cprinter.cpp136
-rw-r--r--src/frontend/cprinter.h45
-rw-r--r--src/frontend/crossrefrendering.cpp90
-rw-r--r--src/frontend/crossrefrendering.h37
-rw-r--r--src/frontend/display/btcolorwidget.cpp65
-rw-r--r--src/frontend/display/btcolorwidget.h44
-rw-r--r--src/frontend/display/btfontsizewidget.cpp51
-rw-r--r--src/frontend/display/btfontsizewidget.h36
-rw-r--r--src/frontend/display/bthtml.js146
-rw-r--r--src/frontend/display/bthtmlfindtext.cpp106
-rw-r--r--src/frontend/display/bthtmlfindtext.h35
-rw-r--r--src/frontend/display/bthtmlfindtext.ui145
-rw-r--r--src/frontend/display/bthtmljsobject.cpp175
-rw-r--r--src/frontend/display/bthtmljsobject.h60
-rw-r--r--src/frontend/display/bthtmlreaddisplay.cpp364
-rw-r--r--src/frontend/display/bthtmlreaddisplay.h118
-rw-r--r--src/frontend/display/cdisplay.cpp208
-rw-r--r--src/frontend/display/cdisplay.h186
-rw-r--r--src/frontend/display/chtmlwritedisplay.cpp285
-rw-r--r--src/frontend/display/chtmlwritedisplay.h106
-rw-r--r--src/frontend/display/cplainwritedisplay.cpp160
-rw-r--r--src/frontend/display/cplainwritedisplay.h100
-rw-r--r--src/frontend/display/creaddisplay.cpp112
-rw-r--r--src/frontend/display/creaddisplay.h73
-rw-r--r--src/frontend/display/cwritedisplay.cpp21
-rw-r--r--src/frontend/display/cwritedisplay.h51
-rw-r--r--src/frontend/displaywindow/btactioncollection.cpp38
-rw-r--r--src/frontend/displaywindow/btactioncollection.h32
-rw-r--r--src/frontend/displaywindow/bttoolbarpopupaction.cpp51
-rw-r--r--src/frontend/displaywindow/bttoolbarpopupaction.h45
-rw-r--r--src/frontend/displaywindow/cbiblereadwindow.cpp480
-rw-r--r--src/frontend/displaywindow/cbiblereadwindow.h144
-rw-r--r--src/frontend/displaywindow/cbookreadwindow.cpp195
-rw-r--r--src/frontend/displaywindow/cbookreadwindow.h69
-rw-r--r--src/frontend/displaywindow/cbuttons.cpp191
-rw-r--r--src/frontend/displaywindow/cbuttons.h77
-rw-r--r--src/frontend/displaywindow/ccommentaryreadwindow.cpp198
-rw-r--r--src/frontend/displaywindow/ccommentaryreadwindow.h72
-rw-r--r--src/frontend/displaywindow/cdisplaywindow.cpp497
-rw-r--r--src/frontend/displaywindow/cdisplaywindow.h264
-rw-r--r--src/frontend/displaywindow/cdisplaywindowfactory.cpp57
-rw-r--r--src/frontend/displaywindow/cdisplaywindowfactory.h34
-rw-r--r--src/frontend/displaywindow/chtmlwritewindow.cpp163
-rw-r--r--src/frontend/displaywindow/chtmlwritewindow.h75
-rw-r--r--src/frontend/displaywindow/clexiconreadwindow.cpp367
-rw-r--r--src/frontend/displaywindow/clexiconreadwindow.h118
-rw-r--r--src/frontend/displaywindow/cmodulechooserbar.cpp127
-rw-r--r--src/frontend/displaywindow/cmodulechooserbar.h77
-rw-r--r--src/frontend/displaywindow/cmodulechooserbutton.cpp211
-rw-r--r--src/frontend/displaywindow/cmodulechooserbutton.h82
-rw-r--r--src/frontend/displaywindow/cplainwritewindow.cpp183
-rw-r--r--src/frontend/displaywindow/cplainwritewindow.h96
-rw-r--r--src/frontend/displaywindow/creadwindow.cpp205
-rw-r--r--src/frontend/displaywindow/creadwindow.h79
-rw-r--r--src/frontend/displaywindow/cwritewindow.cpp161
-rw-r--r--src/frontend/displaywindow/cwritewindow.h72
-rw-r--r--src/frontend/htmldialogs/btaboutdialog.cpp251
-rw-r--r--src/frontend/htmldialogs/btaboutdialog.h29
-rw-r--r--src/frontend/htmldialogs/bttabhtmldialog.cpp140
-rw-r--r--src/frontend/htmldialogs/bttabhtmldialog.h87
-rw-r--r--src/frontend/keychooser/bthistory.cpp130
-rw-r--r--src/frontend/keychooser/bthistory.h80
-rw-r--r--src/frontend/keychooser/cbookkeychooser.cpp278
-rw-r--r--src/frontend/keychooser/cbookkeychooser.h86
-rw-r--r--src/frontend/keychooser/cbooktreechooser.cpp200
-rw-r--r--src/frontend/keychooser/cbooktreechooser.h87
-rw-r--r--src/frontend/keychooser/ckeychooser.cpp64
-rw-r--r--src/frontend/keychooser/ckeychooser.h115
-rw-r--r--src/frontend/keychooser/ckeychooserwidget.cpp304
-rw-r--r--src/frontend/keychooser/ckeychooserwidget.h171
-rw-r--r--src/frontend/keychooser/clexiconkeychooser.cpp180
-rw-r--r--src/frontend/keychooser/clexiconkeychooser.h86
-rw-r--r--src/frontend/keychooser/cscrollbutton.cpp85
-rw-r--r--src/frontend/keychooser/cscrollbutton.h85
-rw-r--r--src/frontend/keychooser/cscrollerwidgetset.cpp87
-rw-r--r--src/frontend/keychooser/cscrollerwidgetset.h76
-rw-r--r--src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.cpp134
-rw-r--r--src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.h79
-rw-r--r--src/frontend/keychooser/versekeychooser/btversekeymenu.cpp52
-rw-r--r--src/frontend/keychooser/versekeychooser/btversekeymenu.h43
-rw-r--r--src/frontend/keychooser/versekeychooser/cbiblekeychooser.cpp108
-rw-r--r--src/frontend/keychooser/versekeychooser/cbiblekeychooser.h78
-rw-r--r--src/frontend/keychooser/versekeychooser/ckeyreferencewidget.cpp229
-rw-r--r--src/frontend/keychooser/versekeychooser/ckeyreferencewidget.h86
-rw-r--r--src/frontend/mainindex/bookmarks/btbookmarkfolder.cpp150
-rw-r--r--src/frontend/mainindex/bookmarks/btbookmarkfolder.h51
-rw-r--r--src/frontend/mainindex/bookmarks/btbookmarkitem.cpp163
-rw-r--r--src/frontend/mainindex/bookmarks/btbookmarkitem.h67
-rw-r--r--src/frontend/mainindex/bookmarks/btbookmarkitembase.cpp41
-rw-r--r--src/frontend/mainindex/bookmarks/btbookmarkitembase.h63
-rw-r--r--src/frontend/mainindex/bookmarks/btbookmarkloader.cpp174
-rw-r--r--src/frontend/mainindex/bookmarks/btbookmarkloader.h47
-rw-r--r--src/frontend/mainindex/bookmarks/cbookmarkindex.cpp850
-rw-r--r--src/frontend/mainindex/bookmarks/cbookmarkindex.h182
-rw-r--r--src/frontend/mainindex/bookshelf/actionenum.h24
-rw-r--r--src/frontend/mainindex/bookshelf/btindexfolder.cpp19
-rw-r--r--src/frontend/mainindex/bookshelf/btindexfolder.h30
-rw-r--r--src/frontend/mainindex/bookshelf/btindexitem.cpp19
-rw-r--r--src/frontend/mainindex/bookshelf/btindexitem.h45
-rw-r--r--src/frontend/mainindex/bookshelf/btindexmodule.cpp93
-rw-r--r--src/frontend/mainindex/bookshelf/btindexmodule.h39
-rw-r--r--src/frontend/mainindex/bookshelf/cbookshelfindex.cpp722
-rw-r--r--src/frontend/mainindex/bookshelf/cbookshelfindex.h207
-rw-r--r--src/frontend/mainindex/bookshelf/chidemodulechooserdialog.cpp70
-rw-r--r--src/frontend/mainindex/bookshelf/chidemodulechooserdialog.h43
-rw-r--r--src/frontend/mainindex/cmainindex.cpp36
-rw-r--r--src/frontend/mainindex/cmainindex.h57
-rw-r--r--src/frontend/profile/cprofile.cpp433
-rw-r--r--src/frontend/profile/cprofile.h120
-rw-r--r--src/frontend/profile/cprofilemgr.cpp130
-rw-r--r--src/frontend/profile/cprofilemgr.h68
-rw-r--r--src/frontend/profile/cprofilewindow.cpp134
-rw-r--r--src/frontend/profile/cprofilewindow.h126
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp84
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysisdialog.h58
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysisitem.cpp169
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysisitem.h65
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysislegenditem.cpp84
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysislegenditem.h35
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysisscene.cpp292
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysisscene.h88
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysisview.cpp50
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysisview.h54
-rw-r--r--src/frontend/searchdialog/btsearchoptionsarea.cpp530
-rw-r--r--src/frontend/searchdialog/btsearchoptionsarea.h150
-rw-r--r--src/frontend/searchdialog/btsearchresultarea.cpp659
-rw-r--r--src/frontend/searchdialog/btsearchresultarea.h201
-rw-r--r--src/frontend/searchdialog/chistorycombobox.cpp48
-rw-r--r--src/frontend/searchdialog/chistorycombobox.h33
-rw-r--r--src/frontend/searchdialog/cmoduleresultview.cpp297
-rw-r--r--src/frontend/searchdialog/cmoduleresultview.h136
-rw-r--r--src/frontend/searchdialog/crangechooserdialog.cpp330
-rw-r--r--src/frontend/searchdialog/crangechooserdialog.h89
-rw-r--r--src/frontend/searchdialog/csearchdialog.cpp304
-rw-r--r--src/frontend/searchdialog/csearchdialog.h134
-rw-r--r--src/frontend/searchdialog/csearchmodulechooserdialog.cpp61
-rw-r--r--src/frontend/searchdialog/csearchmodulechooserdialog.h44
-rw-r--r--src/frontend/searchdialog/csearchresultview.cpp295
-rw-r--r--src/frontend/searchdialog/csearchresultview.h101
-rw-r--r--src/frontend/settingsdialogs/cacceleratorsettings.cpp.OFF268
-rw-r--r--src/frontend/settingsdialogs/cacceleratorsettings.h.OFF72
-rw-r--r--src/frontend/settingsdialogs/cconfigurationdialog.cpp93
-rw-r--r--src/frontend/settingsdialogs/cconfigurationdialog.h49
-rw-r--r--src/frontend/settingsdialogs/cdisplaysettings.cpp199
-rw-r--r--src/frontend/settingsdialogs/cdisplaysettings.h43
-rw-r--r--src/frontend/settingsdialogs/cfontchooser.cpp359
-rw-r--r--src/frontend/settingsdialogs/cfontchooser.h74
-rw-r--r--src/frontend/settingsdialogs/clanguagesettings.cpp302
-rw-r--r--src/frontend/settingsdialogs/clanguagesettings.h65
-rw-r--r--src/frontend/settingsdialogs/clistwidget.cpp30
-rw-r--r--src/frontend/settingsdialogs/clistwidget.h28
-rw-r--r--src/frontend/settingsdialogs/cswordsettings.cpp423
-rw-r--r--src/frontend/settingsdialogs/cswordsettings.h86
-rw-r--r--src/main.cpp213
-rw-r--r--src/tests/backend/config/cbtconfig_test.cpp36
-rw-r--r--src/tests/bibletime_test.cpp20
-rw-r--r--src/tests/bibletime_test.h28
-rw-r--r--src/util/cpointers.cpp55
-rw-r--r--src/util/cpointers.h116
-rw-r--r--src/util/cresmgr.cpp496
-rw-r--r--src/util/cresmgr.h509
-rw-r--r--src/util/ctoolclass.cpp279
-rw-r--r--src/util/ctoolclass.h94
-rw-r--r--src/util/dialogutil.cpp61
-rw-r--r--src/util/dialogutil.h23
-rw-r--r--src/util/directoryutil.cpp368
-rw-r--r--src/util/directoryutil.h112
-rw-r--r--src/util/exceptions.h16
-rw-r--r--src/util/migrationutil.cpp92
-rw-r--r--src/util/migrationutil.h39
291 files changed, 45270 insertions, 0 deletions
diff --git a/src/backend/btmoduletreeitem.cpp b/src/backend/btmoduletreeitem.cpp
new file mode 100644
index 0000000..275c841
--- /dev/null
+++ b/src/backend/btmoduletreeitem.cpp
@@ -0,0 +1,272 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btmoduletreeitem.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "util/cpointers.h"
+#include "backend/managers/cswordbackend.h"
+#include "util/cresmgr.h"
+#include "util/ctoolclass.h"
+
+#include <QString>
+#include <QList>
+
+#include <QDebug>
+
+
+
+//This ctor creates the root item and the tree.
+BTModuleTreeItem::BTModuleTreeItem(QList<BTModuleTreeItem::Filter*>& filters, BTModuleTreeItem::Grouping grouping, QList<CSwordModuleInfo*>* modules)
+ : m_moduleInfo(0),
+ m_firstChild(0),
+ m_next(0),
+ m_type(BTModuleTreeItem::Root),
+ m_category(CSwordModuleInfo::UnknownCategory)
+{
+ if (modules) {
+ m_originalModuleList = *modules;
+ } else {
+ m_originalModuleList = CPointers::backend()->moduleList();
+ }
+ //populate the tree with groups/modules
+ create_tree(filters, grouping);
+}
+
+/**
+* Private constructor which sets the members of the non-root item. This will be the first child of the
+* parent, the previous firstChild will be the next sibling of this.
+*/
+BTModuleTreeItem::BTModuleTreeItem(BTModuleTreeItem* parentItem, const QString& text, BTModuleTreeItem::Type type, CSwordModuleInfo* info, CSwordModuleInfo::Category category)
+ : m_moduleInfo(info),
+ m_text(text),
+ m_firstChild(0),
+ m_next(0),
+ m_type(type),
+ m_category(category)
+{
+ if (info) {
+ m_text = info->name();
+ m_type = BTModuleTreeItem::Module;
+ }
+ BTModuleTreeItem* tmp = parentItem->m_firstChild;
+ parentItem->m_firstChild = this;
+ if (tmp) this->m_next = tmp;
+}
+
+
+BTModuleTreeItem::~BTModuleTreeItem()
+{
+ // this works recursively
+ foreach(BTModuleTreeItem* i, children()) {
+ delete i;
+ }
+}
+
+QList<BTModuleTreeItem*> BTModuleTreeItem::children() const
+{
+ //qDebug("BTModuleTreeItem::children");
+ QList<BTModuleTreeItem*> childList;
+ if (m_firstChild) {
+ BTModuleTreeItem* child = m_firstChild;
+ while (child) {
+ //qDebug() << "child:" << child->text();
+ childList.append(child);
+ child = child->m_next;
+ }
+ }
+ return childList;
+}
+
+//TODO
+QString BTModuleTreeItem::iconName() const
+{
+ if (m_type == Category) {
+ switch ( m_category) {
+ case CSwordModuleInfo::Bibles:
+ return CResMgr::categories::bibles::icon;
+ break;
+ case CSwordModuleInfo::Commentaries:
+ return CResMgr::categories::commentaries::icon;
+ break;
+ case CSwordModuleInfo::Books:
+ return CResMgr::categories::books::icon;
+ break;
+ case CSwordModuleInfo::Cult:
+ return CResMgr::categories::cults::icon;
+ break;
+ case CSwordModuleInfo::Images:
+ return CResMgr::categories::images::icon;
+ break;
+ case CSwordModuleInfo::DailyDevotional:
+ return CResMgr::categories::dailydevotional::icon;
+ break;
+ case CSwordModuleInfo::Lexicons:
+ return CResMgr::categories::lexicons::icon;
+ break;
+ case CSwordModuleInfo::Glossary:
+ return CResMgr::categories::glossary::icon;
+ break;
+ default: break;
+ }
+ }
+ else if (m_type == Module) {
+ return CToolClass::getIconNameForModule(m_moduleInfo);
+ }
+ else if (m_type == Language) {
+ //TODO: don't hardcode here
+ return "flag.svg";
+ }
+
+ return QString::null;
+}
+
+
+void BTModuleTreeItem::create_tree(QList<BTModuleTreeItem::Filter*>& filters, BTModuleTreeItem::Grouping grouping)
+{
+ qDebug("BTModuleTreeItem::create_tree");
+ static bool map_initialized = false;
+ static QMap<CSwordModuleInfo::Category, QString> CategoryNamesMap;
+ if (!map_initialized) {
+ CategoryNamesMap.insert(CSwordModuleInfo::Commentaries, QObject::tr("Commentaries"));
+ CategoryNamesMap.insert(CSwordModuleInfo::Cult, QObject::tr("Cults/Unorthodox"));
+ CategoryNamesMap.insert(CSwordModuleInfo::Images, QObject::tr("Maps and Images"));
+ CategoryNamesMap.insert(CSwordModuleInfo::DailyDevotional, QObject::tr("Daily Devotionals"));
+ CategoryNamesMap.insert(CSwordModuleInfo::Lexicons, QObject::tr("Lexicons and Dictionaries"));
+ CategoryNamesMap.insert(CSwordModuleInfo::Bibles, QObject::tr("Bibles"));
+ CategoryNamesMap.insert(CSwordModuleInfo::Glossary, QObject::tr("Glossaries"));
+ CategoryNamesMap.insert(CSwordModuleInfo::Books, QObject::tr("Books"));
+
+ map_initialized = true;
+ }
+
+ //QList<CSwordModuleInfo*> originalInfoList = CPointers::backend()->moduleList();
+
+ foreach (CSwordModuleInfo* info, m_originalModuleList) {
+ bool included;
+ included = true;
+ foreach (BTModuleTreeItem::Filter* f, filters) {
+ if (!f->filter(info)) {
+ included = false;
+ break;
+ }
+ }
+ if (included) {
+ //qDebug() << "a module will be included: " << info->name();
+
+ BTModuleTreeItem* parentGroupForModule = this;
+ BTModuleTreeItem* parentGroupForLanguage = this;
+ BTModuleTreeItem* parentGroupForCategory = this;
+
+ //the order of if(grouping...) clauses is important
+ if (grouping == BTModuleTreeItem::LangMod || grouping == BTModuleTreeItem::LangCatMod) {
+ BTModuleTreeItem* langItem = create_parent_item(parentGroupForLanguage, info->language()->translatedName(), BTModuleTreeItem::Language);
+
+ if (grouping == BTModuleTreeItem::LangMod)
+ parentGroupForModule = langItem;
+ else
+ parentGroupForCategory = langItem;
+ }
+
+ if (grouping == BTModuleTreeItem::CatMod || grouping == BTModuleTreeItem::CatLangMod) {
+ BTModuleTreeItem* catItem = create_parent_item(parentGroupForCategory, CategoryNamesMap.value(info->category()), BTModuleTreeItem::Category, info->category());
+
+ if (grouping == BTModuleTreeItem::CatMod)
+ parentGroupForModule = catItem;
+ else
+ parentGroupForLanguage = catItem;
+ }
+
+ if (grouping == BTModuleTreeItem::CatLangMod) {
+ // category is there already, create language and make it the parent for the module
+ parentGroupForModule = create_parent_item(parentGroupForLanguage, info->language()->translatedName(), BTModuleTreeItem::Language);
+ }
+
+ if (grouping == BTModuleTreeItem::LangCatMod) {
+ //language is there already, create category and make it the parent for the module
+ parentGroupForModule = create_parent_item(parentGroupForCategory, CategoryNamesMap.value(info->category()), BTModuleTreeItem::Category, info->category());
+ }
+
+ // the parent group for module has been set above, now just add the module to it
+ new BTModuleTreeItem(parentGroupForModule, QString::null, BTModuleTreeItem::Module, info);
+
+ } // end: if (included)
+ }
+
+ // Finally sort the items
+ sort_children(this);
+}
+
+BTModuleTreeItem* BTModuleTreeItem::create_parent_item(
+ BTModuleTreeItem* parentGroup,
+ const QString& itemText,
+ BTModuleTreeItem::Type type,
+ CSwordModuleInfo::Category category)
+{
+ BTModuleTreeItem* item = 0;
+ foreach(BTModuleTreeItem* it, parentGroup->children()) {
+ if (it->text() == itemText) {
+ item = it;
+ break;
+ }
+ }
+ if (!item)
+ item = new BTModuleTreeItem(parentGroup, itemText, type, 0, category);
+
+ return item;
+}
+
+void BTModuleTreeItem::sort_children(BTModuleTreeItem* parent)
+{
+ //qDebug("BTModuleTreeItem::sort_children");
+
+ // sort each child recursively depth-first
+ foreach(BTModuleTreeItem* item, parent->children()) {
+ sort_children(item);
+ }
+
+ QList<BTModuleTreeItem*> items = parent->children();
+ if (items.size() > 0) {
+ // Sort the list of the children according to each item's text
+ qSort(items.begin(), items.end(), BTModuleTreeItem::localeAwareLessThan);
+ //put the children back to tree in sorted order
+ BTModuleTreeItem* first = items.at(0);
+ BTModuleTreeItem* prev = first;
+ foreach (BTModuleTreeItem* item2, items) {
+ prev->m_next = item2;
+ prev = item2;
+ }
+ prev->m_next = 0;
+ parent->m_firstChild = first; // attach the partial tree to the parent
+ }
+}
+
+bool BTModuleTreeItem::localeAwareLessThan(BTModuleTreeItem* first, BTModuleTreeItem* second)
+{
+ static bool map_initialized = false;
+ static QMap<QString, int> CategoryNameValueMap;
+ if (!map_initialized) {
+ //this is the sorting order for categories
+ CategoryNameValueMap.insert(QObject::tr("Bibles"), 1);
+ CategoryNameValueMap.insert(QObject::tr("Commentaries"), 2);
+ CategoryNameValueMap.insert(QObject::tr("Books"), 3);
+ CategoryNameValueMap.insert(QObject::tr("Lexicons and Dictionaries"), 4);
+ CategoryNameValueMap.insert(QObject::tr("Glossaries"), 5);
+ CategoryNameValueMap.insert(QObject::tr("Daily Devotionals"), 6);
+ CategoryNameValueMap.insert(QObject::tr("Maps and Images"), 7);
+ CategoryNameValueMap.insert(QObject::tr("Cults/Unorthodox"), 8);
+ map_initialized = true;
+ }
+
+ //Categories are always in the same order, not alphabetically
+ if (first->type() == BTModuleTreeItem::Category) {
+ return (CategoryNameValueMap.value(first->text()) < CategoryNameValueMap.value(second->text()));
+ }
+ return (QString::localeAwareCompare(first->text(), second->text()) < 0 );
+}
diff --git a/src/backend/btmoduletreeitem.h b/src/backend/btmoduletreeitem.h
new file mode 100644
index 0000000..abdfdb7
--- /dev/null
+++ b/src/backend/btmoduletreeitem.h
@@ -0,0 +1,166 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTMODULETREEITEM_H
+#define BTMODULETREEITEM_H
+
+#include "backend/drivers/cswordmoduleinfo.h"
+
+#include <QString>
+
+
+/**
+Item of a tree which represents Sword modules categorized and filtered.
+Can be used when building trees for different views.
+
+The tree will be created with the public constructor. It creates the root item and
+populates it with the rest of the tree. The root item is the handle to the tree.
+Users can get the list of the children and operate on it recursively.
+
+The tree is meant to be created, read and then deleted. If you need to apply for example
+different set of filters you have to create a new tree - it's not possible to modify the tree.
+
+Example:
+
+ ...
+ QList<BTModuleTreeItem::Filter*> noFilters
+ BTModuleTreeItem root(noFilters, BTModuleTreeItem::CatLangMod);
+ add_to_view(&root, qtreewidget->invisibleRootItem());
+ ...
+ void add_to_view(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem) {
+ foreach (BTModuleTreeItem* i, item->children()) {
+ add_to_view(i, new QTreeWidgetItem(widgetItem));
+ }
+ if (item->type() == BTModuleTreeItem::Category) prepare_category_item(widgetItem, item);
+ ...
+ }
+
+
+ @author The BibleTime team <info@bibletime.info>
+*/
+class BTModuleTreeItem
+{
+public:
+
+ /**
+ * A filter which is given to the root constructor. It filters some modules
+ * out from the tree. If it returns true when the filter() is called the module will be added,
+ * if it returns false the module will be left out.
+ *
+ * If you want for example to get only unindexed modules in the list you should
+ * write a class (possibly a small inner class inside the calling class) which
+ * inherits Filter and write the operator() function which returns true if the
+ * module is unindexed and false if it's indexed.
+ *
+ * It's also possible to do arbitrary tasks to modules by using more complex subclasses.
+ *
+ * The filters will be applied in the order in which they are in the list.
+ * A module will be filtered out if even one filter rejects it and testing
+ * will stop with the first negative.
+ *
+ * Example:
+ * QList<BTModuleTreeItem::Filter*> filters;
+ * MyFilter filter; BTModuleTreeItem::HiddenOff hideFilter;
+ * filters.append(&hideFilter); filters.append(&filter);
+ * BTModuleTreeItem root(filters, BTModuleTreeItem::CatLangMod);
+ */
+ struct Filter {
+ virtual bool filter(CSwordModuleInfo*) = 0;
+ inline virtual ~Filter() {};
+ };
+
+ /**
+ * One example of a filter which can be used with any view. If the module has been
+ * set "hidden" it will be filtered out.
+ */
+ struct HiddenOff : public Filter {
+ inline bool filter(CSwordModuleInfo* mi) { return !mi->isHidden(); }
+ inline virtual ~HiddenOff() {};
+ };
+
+ /**
+ * Type of the item: root item, category (Bibles, Commentaries etc.), language or module.
+ */
+ enum Type {Root, Category, Language, Module};
+
+ /**
+ * Tells how to group the modules. For example:
+ * CatLangMod: first category, second language, third module. Mod: don't use
+ * Category or Language at all, Module is toplevel and tree is flat.
+ */
+ enum Grouping {CatLangMod, CatMod, LangCatMod, LangMod, Mod};
+
+
+ /**
+ * This constructor creates a root item. Create it for example with scoped_ptr or in stack.
+ * The root item is populated with the item tree.
+ * The constructor takes a list of filters (see Filter), grouping indicator (see Grouping)
+ * and optionally the module list from which the tree is constructed
+ * (by default CPointers::backend()->moduleList() is used).
+ */
+ BTModuleTreeItem(QList<BTModuleTreeItem::Filter*>& filters,
+ BTModuleTreeItem::Grouping grouping, QList<CSwordModuleInfo*>* modules = 0);
+
+ /** When the root item is deleted the whole tree is deleted. */
+ ~BTModuleTreeItem();
+
+ /**
+ * Returns the item type.
+ */
+ inline BTModuleTreeItem::Type type() const {return m_type;}
+ /**
+ * Returns the item text (category name, language name or module name).
+ */
+ inline QString text() const {return m_text;}
+ /**
+ * Returns the path to the icon which is appropriate for this type of item, or QString::null.
+ */
+ QString iconName() const;
+ /**
+ * If the type is Module returns a pointer to the corresponding CSwordModuleInfo object,
+ * otherwise returns 0.
+ */
+ inline CSwordModuleInfo* moduleInfo() const {return m_moduleInfo;}
+ /**
+ * Returns a list of the direct children of this item.
+ */
+ QList<BTModuleTreeItem*> children() const;
+
+ /**
+ * For alphabetical sorting which uses text(). See QString::localeAwareCompare().
+ * Categories will always be in the same order regardless of the i18n.
+ */
+ static bool localeAwareLessThan(BTModuleTreeItem* first, BTModuleTreeItem* second);
+
+
+private:
+ /**
+ * Private constructor which sets the members.
+ */
+ BTModuleTreeItem(BTModuleTreeItem* parentItem, const QString& text, Type type, CSwordModuleInfo* info=0, CSwordModuleInfo::Category category=CSwordModuleInfo::UnknownCategory);
+ /** Default ctor is private because it is not to be called.*/
+ BTModuleTreeItem();
+
+ /** Creates the tree under this root item (called only from root ctor). */
+ void create_tree(QList<BTModuleTreeItem::Filter*>& filters, BTModuleTreeItem::Grouping grouping);
+ /** Sorts recursively the children of of the given item. */
+ void sort_children(BTModuleTreeItem* parent);
+ /** Helper function for creating a group item while creating the tree. */
+ BTModuleTreeItem* create_parent_item(BTModuleTreeItem* parent, const QString& text, BTModuleTreeItem::Type type, CSwordModuleInfo::Category category=CSwordModuleInfo::UnknownCategory);
+
+ CSwordModuleInfo* m_moduleInfo;
+ QString m_text;
+ BTModuleTreeItem* m_firstChild;
+ BTModuleTreeItem* m_next;
+ Type m_type;
+ CSwordModuleInfo::Category m_category;
+ QList<CSwordModuleInfo*> m_originalModuleList;
+};
+
+#endif
diff --git a/src/backend/config/cbtconfig.cpp b/src/backend/config/cbtconfig.cpp
new file mode 100644
index 0000000..a0fb4f2
--- /dev/null
+++ b/src/backend/config/cbtconfig.cpp
@@ -0,0 +1,720 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//BibleTime includes
+#include "cbtconfig.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/managers/clanguagemgr.h"
+#include "backend/managers/cdisplaytemplatemgr.h"
+#include "backend/btmoduletreeitem.h"
+#include "util/cpointers.h"
+#include "util/directoryutil.h"
+#include "frontend/searchdialog/btsearchoptionsarea.h"
+
+//Qt includes
+#include <QApplication>
+#include <QString>
+#include <QStringList>
+#include <QMap>
+#include <QList>
+#include <QDebug>
+#include <QSettings>
+#include <QLocale>
+#include <QWebSettings>
+
+//Sword includes
+#include <versekey.h> //for range configuration
+
+//init statics
+QFont* CBTConfig::m_defaultFont = 0;
+CBTConfig::FontCache CBTConfig::fontConfigMap;
+
+/* No constructor and destructor, because this class only contains static methods.
+ It won't be instantiated. */
+
+QString CBTConfig::getKey( const CBTConfig::strings ID) {
+ switch ( ID ) {
+ case bibletimeVersion: return "bibletimeVersion";
+ case language: return "language";
+ case displayStyle: return "displayStyle";
+ case bookshelfCurrentItem: return "bookshelfCurrentItem";
+ }
+ Q_ASSERT(false);
+ return QString::null;
+}
+
+QString CBTConfig::getDefault( const CBTConfig::strings ID) {
+ switch ( ID ) {
+ case bibletimeVersion: return "0.0"; // main() will realize this and set the value to VERSION
+ case language: return QLocale::system().name();
+ case displayStyle: return CDisplayTemplateMgr::defaultTemplate();
+ case bookshelfCurrentItem: return QString();
+ }
+ return QString::null;
+}
+
+QString CBTConfig::getKey( const CBTConfig::modules ID) {
+ switch ( ID ) {
+ case standardBible: return "standardBible";
+ case standardCommentary: return "standardCommentary";
+ case standardLexicon: return "standardLexicon";
+ case standardDailyDevotional: return "standardDailyDevotional";
+ case standardHebrewStrongsLexicon: return "standardHebrewLexicon";
+ case standardGreekStrongsLexicon: return "standardGreekLexicon";
+ case standardHebrewMorphLexicon: return "standardHebrewMorphLexicon";
+ case standardGreekMorphLexicon: return "standardGreekMorphLexicon";
+ }
+ Q_ASSERT(false);
+ return QString::null;
+}
+
+QString CBTConfig::getDefault( const CBTConfig::modules ID) {
+ // CSwordBackend* b = CPointers::backend();
+ switch ( ID ) {
+ case standardBible: return "KJV";
+ case standardCommentary: return "MHC";
+ case standardLexicon: return "ISBE";
+ case standardDailyDevotional: return ""; //no default
+
+ case standardHebrewStrongsLexicon: return "StrongsHebrew";
+ case standardGreekStrongsLexicon: return "StrongsGreek";
+ case standardHebrewMorphLexicon: return "StrongsHebrew";
+ case standardGreekMorphLexicon: return "StrongsGreek";
+ }
+
+ return QString::null;
+}
+
+QString CBTConfig::getKey( const CBTConfig::bools ID) {
+ switch ( ID ) {
+ case firstSearchDialog: return "firstSearchDialog";
+ case readOldBookmarks: return "readOldBookmarks";
+
+ case toolbar: return "toolbar";
+ case mainIndex: return "mainIndex";
+ case infoDisplay: return "infoDisplay";
+
+ case autoTileVertical: return "autoTileVertical";
+ case autoTileHorizontal: return "autoTileHorizontal";
+ case autoCascade: return "autoCascade";
+
+ case lineBreaks: return "lineBreaks";
+ case verseNumbers: return "verseNumbers";
+
+ case logo: return "logo";
+ case autoDeleteOrphanedIndices: return "autoDeleteOrphanedIndices";
+ case crashedLastTime: return "crashedLastTime";
+ case crashedTwoTimes: return "crashedTwoTimes";
+
+ case bookshelfShowHidden: return "bookshelfShowHidden";
+ case allowNetworkConnection: return "allowNetworkConnection";
+ }
+ Q_ASSERT(false);
+ return false;
+}
+
+QString CBTConfig::getKey( const CBTConfig::ints ID) {
+ switch ( ID ) {
+ case footnotes: return "footnotes";
+ case strongNumbers: return "strongNumbers";
+ case headings: return "headings";
+ case morphTags: return "morphTags";
+ case lemmas: return "lemmas";
+ case hebrewPoints: return "hebrewPoints";
+ case hebrewCantillation: return "hebrewCantillation";
+ case greekAccents: return "greekAccents";
+ case textualVariants: return "textualVariants";
+ case scriptureReferences: return "scriptureReferences";
+ case morphSegmentation: return "morphSegmentation";
+ case bookshelfContentsX: return "bookshelfContentsX";
+ case bookshelfContentsY: return "bookshelfContentsY";
+ case magDelay: return "magDelay";
+ case bookshelfGrouping: return "bookshelfGrouping";
+ case mainindexActiveTab: return "mainindexActiveTab";
+ case searchDialogWidth: return "searchDialogWidth";
+ case searchDialogHeight: return "searchDialogHeight";
+ case searchDialogX: return "searchDialogX";
+ case searchDialogY: return "searchDialogY";
+ case searchType: return "searchType";
+ case installPathIndex: return "installPathIndex";
+ }
+ Q_ASSERT(false);
+ return QString::null;
+}
+
+bool CBTConfig::getDefault( const CBTConfig::bools ID) {
+ switch ( ID ) {
+ case firstSearchDialog: return true;
+ case readOldBookmarks: return false;
+
+ case toolbar: return true;
+ case mainIndex: return true;
+ case infoDisplay: return true;
+
+ case autoTileVertical: return true;
+ case autoTileHorizontal: return false;
+ case autoCascade: return false;
+
+ case lineBreaks: return false;
+ case verseNumbers: return true;
+
+ case logo: return true;
+ case autoDeleteOrphanedIndices: return true;
+ case crashedLastTime: return false;
+ case crashedTwoTimes: return false;
+ case bookshelfShowHidden: return false;
+ case allowNetworkConnection: return false;
+ }
+ return false;
+}
+
+int CBTConfig::getDefault( const CBTConfig::ints ID) {
+ switch ( ID ) {
+ case footnotes: return int(true);
+ case strongNumbers: return int(true);
+ case headings: return int(true);
+ case morphTags: return int(true);
+ case lemmas: return int(true);
+ case hebrewPoints: return int(true);
+ case hebrewCantillation: return int(true);
+ case greekAccents: return int(true);
+ case textualVariants: return int(false);
+ case scriptureReferences: return int(true);
+ case morphSegmentation: return int(true);
+ case bookshelfContentsX: return 0;
+ case bookshelfContentsY: return 0;
+ case magDelay: return 400;
+ case bookshelfGrouping: return BTModuleTreeItem::CatLangMod;
+ case searchDialogWidth: return 200;
+ case searchDialogHeight: return 400;
+ case searchDialogX: return 200;
+ case searchDialogY: return 200;
+ case searchType: return Search::BtSearchOptionsArea::AndType;
+ case mainindexActiveTab: return 0;
+ case installPathIndex: return 0;
+ }
+ return 0;
+}
+
+QString CBTConfig::getKey( const CBTConfig::intLists ID) {
+ switch ( ID ) {
+ case leftPaneSplitterSizes: return "leftPaneSplitterSizes";
+ case mainSplitterSizes: return "mainSplitterSizes";
+ case searchMainSplitterSizes: return "searchMainSplitterSizes";
+ case searchResultSplitterSizes: return "searchResultSplitterSizes";
+ }
+ Q_ASSERT(false);
+ return QString::null;
+}
+
+QList<int> CBTConfig::getDefault( const CBTConfig::intLists /*ID*/) {
+ QList<int> result;
+ /*switch ( ID ) {
+ case leftPaneSplitterSizes: break;
+ case mainSplitterSizes: break;
+ case searchMainSplitterSizes: break;
+ case searchResultSplitterSizes: break;*/
+ return result;
+}
+
+QString CBTConfig::getKey( const CBTConfig::stringLists ID) {
+ switch ( ID ) {
+ case searchCompletionTexts: return QString("searchCompletionTexts");
+ case searchTexts: return QString("searchTexts");
+ case searchModulesHistory: return QString("searchModulesHistory");
+ case bookshelfOpenGroups: return QString("bookshelfOpenGroups");
+ case hiddenModules: return QString("hiddenModules");
+ }
+ Q_ASSERT(false);
+ return QString::null;
+}
+
+QStringList CBTConfig::getDefault( const CBTConfig::stringLists ID) {
+ switch ( ID ) {
+ case searchTexts: {
+ QStringList list;
+ list.append(QString::null);
+ return list;
+ }
+ case searchCompletionTexts: return QStringList();
+ case bookshelfOpenGroups: return QStringList();
+ case hiddenModules: return QStringList();
+ case searchModulesHistory: return QStringList();
+ }
+ return QStringList();
+}
+
+QString CBTConfig::getKey( const CBTConfig::stringMaps ID) {
+ switch (ID) {
+ case searchScopes:
+ return QString("SearchScopes");
+ };
+ Q_ASSERT(false);
+ return QString::null;
+}
+
+CBTConfig::StringMap CBTConfig::getDefault( const CBTConfig::stringMaps ID) {
+ switch ( ID ) {
+ case searchScopes: {
+ CBTConfig::StringMap map;
+ map.insert(QObject::tr("Old testament"), QString("Gen - Mal"));
+ map.insert(QObject::tr("Moses/Pentateuch/Torah"),QString("Gen - Deut"));
+ map.insert(QObject::tr("History"), QString("Jos - Est"));
+ map.insert(QObject::tr("Prophets"), QString("Isa - Mal"));
+ map.insert(QObject::tr("New testament"), QString("Mat - Rev"));
+ map.insert(QObject::tr("Gospels"), QString("Mat - Joh"));
+ map.insert(QObject::tr("Letters/Epistles"), QString("Rom - Jude"));
+ map.insert(QObject::tr("Paul's Epistles"), QString("Rom - Phile"));
+
+ //make the list to the current bookname language!
+ CBTConfig::StringMap::Iterator it;
+ sword::VerseKey vk;
+ vk.setLocale("en_US");
+
+ for (it = map.begin(); it != map.end(); ++it) {
+ sword::ListKey list = vk.ParseVerseList(it.value().toLocal8Bit(), "Genesis 1:1", true);
+ QString data;
+ for (int i = 0; i < list.Count(); ++i) {
+ data += QString::fromUtf8(list.GetElement(i)->getRangeText()) + "; ";
+ }
+ map[it.key()] = data; //set the new data
+ };
+
+ return map;
+ };
+ default:
+ return CBTConfig::StringMap();
+ }
+
+ return CBTConfig::StringMap();
+}
+
+
+QString CBTConfig::getKey( const CLanguageMgr::Language* const language ) {
+ Q_ASSERT(!language->name().isEmpty());
+ return language->name();
+}
+
+QFont& CBTConfig::getDefault( const CLanguageMgr::Language* const)
+{
+ //language specific lookup of the font name
+ if (m_defaultFont)
+ {
+ return *m_defaultFont;
+ }
+
+// TODO - make the font name and size a configuration option
+ //int fontSize = QWebSettings::globalSettings()->fontSize(QWebSettings::DefaultFontSize);
+ int fontSize = 12;
+ QString fontName = QWebSettings::globalSettings()->fontFamily(QWebSettings::StandardFont);
+
+ m_defaultFont = new QFont(fontName, fontSize); //TODO: there may be a mem leak here!
+ return *m_defaultFont;
+}
+
+QString CBTConfig::get( const CBTConfig::strings ID)
+{
+ QString result;
+ getConfig()->beginGroup("strings");
+ result = getConfig()->value(getKey(ID), getDefault(ID)).toString();
+ getConfig()->endGroup();
+ return result;
+
+}
+
+CSwordModuleInfo* CBTConfig::get( const CBTConfig::modules ID)
+{
+ CSwordModuleInfo* result;
+ getConfig()->beginGroup("modules");
+ result = CPointers::backend()->findModuleByName( getConfig()->value(getKey(ID), getDefault(ID)).toString() );
+ getConfig()->endGroup();
+ return result;
+}
+
+bool CBTConfig::get( const CBTConfig::bools ID)
+{
+ bool result;
+ getConfig()->beginGroup("bools");
+ result = getConfig()->value(getKey(ID), getDefault(ID)).toBool();
+ getConfig()->endGroup();
+ return result;
+}
+
+int CBTConfig::get( const CBTConfig::ints ID)
+{
+ int result;
+ getConfig()->beginGroup("ints");
+ result = getConfig()->value(getKey(ID), getDefault(ID)).toInt();
+ getConfig()->endGroup();
+ return result;
+}
+
+QList<int> CBTConfig::get( const CBTConfig::intLists ID )
+{
+ QList<int> result;
+ getConfig()->beginGroup("intlists");
+ result = StringToIntList( getConfig()->value(getKey(ID), IntListToString( getDefault(ID) )).toString() );
+ getConfig()->endGroup();
+ return result;
+}
+
+QStringList CBTConfig::get( const CBTConfig::stringLists ID )
+{
+ QStringList result;
+ getConfig()->beginGroup("stringlists");
+ result = getConfig()->value(getKey(ID), getDefault(ID)).toStringList();
+ getConfig()->endGroup();
+ return result;
+}
+
+CBTConfig::StringMap CBTConfig::get( const CBTConfig::stringMaps ID )
+{
+ getConfig()->beginGroup(getKey(ID));
+ CBTConfig::StringMap map;
+
+ QStringList keys(getConfig()->childKeys());
+ if (!keys.isEmpty()) {
+ switch (ID) {
+ case searchScopes: { //make sure we return the scopes in the chosen language. saved keys are in english
+ sword::VerseKey vk;
+ foreach (QString key, keys) {
+ Q_ASSERT(!key.isEmpty());
+ sword::ListKey list = vk.ParseVerseList(getConfig()->value(key).toString().toUtf8(), "Genesis 1:1", true);
+ QString data;
+ for (int i = 0; i < list.Count(); ++i) {
+ data += QString::fromUtf8(list.GetElement(i)->getRangeText()) + "; ";
+ }
+ map[key] = data; //set the new data
+ }
+ }
+ default: break;
+ }
+ }
+ else
+ {
+ map = getDefault(ID);
+ }
+ getConfig()->endGroup();
+ return map;
+}
+
+CBTConfig::FontSettingsPair CBTConfig::get( const CLanguageMgr::Language* const language )
+{
+ if (fontConfigMap.contains(language)) {
+ return fontConfigMap.find(language).value();
+ }
+
+ FontSettingsPair settings;
+
+ getConfig()->beginGroup("font standard settings");
+ settings.first = getConfig()->value(getKey(language), QVariant(false)).toBool();
+ getConfig()->endGroup();
+ getConfig()->beginGroup("fonts");
+
+ QFont font;
+ if (settings.first)
+ font.fromString(getConfig()->value(getKey(language), getDefault(language)).toString());
+ else
+ font = getDefault(language);
+
+ settings.second = font;
+ getConfig()->endGroup();
+
+ fontConfigMap.insert(language, settings); //cache the value
+ return settings;
+}
+
+void CBTConfig::set( const CBTConfig::strings ID, const QString value )
+{
+// KConfigGroup cg = CBTConfig::getConfig()->group("strings");
+// cg.writeEntry(getKey(ID), value);
+ getConfig()->beginGroup("strings");
+ getConfig()->setValue(getKey(ID), value);
+ getConfig()->endGroup();
+}
+
+void CBTConfig::set( const CBTConfig::modules ID, CSwordModuleInfo* const value )
+{
+// KConfigGroup cg = CBTConfig::getConfig()->group("modules");
+// cg.writeEntry(getKey(ID), value ? value->name() : QString::null);
+ getConfig()->beginGroup("modules");
+ getConfig()->setValue(getKey(ID), value ? value->name() : QString::null);
+ getConfig()->endGroup();
+}
+
+void CBTConfig::set( const CBTConfig::modules ID, const QString& value )
+{
+ CSwordModuleInfo* module = CPointers::backend()->findModuleByName(value);
+ if (module) {
+ CBTConfig::set(ID, module);
+ }
+}
+
+void CBTConfig::set(const CBTConfig::bools ID,const bool value )
+{
+ getConfig()->beginGroup("bools");
+ getConfig()->setValue(getKey(ID), value);
+ getConfig()->endGroup();
+}
+
+void CBTConfig::set(const CBTConfig::ints ID, const int value )
+{
+ getConfig()->beginGroup("ints");
+ getConfig()->setValue(getKey(ID), value);
+ getConfig()->endGroup();
+}
+
+void CBTConfig::set( const CBTConfig::intLists ID, const QList<int> value )
+{
+ getConfig()->beginGroup("intlists");
+ getConfig()->setValue(getKey(ID), IntListToString(value));
+ getConfig()->endGroup();
+}
+
+void CBTConfig::set( const CBTConfig::stringLists ID, const QStringList value )
+{
+ getConfig()->beginGroup("stringlists");
+ getConfig()->setValue(getKey(ID), value);
+ getConfig()->endGroup();
+}
+
+void CBTConfig::set( const CBTConfig::stringMaps ID, const CBTConfig::StringMap value )
+{
+ getConfig()->beginGroup(getKey(ID));
+ getConfig()->remove(""); //clear all entries of this group to make sure old stuff gets removed
+
+ switch (ID) {
+ case searchScopes: {
+ /**
+ * We want to make sure that the search scopes are saved with english key names so loading them
+ * will always work with each locale set.
+ */
+ CBTConfig::StringMap::ConstIterator it;
+ QString data;// = QString::null;
+
+ sword::VerseKey vk;
+ for (it = value.begin(); it != value.end(); ++it) {
+ sword::ListKey list = vk.ParseVerseList(it.value().toUtf8(), "Genesis 1:1", true);
+ data = QString::null;
+ for (int i = 0; i < list.Count(); ++i) {
+ if ( sword::VerseKey* range = dynamic_cast<sword::VerseKey*>(list.GetElement(i)) ) {
+ range->setLocale("en");
+ data += QString::fromUtf8( range->getRangeText() ) + ";";
+ }
+ }
+ getConfig()->setValue(it.key(), data);
+ }
+ break;
+ }
+ default: {
+ for (CBTConfig::StringMap::ConstIterator it = value.begin(); it != value.end(); ++it) {
+ getConfig()->setValue(it.key(), it.value());
+ }
+ break;
+ }
+ }
+ getConfig()->endGroup();
+}
+
+
+void CBTConfig::set( const CLanguageMgr::Language* const language, const FontSettingsPair& value )
+{
+ getConfig()->beginGroup("fonts");
+ getConfig()->setValue(getKey(language), value.second.toString());
+ getConfig()->endGroup();
+ getConfig()->beginGroup("font standard settings");
+ getConfig()->setValue(getKey(language), value.first);
+ getConfig()->endGroup();
+
+ if (fontConfigMap.contains(language)) {
+ fontConfigMap.remove
+ (language); //remove it from the cache
+ }
+}
+
+CSwordBackend::DisplayOptions CBTConfig::getDisplayOptionDefaults()
+{
+ CSwordBackend::DisplayOptions options;
+ options.lineBreaks = get(CBTConfig::lineBreaks);
+ options.verseNumbers = get(CBTConfig::verseNumbers);
+
+ return options;
+}
+
+CSwordBackend::FilterOptions CBTConfig::getFilterOptionDefaults()
+{
+ CSwordBackend::FilterOptions options;
+
+ options.footnotes = true; //required for the info display
+ options.strongNumbers = true; //get(CBTConfig::strongNumbers);
+ options.headings = get(CBTConfig::headings);
+ options.morphTags = true;//required for the info display
+ options.lemmas = true;//required for the info display
+ options.redLetterWords = true;
+ options.hebrewPoints = get(CBTConfig::hebrewPoints);
+ options.hebrewCantillation = get(CBTConfig::hebrewCantillation);
+ options.greekAccents = get(CBTConfig::greekAccents);
+ options.textualVariants = get(CBTConfig::textualVariants);
+ options.scriptureReferences = get(CBTConfig::scriptureReferences);
+ options.morphSegmentation = get(CBTConfig::morphSegmentation);
+
+ return options;
+}
+
+//void CBTConfig::setupAccelSettings(const CBTConfig::keys /*type*/, KActionCollection* const /*actionCollection*/)
+//{
+// qDebug("CBTConfig::setupAccelSettings");
+// QString groupName;
+// switch (type) {
+// case allWindows : {
+// groupName = "Displaywindow shortcuts";
+// break;
+// };
+// case writeWindow : {
+// groupName = "Writewindow shortcuts";
+// break;
+// };
+// case readWindow : {
+// groupName = "Readwindow shortcuts";
+// break;
+// };
+// case bookWindow : {
+// groupName = "Book shortcuts";
+// break;
+// };
+// case bibleWindow : {
+// groupName = "Bible shortcuts";
+// break;
+// };
+// case commentaryWindow : {
+// groupName = "Commentary shortcuts";
+// break;
+// };
+// case lexiconWindow : {
+// groupName = "Lexicon shortcuts";
+// break;
+// };
+// case application : {
+// groupName = "Application shortcuts";
+// break;
+// };
+// };
+// qDebug() << groupName;
+// Q_ASSERT(CBTConfig::getConfig());
+// //buggy???
+// KConfigGroup* cg = &(CBTConfig::getConfig()->group(groupName));
+// //KConfigGroup* cg;
+//
+// Q_ASSERT(cg);
+// Q_ASSERT(actionCollection);
+// //actionCollection->readSettings(cg);
+// actionCollection->setConfigGroup(groupName);
+//
+// actionCollection->readSettings();
+// qDebug("CBTConfig::setupAccelSettings end");
+//}
+
+//void CBTConfig::saveAccelSettings(const CBTConfig::keys /*type*/, KActionCollection* const /*actionCollection*/)
+//{
+// qDebug("CBTConfig::saveAccelSettings");
+// QString groupName;
+// switch (type) {
+// case allWindows : {
+// groupName = "Displaywindow shortcuts";
+// break;
+// };
+// case writeWindow : {
+// groupName = "Writewindow shortcuts";
+// break;
+// };
+// case readWindow : {
+// groupName = "Readwindow shortcuts";
+// break;
+// };
+// case bookWindow : {
+// groupName = "Book shortcuts";
+// break;
+// };
+// case bibleWindow : {
+// groupName = "Bible shortcuts";
+// break;
+// };
+// case commentaryWindow : {
+// groupName = "Commentary shortcuts";
+// break;
+// };
+// case lexiconWindow : {
+// groupName = "Lexicon shortcuts";
+// break;
+// };
+// case application : {
+// groupName = "Application shortcuts";
+// break;
+// };
+// };
+//
+// // KConfigGroup* cg = &(CBTConfig::getConfig()->group(groupName));
+//
+// qDebug("NOT saving accelerators!");
+// //actionCollection->writeSettings(cg);
+// qDebug("CBTConfig::saveAccelSettings end");
+//}
+
+
+QString CBTConfig::getModuleEncryptionKey( const QString& module )
+{
+ Q_ASSERT(!module.isEmpty());
+ QString result;
+ getConfig()->beginGroup("Module keys");
+ result = getConfig()->value(module, QVariant(QString::null)).toString();
+ getConfig()->endGroup();
+ return result;
+}
+
+void CBTConfig::setModuleEncryptionKey( const QString& module, const QString& key )
+{
+ getConfig()->beginGroup("Module keys");
+ getConfig()->setValue(module, key);
+ getConfig()->endGroup();
+}
+
+QSettings* CBTConfig::getConfig()
+{
+ static QSettings config(util::filesystem::DirectoryUtil::getUserBaseDir().absolutePath() + "/bibletimerc", QSettings::IniFormat);
+ return &config;
+}
+
+void CBTConfig::syncConfig()
+{
+ CBTConfig::getConfig()->sync();
+}
+
+QString CBTConfig::IntListToString( const QList<int> intList )
+{
+ QStringList intStrings;
+ foreach(int i, intList)
+ {
+ intStrings << QString::number(i);
+ }
+ return intStrings.join(",");
+}
+
+QList<int> CBTConfig::StringToIntList( const QString intListString )
+{
+ QList<int> intList;
+ if (!intListString.isEmpty() && intListString.contains(','))
+ {
+ foreach(QString intString, intListString.split(","))
+ {
+ intList << intString.trimmed().toInt();
+ }
+ }
+ return intList;
+}
diff --git a/src/backend/config/cbtconfig.h b/src/backend/config/cbtconfig.h
new file mode 100644
index 0000000..0ded865
--- /dev/null
+++ b/src/backend/config/cbtconfig.h
@@ -0,0 +1,197 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CBTCONFIG_H
+#define CBTCONFIG_H
+
+#include "backend/managers/cswordbackend.h"
+
+//Qt includes
+#include <QString>
+#include <QFont>
+#include <QList>
+#include <QMap>
+
+//Forward declarations
+class QSettings;
+//class CLanguageMgr::Language;
+
+/**
+ * This class is the interface to the config object of BibleTime
+ * @author The BibleTime team
+ */
+class CBTConfig {
+public:
+ typedef QMap<QString, QString> StringMap;
+
+ enum strings {
+ bibletimeVersion,
+ language,
+ displayStyle,
+ bookshelfCurrentItem
+ };
+ enum modules {
+ standardBible = 0, //just to make sure, default is IMHO 0, so that's redundant here
+ standardCommentary,
+ standardLexicon,
+ standardDailyDevotional,
+ standardHebrewStrongsLexicon,
+ standardGreekStrongsLexicon,
+ standardHebrewMorphLexicon,
+ standardGreekMorphLexicon,
+ lastModuleType = standardGreekMorphLexicon
+ };
+ enum bools {
+ firstSearchDialog,
+ readOldBookmarks,
+
+ toolbar,
+ mainIndex,
+ infoDisplay,
+
+ autoTileVertical,
+ autoTileHorizontal,
+ autoCascade,
+
+ lineBreaks,
+ verseNumbers,
+
+ logo,
+ autoDeleteOrphanedIndices,
+ crashedLastTime,
+ crashedTwoTimes,
+
+ bookshelfShowHidden,
+
+ allowNetworkConnection
+ };
+ enum ints {
+ footnotes,
+ strongNumbers,
+ headings,
+ morphTags,
+ lemmas,
+ hebrewPoints,
+ hebrewCantillation,
+ greekAccents,
+ textualVariants,
+ scriptureReferences,
+ morphSegmentation,
+
+ bookshelfContentsX,
+ bookshelfContentsY,
+ magDelay, /* The delay until a mouse move makes the content appear in the mag */
+ bookshelfGrouping,
+ mainindexActiveTab,
+
+ searchDialogWidth,
+ searchDialogHeight,
+ searchDialogX,
+ searchDialogY,
+ searchType,
+
+ installPathIndex
+ };
+ enum intLists {
+ leftPaneSplitterSizes,
+ mainSplitterSizes,
+ searchMainSplitterSizes,
+ searchResultSplitterSizes
+ };
+ enum stringLists {
+ searchCompletionTexts,
+ searchTexts,
+ searchModulesHistory,
+ bookshelfOpenGroups,
+ hiddenModules
+ };
+ enum keys {
+ allWindows,
+ readWindow,
+ writeWindow,
+ bookWindow,
+ bibleWindow,
+ commentaryWindow,
+ lexiconWindow,
+ application
+ };
+ enum stringMaps {
+ searchScopes
+ };
+ typedef std::pair<bool, QFont> FontSettingsPair;
+
+ static QString get( const CBTConfig::strings );
+ static CSwordModuleInfo* get( const CBTConfig::modules );
+ static bool get( const CBTConfig::bools );
+ static int get( const CBTConfig::ints );
+ static QList<int> get( const CBTConfig::intLists );
+ static QStringList get( const CBTConfig::stringLists );
+ static CBTConfig::StringMap get( const CBTConfig::stringMaps );
+
+ static FontSettingsPair get( const CLanguageMgr::Language* const );
+
+ static QString getDefault( const CBTConfig::strings );
+ static QString getDefault( const CBTConfig::modules );
+ static bool getDefault( const CBTConfig::bools );
+ static int getDefault( const CBTConfig::ints );
+ static QList<int> getDefault( const CBTConfig::intLists );
+ static QStringList getDefault( const CBTConfig::stringLists );
+ static CBTConfig::StringMap getDefault( const CBTConfig::stringMaps );
+ static QFont& getDefault( const CLanguageMgr::Language* const );
+
+ static void set( const CBTConfig::strings, const QString value );
+ static void set( const CBTConfig::modules, CSwordModuleInfo* const module );
+ static void set( const CBTConfig::modules, const QString& moduleName );
+ static void set( const CBTConfig::bools, const bool value );
+ static void set( const CBTConfig::ints, const int value );
+ static void set( const CBTConfig::intLists, const QList<int> value );
+ static void set( const CBTConfig::stringLists, const QStringList value);
+ static void set( const CBTConfig::stringMaps, const CBTConfig::StringMap value);
+ static void set( const CLanguageMgr::Language* const language, const FontSettingsPair& fontSettings );
+
+ static CSwordBackend::FilterOptions getFilterOptionDefaults();
+ static CSwordBackend::DisplayOptions getDisplayOptionDefaults();
+
+// static void setupAccelSettings(const CBTConfig::keys type, KActionCollection* const actionCollection);
+// static void saveAccelSettings(const CBTConfig::keys type, KActionCollection* const actionCollection);
+
+ static QString getModuleEncryptionKey( const QString& name );
+ static void setModuleEncryptionKey( const QString& name, const QString& key );
+
+ /** Re-reads the config from disk */
+ static void syncConfig();
+
+private:
+ friend class BibleTimeTest;
+ /** The config object.
+ * @return A config object which is used currently, may be the global config or the session config
+ */
+ static QSettings* getConfig();
+
+ static QString getKey( const CBTConfig::strings );
+ static QString getKey( const CBTConfig::modules );
+ static QString getKey( const CBTConfig::bools );
+ static QString getKey( const CBTConfig::ints );
+ static QString getKey( const CBTConfig::intLists );
+ static QString getKey( const CBTConfig::stringLists );
+ static QString getKey( const CBTConfig::stringMaps );
+ static QString getKey( const CLanguageMgr::Language* const );
+
+ static QString IntListToString( const QList<int> );
+ static QList<int> StringToIntList( const QString );
+
+ //static caches
+ static QFont* m_defaultFont;
+
+ typedef QMap<const CLanguageMgr::Language*, CBTConfig::FontSettingsPair> FontCache;
+ static QMap<const CLanguageMgr::Language*, CBTConfig::FontSettingsPair> fontConfigMap;
+};
+
+
+#endif
diff --git a/src/backend/cswordmodulesearch.cpp b/src/backend/cswordmodulesearch.cpp
new file mode 100644
index 0000000..f57a87a
--- /dev/null
+++ b/src/backend/cswordmodulesearch.cpp
@@ -0,0 +1,123 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//BibleTime includes
+#include "cswordmodulesearch.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/managers/cswordbackend.h"
+#include "backend/config/cbtconfig.h"
+
+//Sword includes
+#include <swmodule.h>
+#include <swkey.h>
+#include <listkey.h>
+
+
+CSwordModuleSearch* CSwordModuleSearch::searcher = 0;
+
+CSwordModuleSearch::CSwordModuleSearch()
+ : m_searchedText(QString::null),
+ m_searchOptions(0),
+ m_foundItems(false)
+{
+ searcher = this;
+}
+
+CSwordModuleSearch::~CSwordModuleSearch() {
+ searcher = 0;
+}
+
+/** This function sets the modules which should be searched. */
+void CSwordModuleSearch::setModules( const QList<CSwordModuleInfo*>& list ) {
+ m_moduleList = list;
+}
+
+/** Starts the search for the search text. */
+bool CSwordModuleSearch::startSearch() {
+ backend()->setFilterOptions ( CBTConfig::getFilterOptionDefaults() );
+ m_foundItems = false;
+
+ bool foundItems = false;
+
+ // for (m_moduleList.first(); m_moduleList.current() && !m_terminateSearch; m_moduleList.next()) {
+ QList<CSwordModuleInfo*>::iterator end_it = m_moduleList.end();
+
+ for (QList<CSwordModuleInfo*>::iterator it = m_moduleList.begin(); it != end_it; ++it) {
+ if ( (*it)->searchIndexed(m_searchedText/*, m_searchOptions*/, m_searchScope) ) {
+ foundItems = true;
+ }
+ }
+
+ m_foundItems = foundItems;
+
+ //m_finishedSig.activate();
+ emit finished();
+ return true;
+}
+
+/** Sets the text which should be search in the modules. */
+void CSwordModuleSearch::setSearchedText( const QString& text ) {
+ m_searchedText = text;
+}
+
+/** Sets the search scope. */
+void CSwordModuleSearch::setSearchScope( const sword::ListKey& scope ) {
+ m_searchScope.copyFrom( scope );
+
+ if (!strlen(scope.getRangeText())) { //we can't search with an empty search scope, would crash
+ //reset the scope
+ resetSearchScope();
+
+ //disable searching with a scope!
+ // if (m_searchOptions | useScope) {
+ // qWarning("using the scope!");
+ //set back the scope flag
+ // }
+ }
+}
+
+/** Sets the search scope back. */
+void CSwordModuleSearch::resetSearchScope() {
+ m_searchScope.ClearList();
+}
+
+/** Returns true if in the last search the searcher found items, if no items were found return false. */
+bool CSwordModuleSearch::foundItems() const {
+ return m_foundItems;
+}
+
+/** Returns a copy of the used search scope. */
+const sword::ListKey& CSwordModuleSearch::searchScope() const {
+ return m_searchScope;
+}
+
+void CSwordModuleSearch::connectFinished( QObject *receiver, const char *member ) {
+ //m_finishedSig.connect(receiver, member);
+ QObject::connect(this, SIGNAL(finished()), receiver, member);
+}
+
+/** Should be called when the search finished. */
+void CSwordModuleSearch::searchFinished() {
+ //m_finishedSig.activate();
+ emit finished();
+}
+
+bool CSwordModuleSearch::modulesHaveIndices( const QList<CSwordModuleInfo*>& modules )
+{
+ bool hasIndices = true;
+ QList<CSwordModuleInfo*>::const_iterator end_it = modules.end();
+ for( QList<CSwordModuleInfo*>::const_iterator it = modules.begin(); it != end_it; ++it) {
+ if (!(*it)->hasIndex()) {
+ hasIndices = false;
+ break;
+ }
+ }
+ return hasIndices;
+}
diff --git a/src/backend/cswordmodulesearch.h b/src/backend/cswordmodulesearch.h
new file mode 100644
index 0000000..7ba6a6f
--- /dev/null
+++ b/src/backend/cswordmodulesearch.h
@@ -0,0 +1,98 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CSWORDMODULESEARCH_H
+#define CSWORDMODULESEARCH_H
+
+//BibleTime - backend
+class CSwordModuleInfo;
+
+//BibleTime - utils
+#include "util/cpointers.h"
+
+//Qt includes
+#include <QObject>
+#include <QString>
+
+//Sword includes
+#include <listkey.h>
+
+/**
+ * CSwordModuleSearch manages the search on Sword modules. It manages the thread(s)
+ * and manages the different modules.
+ *
+ * @author The BibleTime team
+ * @version $Id: cswordmodulesearch.h,v 1.34 2006/08/08 19:32:48 joachim Exp $
+ */
+
+class CSwordModuleSearch: public QObject, CPointers {
+ Q_OBJECT
+
+public:
+ CSwordModuleSearch();
+ /**
+ * The destructor of this class. It cleans uop memory before it's deleted.
+ */
+ virtual ~CSwordModuleSearch();
+ /**
+ * Sets the text which should be search in the modules.
+ */
+ void setSearchedText( const QString& );
+ /**
+ * Starts the search for the search text.
+ */
+ bool startSearch();
+ /**
+ * This function sets the modules which should be searched.
+ */
+ void setModules( const QList<CSwordModuleInfo*>& );
+ /**
+ * Sets the search scope.
+ */
+ void setSearchScope( const sword::ListKey& scope );
+ /**
+ * Sets the seaech scope back.
+ */
+ void resetSearchScope();
+ /**
+ * @return "true" if in the last search the searcher found items, if no items were found return "false"
+ */
+ bool foundItems() const;
+ /**
+ * Returns a copy of the used search scope.
+ */
+ const sword::ListKey& searchScope() const;
+
+ void connectFinished( QObject * receiver, const char * member );
+ void searchFinished();
+
+ /**
+ * Returns true if all of the specified modules have indices already built.
+ */
+ bool modulesHaveIndices( const QList<CSwordModuleInfo*>& );
+
+protected:
+ QString m_searchedText;
+ sword::ListKey m_searchScope;
+ QList<CSwordModuleInfo*> m_moduleList;
+
+ int m_searchOptions;
+
+ bool m_foundItems;
+
+signals:
+ void finished();
+
+private:
+ static CSwordModuleSearch* searcher;
+};
+
+#endif
diff --git a/src/backend/drivers/cswordbiblemoduleinfo.cpp b/src/backend/drivers/cswordbiblemoduleinfo.cpp
new file mode 100644
index 0000000..921157b
--- /dev/null
+++ b/src/backend/drivers/cswordbiblemoduleinfo.cpp
@@ -0,0 +1,261 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//BibleTime includes
+#include "cswordbiblemoduleinfo.h"
+#include "backend/managers/cswordbackend.h"
+#include "backend/keys/cswordversekey.h"
+
+//Qt
+#include <QFile>
+
+//Sword
+#include <versekey.h>
+
+#include <boost/scoped_ptr.hpp>
+
+
+CSwordBibleModuleInfo::CSwordBibleModuleInfo( sword::SWModule* module, CSwordBackend* const usedBackend )
+: CSwordModuleInfo(module, usedBackend),
+m_lowerBound(0),
+m_upperBound(0),
+m_bookList(0),
+m_cachedLocale("unknown"),
+m_hasOT(-1),
+m_hasNT(-1) {}
+
+CSwordBibleModuleInfo::CSwordBibleModuleInfo( const CSwordBibleModuleInfo& m ) :
+CSwordModuleInfo(m),
+m_lowerBound(0),
+m_upperBound(0),
+m_bookList(0) {
+ if (m.m_bookList) {
+ m_bookList = new QStringList();
+ *m_bookList = *m.m_bookList;
+ }
+
+ m_hasOT = m.m_hasOT;
+ m_hasNT = m.m_hasNT;
+ m_cachedLocale = m.m_cachedLocale;
+}
+
+CSwordModuleInfo* CSwordBibleModuleInfo::clone() {
+ return new CSwordBibleModuleInfo(*this);
+}
+
+CSwordBibleModuleInfo::~CSwordBibleModuleInfo() {
+ delete m_bookList;
+}
+
+void CSwordBibleModuleInfo::initBounds() {
+ if (m_hasOT == -1) {
+ m_hasOT = hasTestament(OldTestament);
+ }
+
+ if (m_hasNT == -1) {
+ m_hasNT = hasTestament(NewTestament);
+ }
+
+ if (m_hasOT) {
+ m_lowerBound.key("Genesis 1:1");
+ }
+ else {
+ m_lowerBound.key("Matthew 1:1");
+ }
+
+ if (!m_hasNT) {
+ m_upperBound.key("Malachi 4:6");
+ }
+ else {
+ m_upperBound.key("Revelation of John 22:21");
+ }
+}
+
+
+/** Returns the books available in this module */
+QStringList* CSwordBibleModuleInfo::books() {
+ if (m_cachedLocale != backend()->booknameLanguage()) { //if the locale has changed
+ delete m_bookList;
+ m_bookList = 0;
+ }
+
+ if (!m_bookList) {
+ m_bookList = new QStringList();
+
+ initBounds();
+ int min = 0;
+ int max = 1;
+
+ //find out if we have ot and nt, only ot or only nt
+
+ if (m_hasOT>0 && m_hasNT>0) { //both
+ min = 0;
+ max = 1;
+ }
+ else if (m_hasOT>0 && !m_hasNT) { //only OT
+ min = 0;
+ max = 0;
+ }
+ else if (!m_hasOT && m_hasNT>0) { //only NT
+ min = 1;
+ max = 1;
+ }
+ else if (!m_hasOT && !m_hasNT) { //somethings wrong here! - no OT and no NT
+ qWarning("CSwordBibleModuleInfo (%s) no OT and not NT! Check your config!", module()->Name());
+ min = 0;
+ max = -1;
+ }
+
+ boost::scoped_ptr<sword::VerseKey> key((sword::VerseKey *)module()->CreateKey());
+ (*key) = sword::TOP;
+
+ for (key->Testament(min+1); !key->Error() && (key->Testament()-1) <= max; key->Book(key->Book()+1)) {
+ m_bookList->append( QString::fromUtf8(key->getBookName()) );
+ }
+
+ m_cachedLocale = backend()->booknameLanguage();
+ }
+
+ return m_bookList;
+}
+
+/** Returns the number of chapters for the given book. */
+unsigned int CSwordBibleModuleInfo::chapterCount(const unsigned int book) {
+ int result = 0;
+
+ boost::scoped_ptr<sword::VerseKey> key((sword::VerseKey *)module()->CreateKey());
+ (*key) = sword::TOP;
+
+ // works for old and new versions
+ key->Book(book);
+ (*key) = sword::MAXCHAPTER;
+ result = key->Chapter();
+
+ return result;
+}
+
+unsigned int CSwordBibleModuleInfo::chapterCount(const QString& book) {
+ return chapterCount( bookNumber(book) );
+}
+
+/** Returns the number of verses for the given chapter. */
+
+unsigned int CSwordBibleModuleInfo::verseCount( const unsigned int book, const unsigned int chapter ) {
+ unsigned int result = 0;
+
+ boost::scoped_ptr<sword::VerseKey> key((sword::VerseKey *)module()->CreateKey());
+ (*key) = sword::TOP;
+
+ // works for old and new versions
+ key->Book(book);
+ key->Chapter(chapter);
+ (*key) = sword::MAXVERSE;
+ result = key->Verse();
+
+ return result;
+}
+
+unsigned int CSwordBibleModuleInfo::verseCount( const QString& book, const unsigned int chapter ) {
+ return verseCount( bookNumber(book), chapter );
+}
+
+unsigned int CSwordBibleModuleInfo::bookNumber(const QString &book) {
+ unsigned int bookNumber = 0;
+ bool found = false;
+ int min = 0;
+ int max = 1;
+
+ //find out if we have ot and nt, only ot or only nt
+ initBounds();
+
+ boost::scoped_ptr<sword::VerseKey> key((sword::VerseKey *)module()->CreateKey());
+ (*key) = sword::TOP;
+
+#ifdef SWORD_MULTIVERSE
+ key->setBookName(book.toUtf8().constData());
+
+ bookNumber = ((key->Testament() > 1) ? key->BMAX[0] : 0) + key->Book();
+#else
+
+ if ((m_hasOT>0 && m_hasNT>0) || (m_hasOT == -1 && m_hasNT == -1)) {
+ min = 0;
+ max = 1;
+ bookNumber = 0;
+ }
+ else if (m_hasOT>0 && !m_hasNT) {
+ min = 0;
+ max = 0;
+ bookNumber = 0;
+ }
+ else if (!m_hasOT && m_hasNT>0) {
+ min = 1;
+ max = 1;
+ bookNumber = key->BMAX[0];
+ }
+ else if (!m_hasOT && !m_hasNT) {
+ min = 0;
+ max = -1; //no loop
+ bookNumber = 0;
+ }
+
+ for (int i = min; i <= max && !found; ++i) {
+ for ( int j = 0; j < key->BMAX[i] && !found; ++j) {
+ ++bookNumber;
+
+ if (book == QString::fromUtf8( key->books[i][j].name) )
+ found = true;
+ }
+ }
+#endif
+
+ return bookNumber;
+}
+
+/** Returns true if his module has the text of desired type of testament */
+bool CSwordBibleModuleInfo::hasTestament( CSwordBibleModuleInfo::Testament type ) {
+ if (m_hasOT == -1 || m_hasNT == -1) {
+ const bool oldStatus = module()->getSkipConsecutiveLinks();
+ module()->setSkipConsecutiveLinks(true);
+
+ *module() = sword::TOP; //position to first entry
+ sword::VerseKey key( module()->KeyText() );
+
+ if (key.Testament() == 1) { // OT && NT
+ m_hasOT = 1;
+ }
+ else if (key.Testament() == 2) { //no OT
+ m_hasOT = 0;
+ }
+
+ *module() = sword::BOTTOM;
+ key = module()->KeyText();
+
+ if (key.Testament() == 1) { // only OT, no NT
+ m_hasNT = 0;
+ }
+ else if (key.Testament() == 2) { //has NT
+ m_hasNT = 1;
+ }
+
+ module()->setSkipConsecutiveLinks(oldStatus);
+ }
+
+ switch (type) {
+
+ case OldTestament:
+ return m_hasOT>0;
+
+ case NewTestament:
+ return m_hasNT>0;
+
+ default:
+ return false;
+ }
+}
+
diff --git a/src/backend/drivers/cswordbiblemoduleinfo.h b/src/backend/drivers/cswordbiblemoduleinfo.h
new file mode 100644
index 0000000..c25eb37
--- /dev/null
+++ b/src/backend/drivers/cswordbiblemoduleinfo.h
@@ -0,0 +1,126 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CSWORDBIBLEMODULEINFO_H
+#define CSWORDBIBLEMODULEINFO_H
+
+#include "cswordmoduleinfo.h"
+#include "backend/keys/cswordversekey.h"
+
+//Qt
+#include <QStringList>
+
+/**
+ * This is the CModuleInfo imlementation for Bible modules managed by Sword.
+ *
+ * @short Implementation for Sword Bibles
+ * @author The BibleTime team
+ * @version $Id: cswordbiblemoduleinfo.h,v 1.18 2006/02/25 11:38:15 joachim Exp $
+ */
+
+class CSwordBibleModuleInfo : public CSwordModuleInfo {
+
+public:
+ enum Testament {
+ OldTestament = 1,
+ NewTestament = 2
+ };
+
+ /**
+ * The constructor of this class
+ */
+ CSwordBibleModuleInfo( sword::SWModule* module, CSwordBackend* const );
+ /** The copy constructor for this Bible module.
+ */
+ CSwordBibleModuleInfo( const CSwordBibleModuleInfo& m );
+ /**
+ * The destructor of this class
+ */
+ ~CSwordBibleModuleInfo();
+ /**
+ * Returns the number of avalable verses for the given chapter and book.
+ *
+ * @param book The number book we should use
+ * @param chapter The chapter we should use
+ * @return The number of verses for the given book and chapter
+ */
+ virtual unsigned int verseCount( const unsigned int book, const unsigned int chapter );
+ /**
+ * Returns the number of avalable verses for the given chapter and book.
+ *
+ * @param book The name of the book we use
+ * @param chapter The number of the chapter we use
+ * @return The number of verses for the given book and chapter
+ */
+ virtual unsigned int verseCount( const QString& book, const unsigned int chapter );
+ /** Information about the chapters in a book.
+ * @return The number of available chapters of the given book.
+ * @return The number of chapters for the given book
+ */
+ virtual unsigned int chapterCount( const unsigned int book );
+ /** Information about the chapters in a book.
+ * @return The number of available chapters of the given book.
+ */
+ virtual unsigned int chapterCount( const QString& book );
+ /** Return all book of this module.
+ * @return A QStringList containing the books which are available in this module.
+ */
+ virtual QStringList* books();
+ /**
+ * Reimplementation, Returns the type
+ */
+ virtual CSwordModuleInfo::ModuleType type() const;
+ /**
+ * @return the book number, values starting with 1; 0 if not found
+ */
+ unsigned int bookNumber(const QString &book);
+ /**
+ * Returns true if his module has the text of desired type of testament
+ */
+ bool hasTestament( CSwordBibleModuleInfo::Testament );
+ /** Reimplementation to clone this object. */
+ virtual CSwordModuleInfo* clone();
+ /**
+ * Returns the key which represents the lower bound of this module.
+ */
+ inline const CSwordVerseKey& lowerBound();
+ /**
+ * Returns the key which represents the upper bound of this module.
+ */
+ inline const CSwordVerseKey& upperBound();
+
+private:
+ void initBounds();
+
+ CSwordVerseKey m_lowerBound;
+ CSwordVerseKey m_upperBound;
+
+ QStringList* m_bookList; //This booklist is cached
+ QString m_cachedLocale;
+ short int m_hasOT;
+ short int m_hasNT;
+};
+
+inline CSwordModuleInfo::ModuleType CSwordBibleModuleInfo::type() const {
+ return CSwordModuleInfo::Bible;
+}
+
+/** Returns the key which represents the lower bound of this module. */
+inline const CSwordVerseKey& CSwordBibleModuleInfo::lowerBound() {
+ initBounds();
+ return m_lowerBound;
+}
+
+/** Returns the key which represents the lower bound of this module. */
+inline const CSwordVerseKey& CSwordBibleModuleInfo::upperBound() {
+ initBounds();
+ return m_upperBound;
+}
+
+#endif
diff --git a/src/backend/drivers/cswordbookmoduleinfo.cpp b/src/backend/drivers/cswordbookmoduleinfo.cpp
new file mode 100644
index 0000000..0a8c1e6
--- /dev/null
+++ b/src/backend/drivers/cswordbookmoduleinfo.cpp
@@ -0,0 +1,68 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//BibleTime includes
+#include "cswordbookmoduleinfo.h"
+#include "backend/keys/cswordtreekey.h"
+
+//Sword includes
+#include <treekeyidx.h>
+#include <treekey.h>
+
+CSwordBookModuleInfo::CSwordBookModuleInfo( sword::SWModule* module, CSwordBackend* const usedBackend )
+: CSwordModuleInfo(module, usedBackend),
+m_depth(-1) {}
+
+CSwordBookModuleInfo::CSwordBookModuleInfo( const CSwordBookModuleInfo& module )
+: CSwordModuleInfo(module) {
+ m_depth = module.m_depth;
+}
+
+CSwordBookModuleInfo::~CSwordBookModuleInfo() {}
+
+int CSwordBookModuleInfo::depth() {
+ if (m_depth == -1) {
+ sword::TreeKeyIdx* key = tree();
+
+ if (key) {
+ key->root();
+ computeDepth(key, 0);
+ }
+ }
+
+ return m_depth;
+}
+
+void CSwordBookModuleInfo::computeDepth(sword::TreeKeyIdx* key, int level ) {
+ std::string savedKey;
+ // savedKey = key->getFullName(); //sword 1.5.8
+ savedKey = key->getText();
+
+ if (level > m_depth) {
+ m_depth = level;
+ }
+
+ if (key->hasChildren()) {
+ key->firstChild();
+ computeDepth(key, level+1);
+
+ key->setText( savedKey.c_str() );//return to the initial value
+ }
+
+ if (key->nextSibling()) {
+ computeDepth(key, level);
+ }
+}
+
+/** Returns a treekey filled with the structure of this module */
+sword::TreeKeyIdx* CSwordBookModuleInfo::tree() const {
+ sword::TreeKeyIdx* treeKey = dynamic_cast<sword::TreeKeyIdx*>((sword::SWKey*)*(module()));
+ Q_ASSERT(treeKey);
+ return treeKey;
+}
diff --git a/src/backend/drivers/cswordbookmoduleinfo.h b/src/backend/drivers/cswordbookmoduleinfo.h
new file mode 100644
index 0000000..f471d61
--- /dev/null
+++ b/src/backend/drivers/cswordbookmoduleinfo.h
@@ -0,0 +1,64 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CSWORDGENBOOKMODULEINFO_H
+#define CSWORDGENBOOKMODULEINFO_H
+
+#include "cswordmoduleinfo.h"
+
+//Sword
+#include <treekeyidx.h>
+
+/** Class for generic book support
+ * @author The BibleTime team
+ */
+
+class CSwordBookModuleInfo : public CSwordModuleInfo {
+
+public:
+ /** Constructor.
+ * @param module The module which belongs to this object
+ * @param backend The parent backend for this book module.
+ */
+ CSwordBookModuleInfo( sword::SWModule* module, CSwordBackend* const backend );
+ /** Copy constructor.
+ * Copy constructor to copy the passed parameter.
+ * @param module The module which should be copied.
+ */
+ CSwordBookModuleInfo( const CSwordBookModuleInfo& module );
+ /** Destructor.
+ */
+ ~CSwordBookModuleInfo();
+ /**
+ * Returns the type of the module.
+ */
+ virtual CSwordModuleInfo::ModuleType type() const;
+ /**
+ * Returns the maximal depth of sections and subsections.
+ */
+ int depth();
+ /**
+ * @return A treekey filled with the structure of this module. Don't delete the returned key because it's casted from the module object.
+ */
+ sword::TreeKeyIdx* tree() const;
+
+private:
+ /**
+ * A recursive helper function to help computng the module depth!
+ */
+ void computeDepth(sword::TreeKeyIdx* key, int level = 0 );
+ int m_depth;
+};
+
+inline CSwordBookModuleInfo::ModuleType CSwordBookModuleInfo::type() const {
+ return CSwordModuleInfo::GenericBook;
+}
+
+
+#endif
diff --git a/src/backend/drivers/cswordcommentarymoduleinfo.cpp b/src/backend/drivers/cswordcommentarymoduleinfo.cpp
new file mode 100644
index 0000000..b09e2f3
--- /dev/null
+++ b/src/backend/drivers/cswordcommentarymoduleinfo.cpp
@@ -0,0 +1,32 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cswordcommentarymoduleinfo.h"
+
+CSwordCommentaryModuleInfo::CSwordCommentaryModuleInfo( sword::SWModule* module, CSwordBackend* const usedBackend)
+: CSwordBibleModuleInfo(module, usedBackend) {}
+
+CSwordCommentaryModuleInfo::~CSwordCommentaryModuleInfo() {}
+
+/** No descriptions */
+CSwordModuleInfo* CSwordCommentaryModuleInfo::clone() {
+ return new CSwordCommentaryModuleInfo(*this);
+}
+
+/** Returns true if this module may be written by the write display windows. */
+bool CSwordCommentaryModuleInfo::isWritable() const {
+ // qWarning(module()->getConfigEntry("ModDrv"));
+ //a module is only writable if it's a RawFiles module with writable returning true
+
+ if ( (std::string(module()->getConfigEntry("ModDrv")) == std::string("RawFiles")) && module()->isWritable()) {
+ return true;
+ };
+
+ return false;
+}
diff --git a/src/backend/drivers/cswordcommentarymoduleinfo.h b/src/backend/drivers/cswordcommentarymoduleinfo.h
new file mode 100644
index 0000000..7ebf23f
--- /dev/null
+++ b/src/backend/drivers/cswordcommentarymoduleinfo.h
@@ -0,0 +1,43 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CSWORDCOMMENTARYMODULEINFO_H
+#define CSWORDCOMMENTARYMODULEINFO_H
+
+//own includes
+#include "cswordbiblemoduleinfo.h"
+
+/** Commentary module implementation.
+ * This CSwordModule implementation provides access to Sword's commentary modules.
+ * @author The BibleTime team
+ * @version $Id: cswordcommentarymoduleinfo.h,v 1.13 2006/02/25 11:38:15 joachim Exp $
+ */
+
+class CSwordCommentaryModuleInfo : public CSwordBibleModuleInfo {
+
+public:
+ CSwordCommentaryModuleInfo( sword::SWModule* module, CSwordBackend* const );
+ ~CSwordCommentaryModuleInfo();
+ /** Reimplementation to return the commentary type.
+ */
+ virtual CSwordModuleInfo::ModuleType type() const;
+ /** Reimplementation to clone the current object.
+ */
+ virtual CSwordModuleInfo* clone();
+ /**
+ * Returns true if this module may be written by the write display windows.
+ */
+ virtual bool isWritable() const;
+};
+
+inline CSwordModuleInfo::ModuleType CSwordCommentaryModuleInfo::type() const {
+ return CSwordModuleInfo::Commentary;
+}
+
+#endif
diff --git a/src/backend/drivers/cswordlexiconmoduleinfo.cpp b/src/backend/drivers/cswordlexiconmoduleinfo.cpp
new file mode 100644
index 0000000..a8b81e4
--- /dev/null
+++ b/src/backend/drivers/cswordlexiconmoduleinfo.cpp
@@ -0,0 +1,170 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cswordlexiconmoduleinfo.h"
+#include "util/directoryutil.h"
+
+//Qt
+#include <QFile>
+#include <QDataStream>
+#include <QTextCodec>
+
+//Sword
+#include <swmodule.h>
+
+//STL includes
+#include <algorithm>
+
+//Change it once the format changed to make all systems rebuild their caches
+#define CACHE_FORMAT "2"
+
+CSwordLexiconModuleInfo::CSwordLexiconModuleInfo( sword::SWModule* module, CSwordBackend* const backend ) : CSwordModuleInfo(module, backend) {
+ m_entryList = 0;
+}
+
+CSwordLexiconModuleInfo::CSwordLexiconModuleInfo( const CSwordLexiconModuleInfo& m ) : CSwordModuleInfo(m) {
+ delete m_entryList;
+ m_entryList = 0;
+
+ if (m.m_entryList) {
+ m_entryList = new QStringList();
+ *m_entryList = *m.m_entryList;//copy list items
+ }
+}
+
+CSwordLexiconModuleInfo::~CSwordLexiconModuleInfo() {
+ delete m_entryList;
+ m_entryList = 0;
+}
+
+/** Returns the entries of the module. */
+QStringList* CSwordLexiconModuleInfo::entries() {
+ if (!module()) {
+ return 0;
+ }
+
+ sword::SWModule* my_module = module();
+ bool is_unicode = isUnicode();
+
+ if (!m_entryList) {
+ m_entryList = new QStringList();
+ bool read = false;
+
+ //Check for buggy modules! They will not be loaded any more.
+
+ if ( name() == QString("ZhEnglish")) {
+ qWarning("Module ZhEnglish is buggy and will not be loaded.");
+ return m_entryList;
+ }
+
+ QString dir(util::filesystem::DirectoryUtil::getUserCacheDir().absolutePath());
+ QFile f1(
+ QString(dir)
+ .append("/")
+ .append(name())
+ );
+
+ if ( f1.open( QIODevice::ReadOnly ) ) {
+ QDataStream s( &f1 );
+ QString mod_ver, prog_ver;
+ s >> mod_ver;
+ s >> prog_ver;
+
+ if ((mod_ver == config(ModuleVersion)) && (prog_ver == CACHE_FORMAT)) {
+ s >> *m_entryList;
+ read = true;
+ }
+
+ f1.close();
+ // qWarning("read entries %d",m_entryList->count());
+ }
+
+ // Q_ASSERT(read);
+ // Q_ASSERT(m_entryList->count());
+ if (!read || !m_entryList->count()) {
+ my_module->setSkipConsecutiveLinks(true);
+ (*my_module) = sword::TOP;
+ snap(); //snap to top entry
+
+ // qWarning("Reading in module" );
+ int i = 0;
+
+ do {
+ if ( is_unicode ) {
+ m_entryList->append(QString::fromUtf8(my_module->KeyText()));
+ // qWarning("Entry: %s", my_module->KeyText() );
+ }
+ else { //for latin1 modules use fromLatin1 because of speed
+ // m_entryList->append(QString::fromLatin1(my_module->KeyText()));
+ QTextCodec* codec = QTextCodec::codecForName("Windows-1252");
+ m_entryList->append(codec->toUnicode(my_module->KeyText()));
+ }
+
+ (*my_module)++;
+ i++;
+ }
+ while ( !my_module->Error() );
+
+ // qWarning("Reading finished. Module has %d entries.", i );
+
+ (*my_module) = sword::TOP; //back to the first entry
+
+ my_module->setSkipConsecutiveLinks(false);
+
+ if (m_entryList->count()) {
+ m_entryList->first().simplified();
+
+ if (m_entryList->first().trimmed().isEmpty()) {
+ m_entryList->erase( m_entryList->begin() );
+ }
+
+ //now sort the list, this is necesssary because Sword doesn't do Unicode ordering
+ // qWarning("sorting");
+ // QStringList::iterator start(m_entryList->begin());
+ // QStringList::iterator end(m_entryList->end());
+ // std::sort( start, end, myLocaleAwareCompare() ); //stl sort
+ // m_entryList->sort(); //make sure the module is sorted by utf-8
+ }
+
+ qWarning("Writing cache file.");
+
+ if (m_entryList->count()) {
+ //create cache
+ QString dir = util::filesystem::DirectoryUtil::getUserCacheDir().absolutePath();
+ //QFile f2( QString::fromLatin1("%1/%2").arg(dir).arg( name() ) );
+ QFile f2( QString(dir).append("/").append(name()) );
+
+
+ if (f2.open( QIODevice::WriteOnly )) {
+ QDataStream s( &f2 );
+ s << config(CSwordModuleInfo::ModuleVersion); //store module version
+ s << QString(CACHE_FORMAT); //store BT version -- format may change
+ s << *m_entryList;
+ f2.close();
+ }
+ }
+ }
+ }
+
+ return m_entryList;
+}
+
+/** Jumps to the closest entry in the module. */
+bool CSwordLexiconModuleInfo::snap() {
+ if(module()->getRawEntry()) { // Snap to the current entry
+ return true;
+ }
+
+ return false;
+}
+
+/** No descriptions */
+CSwordModuleInfo* CSwordLexiconModuleInfo::clone() {
+ return new CSwordLexiconModuleInfo(*this);
+}
diff --git a/src/backend/drivers/cswordlexiconmoduleinfo.h b/src/backend/drivers/cswordlexiconmoduleinfo.h
new file mode 100644
index 0000000..13f72e4
--- /dev/null
+++ b/src/backend/drivers/cswordlexiconmoduleinfo.h
@@ -0,0 +1,71 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CSWORDLEXICONMODULEINFO_H
+#define CSWORDLEXICONMODULEINFO_H
+
+//own includes
+#include "cswordmoduleinfo.h"
+
+//Qt includes
+#include <QStringList>
+
+/**
+ * The implementation of CModuleInfo for the Sword lexiccons and citionaries.
+ * @author The BibleTime team
+ * @version $Id: cswordlexiconmoduleinfo.h,v 1.12 2006/02/25 11:38:15 joachim Exp $
+ */
+
+class CSwordLexiconModuleInfo : public CSwordModuleInfo {
+
+public:
+ /**
+ * The standard constructor fot this object.
+ * A default constructor doesn't exist. Use this one.
+ */
+ CSwordLexiconModuleInfo( sword::SWModule* module, CSwordBackend* const );
+ /**
+ * The copy constructor
+ */
+ CSwordLexiconModuleInfo( const CSwordLexiconModuleInfo& m );
+ /** Reimplementation to return a valid clone.
+ */
+ virtual CSwordModuleInfo* clone();
+ /** Destructor.
+ */
+ virtual ~CSwordLexiconModuleInfo();
+ /**
+ * Returns the entries of the module.
+ * This function returns the entries of the modules represented by this object.
+ * If this function is called for the first time the list is load from disk and stored in a list which cahes it.
+ * If the function is called again, the cached list is returned so we have a major speed improvement.
+ * @return The list of lexicon entries
+ */
+ QStringList* entries();
+ /**
+ * Reimplementation, to return the right type for this lexicon.
+ */
+ virtual CSwordModuleInfo::ModuleType type() const;
+ /**
+ * Jumps to the closest entry in the module.
+ */
+ bool snap();
+
+private:
+ /**
+ * This is the list which caches the entres of the module.
+ */
+ QStringList* m_entryList;
+};
+
+inline CSwordModuleInfo::ModuleType CSwordLexiconModuleInfo::type() const {
+ return CSwordModuleInfo::Lexicon;
+}
+
+#endif
diff --git a/src/backend/drivers/cswordmoduleinfo.cpp b/src/backend/drivers/cswordmoduleinfo.cpp
new file mode 100644
index 0000000..c76f5ef
--- /dev/null
+++ b/src/backend/drivers/cswordmoduleinfo.cpp
@@ -0,0 +1,955 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//BibleTime includes
+#include "cswordmoduleinfo.h"
+#include "cswordlexiconmoduleinfo.h"
+
+#include "backend/managers/cswordbackend.h"
+#include "backend/cswordmodulesearch.h"
+#include "backend/keys/cswordkey.h"
+#include "backend/rendering/centrydisplay.h"
+#include "backend/managers/clanguagemgr.h"
+
+#include "util/directoryutil.h"
+#include "util/cpointers.h"
+#include "util/exceptions.h"
+#include "backend/config/cbtconfig.h"
+
+
+#include <boost/scoped_ptr.hpp>
+
+//Qt includes
+#include <QRegExp>
+#include <QDir>
+#include <QFileInfo>
+#include <QList>
+#include <QByteArray>
+#include <QDebug>
+#include <QSettings>
+#include <QMessageBox>
+#include <QCoreApplication>
+
+//Sword includes
+#include <swbuf.h>
+#include <swkey.h>
+#include <listkey.h>
+#include <versekey.h>
+#include <swconfig.h>
+#include <rtfhtml.h>
+
+//Lucence includes
+#include <CLucene.h>
+#include <CLucene/util/Reader.h>
+#include <CLucene/util/Misc.h>
+#include <CLucene/util/dirent.h>
+
+
+//Increment this, if the index format changes
+//Then indices on the user's systems will be rebuilt
+const unsigned int INDEX_VERSION = 6;
+
+//Maximum index entry size, 1MiB for now
+//Lucene default is too small
+const unsigned long BT_MAX_LUCENE_FIELD_LENGTH = 1024*1024;
+
+CSwordModuleInfo::CSwordModuleInfo(sword::SWModule * module, CSwordBackend * const usedBackend) {
+ m_module = module;
+ Q_ASSERT(module);
+
+ m_hidden = false;
+ m_cancelIndexing = false;
+ m_searchResult.ClearList();
+ m_backend = usedBackend ? usedBackend : CPointers::backend();
+ m_dataCache.name = module ? QString(module->Name()) : QString::null;
+ m_dataCache.isUnicode = module ? module->isUnicode() : false;
+ m_dataCache.category = UnknownCategory;
+ m_dataCache.language = 0;
+ m_dataCache.hasVersion = !QString((*m_backend->getConfig())[module->Name()]["Version"]).isEmpty();
+
+ if (backend()) {
+ if (hasVersion() && (minimumSwordVersion() > sword::SWVersion::currentVersion)) {
+ qWarning("The module \"%s\" requires a newer Sword library. Please update to \"Sword %s\".",
+ name().toUtf8().constData(), (const char *)minimumSwordVersion());
+ }
+ }
+}
+
+CSwordModuleInfo::CSwordModuleInfo(const CSwordModuleInfo & m) : QObject(){
+ m_module = m.m_module;
+ m_backend = m.m_backend;
+ m_dataCache = m.m_dataCache;
+ m_searchResult = m.m_searchResult;
+ m_hidden = m.m_hidden;
+ m_cancelIndexing = m.m_cancelIndexing;
+}
+
+/** No descriptions */
+CSwordModuleInfo *CSwordModuleInfo::clone() {
+ return new CSwordModuleInfo(*this);
+}
+
+CSwordModuleInfo::~CSwordModuleInfo() {
+ m_searchResult.ClearList();
+ m_module = 0; //the Sword module object is deleted by the backend
+}
+
+/** Sets the unlock key of the modules and writes the key into the cofig file.*/
+bool CSwordModuleInfo::unlock(const QString & unlockKey) {
+ if (!isEncrypted()) {
+ return false;
+ }
+
+ CBTConfig::setModuleEncryptionKey(name(), unlockKey);
+ backend()->setCipherKey(m_module->Name(), unlockKey.toUtf8().constData());
+ //TODO: write to Sword config as well
+
+ return true;
+}
+
+/** This function returns true if this module is locked, otherwise return false. */
+bool CSwordModuleInfo::isLocked() {
+ //still works, but the cipherkey is stored in CBTConfig.
+ //Works because it is set in sword on program startup.
+
+ if (isEncrypted()) {
+ if (unlockKeyIsValid()) {
+ return false;
+ }
+ return true;
+ }
+ return false;
+}
+
+/** This functions returns true if this module is encrypted (locked or unlocked). */
+bool CSwordModuleInfo::isEncrypted() const {
+ /**
+ * If we have the CipherKey entry the module
+ * is encrypted but not necessarily locked
+ */
+
+ //This code is still right, though we do no longer write to the module config files any more
+ sword::ConfigEntMap config = backend()->getConfig()->Sections.find(name().toUtf8().constData())->second;
+ sword::ConfigEntMap::iterator it = config.find("CipherKey");
+
+ if (it != config.end()) {
+ return true;
+ }
+
+ return false;
+}
+
+/** This function makes an estimate if a module was properly unlocked.
+* It returns true if the first entry of the module is not empty and
+* contains only printable characters (for the first 100 chars or so).
+* If that is the case, we can safely assume that a) the module was properly
+* unlocked and b) no buffer overflows will occur, which can happen when
+* Sword filters process garbage text which was not properly decrypted.
+*/
+bool CSwordModuleInfo::unlockKeyIsValid() {
+
+ (*m_module) = sword::TOP;
+
+ // This needs to use ::fromLatin1 because if the text is still locked,
+ // a lot of garbage will show up. It will also work with properly decrypted
+ // Unicode text, because all non-ASCII Unicode chars consist of bytes >127
+ // and therefore contain no control (nonprintable) characters, which are all <127.
+ QString test = isUnicode()
+ ? QString::fromUtf8(m_module->getRawEntryBuf().c_str())
+ : QString::fromLatin1( m_module->getRawEntryBuf().c_str() );
+
+ if (test.isEmpty()) {
+ qWarning() << "Unlock key of module" << name() << "is NOT valid!";
+ return false;
+ }
+
+ for (int i = 0; i <= test.length() && i < 100; i++) {
+ if ( !test[i].isPrint() && !test[i].isNull() ) {
+ qWarning() << "Unlock key of module" << name() << "is NOT valid!";
+ return false;
+ }
+ }
+
+ qDebug() << "Unlock key of module" << name() << "is valid";
+ return true;
+}
+
+QString CSwordModuleInfo::getGlobalBaseIndexLocation() {
+ return util::filesystem::DirectoryUtil::getUserIndexDir().absolutePath();
+}
+
+QString CSwordModuleInfo::getModuleBaseIndexLocation() const {
+ return getGlobalBaseIndexLocation() + QString("/") + name().toLocal8Bit();
+}
+
+QString CSwordModuleInfo::getModuleStandardIndexLocation() const { //this for now returns the location of the main index
+ return getModuleBaseIndexLocation() + QString("/standard");
+}
+
+bool CSwordModuleInfo::hasIndex() {
+ //this will return true only
+ //if the index exists and has correct version information for both index and module
+ QDir d;
+ if (!d.exists( getModuleStandardIndexLocation() )) {
+ return false;
+ }
+
+ //first check if the index version and module version are ok
+ QSettings module_config(getModuleBaseIndexLocation() + QString("/bibletime-index.conf"), QSettings::IniFormat);
+
+ if (hasVersion()) {
+ if (module_config.value("module-version") != QString(config(CSwordModuleInfo::ModuleVersion)) ) {
+ return false;
+ }
+ }
+ if (module_config.value("index-version") != QString::number( INDEX_VERSION )) {
+ qDebug("%s: INDEX_VERSION is not compatible with this version of BibleTime.", name().toUtf8().constData());
+ return false;
+ }
+
+ //then check if the index is there
+ return lucene::index::IndexReader::indexExists(getModuleStandardIndexLocation().toAscii().constData());
+}
+
+
+void CSwordModuleInfo::buildIndex() {
+
+ m_cancelIndexing = false;
+
+ try
+ {
+ //Without this we don't get strongs, lemmas, etc
+ backend()->setFilterOptions ( CBTConfig::getFilterOptionDefaults() );
+ //make sure we reset all important filter options which influcence the plain filters.
+ backend()->setOption( CSwordModuleInfo::strongNumbers, false );
+ backend()->setOption( CSwordModuleInfo::morphTags, false );
+ backend()->setOption( CSwordModuleInfo::morphSegmentation, false );
+ backend()->setOption( CSwordModuleInfo::footnotes, false );
+ backend()->setOption( CSwordModuleInfo::headings, false );
+ backend()->setOption( CSwordModuleInfo::scriptureReferences, false );
+ backend()->setOption( CSwordModuleInfo::redLetterWords, false );
+
+ // do not use any stop words
+ const TCHAR* stop_words[] = { NULL };
+ lucene::analysis::standard::StandardAnalyzer an( (const TCHAR**)stop_words );
+ QString index = getModuleStandardIndexLocation();
+
+ QDir dir("/");
+ dir.mkpath( getGlobalBaseIndexLocation() );
+ dir.mkpath( getModuleBaseIndexLocation() );
+ dir.mkpath( getModuleStandardIndexLocation() );
+
+ if (lucene::index::IndexReader::indexExists(index.toAscii().constData())) {
+ if (lucene::index::IndexReader::isLocked(index.toAscii().constData()) ) {
+ lucene::index::IndexReader::unlock(index.toAscii().constData());
+ }
+ }
+
+ boost::scoped_ptr<lucene::index::IndexWriter> writer( new lucene::index::IndexWriter(index.toAscii().constData(), &an, true) ); //always create a new index
+ writer->setMaxFieldLength(BT_MAX_LUCENE_FIELD_LENGTH);
+ writer->setUseCompoundFile(true); //merge segments into a single file
+ writer->setMinMergeDocs(1000);
+
+ *m_module = sword::TOP;
+ unsigned long verseLowIndex = m_module->Index();
+ *m_module = sword::BOTTOM;
+ unsigned long verseHighIndex = m_module->Index();
+
+ //verseLowIndex is not 0 in all cases (i.e. NT-only modules)
+ unsigned long verseIndex = verseLowIndex + 1;
+ unsigned long verseSpan = verseHighIndex - verseLowIndex;
+
+ //Index() is not implemented properly for lexicons, so we use a
+ //workaround.
+ if (type() == CSwordModuleInfo::Lexicon){
+ verseIndex = 0;
+ verseLowIndex = 0;
+ verseSpan = ((CSwordLexiconModuleInfo*)this)->entries()->size();
+ }
+
+ emit indexingProgress(0);
+
+ sword::SWKey* key = m_module->getKey();
+ //VerseKey for bibles
+ sword::VerseKey* vk = dynamic_cast<sword::VerseKey*>(key);
+
+ if (vk) {
+ // we have to be sure to insert the english key into the index, otherwise we'd be in trouble if the language changes
+ vk->setLocale("en_US");
+ //If we have a verse based module, we want to include the pre-chapter etc. headings in the search
+ vk->Headings(1);
+ }
+
+ //holds UTF-8 data and is faster than QString.
+ QByteArray textBuffer;
+
+ // we start with the first module entry, key is automatically updated
+ // because key is a pointer to the modules key
+ m_module->setSkipConsecutiveLinks(true);
+
+ wchar_t wcharBuffer[BT_MAX_LUCENE_FIELD_LENGTH + 1];
+
+ for (*m_module = sword::TOP; !(m_module->Error()) && !m_cancelIndexing; (*m_module)++) {
+
+ //If it is a sword-heading, store in buffer and index later in Verse X:1
+ if (vk) {
+ if (vk->Verse() == 0) {
+ textBuffer.append( m_module->StripText() );
+ continue;
+ }
+ }
+
+ boost::scoped_ptr<lucene::document::Document> doc(new lucene::document::Document());
+
+ //index the key
+ lucene_utf8towcs(wcharBuffer, key->getText(), BT_MAX_LUCENE_FIELD_LENGTH);
+ //doc->add(*lucene::document::Field::UnIndexed((const TCHAR*)_T("key"), (const TCHAR*)wcharBuffer));
+ doc->add(*(new lucene::document::Field((const TCHAR*)_T("key"), (const TCHAR*)wcharBuffer, lucene::document::Field::STORE_YES | lucene::document::Field::INDEX_NO)));
+ // index the main text
+ //at this point we have to make sure we disabled the strongs and the other options
+ //so the plain filters won't include the numbers somehow.
+ lucene_utf8towcs(wcharBuffer, (const char*) textBuffer.append(m_module->StripText()), BT_MAX_LUCENE_FIELD_LENGTH);
+ //doc->add(*lucene::document::Field::UnStored((const TCHAR*)_T("content"), (const TCHAR*)wcharBuffer));
+ doc->add(*(new lucene::document::Field((const TCHAR*)_T("content"), (const TCHAR*)wcharBuffer, lucene::document::Field::STORE_NO | lucene::document::Field::INDEX_TOKENIZED)));
+ textBuffer.resize(0); //clean up
+
+ // index attributes
+ sword::AttributeList::iterator attListI;
+ sword::AttributeValue::iterator attValueI;
+ // Footnotes
+ for (attListI = m_module->getEntryAttributes()["Footnote"].begin();
+ attListI != m_module->getEntryAttributes()["Footnote"].end();
+ attListI++) {
+ lucene_utf8towcs(wcharBuffer, attListI->second["body"], BT_MAX_LUCENE_FIELD_LENGTH);
+ //doc->add(*lucene::document::Field::UnStored((const TCHAR*)_T("footnote"), wcharBuffer));
+ doc->add(*(new lucene::document::Field((const TCHAR*)_T("footnote"), (const TCHAR*)wcharBuffer, lucene::document::Field::STORE_NO | lucene::document::Field::INDEX_TOKENIZED)));
+ } // for attListI
+
+ // Headings
+ for (attValueI = m_module->getEntryAttributes()["Heading"]["Preverse"].begin();
+ attValueI != m_module->getEntryAttributes()["Heading"]["Preverse"].end();
+ attValueI++) {
+ lucene_utf8towcs(wcharBuffer, attValueI->second, BT_MAX_LUCENE_FIELD_LENGTH);
+ //doc->add(*lucene::document::Field::UnStored((const TCHAR*)_T("heading"), wcharBuffer));
+ doc->add(*(new lucene::document::Field((const TCHAR*)_T("heading"), (const TCHAR*)wcharBuffer, lucene::document::Field::STORE_NO | lucene::document::Field::INDEX_TOKENIZED)));
+ } // for attValueI
+
+ // Strongs/Morphs
+ for (attListI = m_module->getEntryAttributes()["Word"].begin();
+ attListI != m_module->getEntryAttributes()["Word"].end();
+ attListI++) {
+ // for each attribute
+ if (attListI->second["LemmaClass"] == "strong") {
+ lucene_utf8towcs(wcharBuffer, attListI->second["Lemma"], BT_MAX_LUCENE_FIELD_LENGTH);
+ //doc->add(*lucene::document::Field::UnStored((const TCHAR*)_T("strong"), wcharBuffer));
+ doc->add(*(new lucene::document::Field((const TCHAR*)_T("strong"), (const TCHAR*)wcharBuffer, lucene::document::Field::STORE_NO | lucene::document::Field::INDEX_TOKENIZED)));
+ //qWarning("Adding strong %s", attListI->second["Lemma"].c_str());
+ }
+ if (attListI->second.find("Morph") != attListI->second.end()) {
+ lucene_utf8towcs(wcharBuffer, attListI->second["Morph"], BT_MAX_LUCENE_FIELD_LENGTH);
+ //doc->add(*lucene::document::Field::UnStored((const TCHAR*)_T("morph"), wcharBuffer));
+ doc->add(*(new lucene::document::Field((const TCHAR*)_T("morph"), (const TCHAR*)wcharBuffer, lucene::document::Field::STORE_NO | lucene::document::Field::INDEX_TOKENIZED)));
+ }
+ } // for attListI
+
+ writer->addDocument(doc.get());
+ //Index() is not implemented properly for lexicons, so we use a
+ //workaround.
+ if (type() == CSwordModuleInfo::Lexicon){
+ verseIndex++;
+ }
+ else{
+ verseIndex = m_module->Index();
+ }
+
+ if (verseIndex % 200 == 0) {
+ int indexingProgressValue;
+ if (verseSpan == 0) { //prevent division by zero
+ //m_indexingProgress.setValue( QVariant(0) );
+ indexingProgressValue = 0;
+ } else {
+ //m_indexingProgress.setValue( QVariant((int)((100*(verseIndex-verseLowIndex))/(verseHighIndex-verseLowIndex))) );
+ indexingProgressValue = (int)((100*(verseIndex-verseLowIndex)) / (verseSpan));
+ }
+ //m_indexingProgress.activate();
+ emit indexingProgress(indexingProgressValue);
+ }
+ }
+
+ if (!m_cancelIndexing)
+ {
+ writer->optimize();
+ }
+ writer->close();
+
+ if (m_cancelIndexing){
+ deleteIndexForModule(name());
+ m_cancelIndexing = false;
+ }
+ else
+ {
+ QSettings module_config(getModuleBaseIndexLocation() + QString("/bibletime-index.conf"), QSettings::IniFormat);
+ if (hasVersion()) module_config.setValue("module-version", config(CSwordModuleInfo::ModuleVersion) );
+ module_config.setValue("index-version", INDEX_VERSION );
+ }
+ }
+ catch(...)
+ {
+ qWarning("CLucene exception occurred while indexing");
+ QMessageBox::warning(0, QCoreApplication::tr("Indexing aborted"), QCoreApplication::tr("An internal error occurred while building the index."));
+ deleteIndexForModule(name());
+ m_cancelIndexing = false;
+ }
+}
+
+void CSwordModuleInfo::deleteIndexForModule( QString name ) {
+ util::filesystem::DirectoryUtil::removeRecursive( getGlobalBaseIndexLocation() + "/" + name );
+}
+
+unsigned long CSwordModuleInfo::indexSize() const {
+ return util::filesystem::DirectoryUtil::getDirSizeRecursive( getModuleBaseIndexLocation() );
+}
+
+
+bool CSwordModuleInfo::searchIndexed(const QString& searchedText, sword::ListKey& scope) {
+ char utfBuffer[BT_MAX_LUCENE_FIELD_LENGTH + 1];
+ wchar_t wcharBuffer[BT_MAX_LUCENE_FIELD_LENGTH + 1];
+
+ // work around Swords thread insafety for Bibles and Commentaries
+ boost::scoped_ptr < CSwordKey > key(CSwordKey::createInstance(this));
+ sword::SWKey* s = dynamic_cast < sword::SWKey * >(key.get());
+ QList<sword::VerseKey*> list;
+
+ if (s) {
+ m_module->SetKey(*s);
+ }
+
+ m_searchResult.ClearList();
+
+ try {
+ // do not use any stop words
+ const TCHAR* stop_words[] = { NULL };
+ lucene::analysis::standard::StandardAnalyzer analyzer( stop_words );
+ lucene::search::IndexSearcher searcher(getModuleStandardIndexLocation().toAscii().constData());
+ lucene_utf8towcs(wcharBuffer, searchedText.toUtf8().constData(), BT_MAX_LUCENE_FIELD_LENGTH);
+ boost::scoped_ptr<lucene::search::Query> q( lucene::queryParser::QueryParser::parse((const TCHAR*)wcharBuffer, (const TCHAR*)_T("content"), &analyzer) );
+
+ boost::scoped_ptr<lucene::search::Hits> h( searcher.search(q.get(), lucene::search::Sort::INDEXORDER) );
+
+ const bool useScope = (scope.Count() > 0);
+// const bool isVerseModule = (type() == CSwordModuleInfo::Bible) || (type() == CSwordModuleInfo::Commentary);
+
+ lucene::document::Document* doc = 0;
+ boost::scoped_ptr<sword::SWKey> swKey( module()->CreateKey() );
+
+
+ for (int i = 0; i < h->length(); ++i) {
+ doc = &h->doc(i);
+ lucene_wcstoutf8(utfBuffer, (const wchar_t*)doc->get((const TCHAR*)_T("key")), BT_MAX_LUCENE_FIELD_LENGTH);
+
+ swKey->setText(utfBuffer);
+
+ // limit results based on scope
+ //if (searchOptions & CSwordModuleSearch::useScope && scope.Count() > 0){
+ if (useScope) {
+ for (int j = 0; j < scope.Count(); j++) {
+ sword::VerseKey* vkey = dynamic_cast<sword::VerseKey*>(scope.getElement(j));
+ if (vkey->LowerBound().compare(*swKey) <= 0 && vkey->UpperBound().compare(*swKey) >= 0) {
+ m_searchResult.add(*swKey);
+ }
+ }
+ } else { // no scope, give me all buffers
+ m_searchResult.add(*swKey);
+ }
+ }
+ }
+ catch (...) {
+ qWarning("CLucene exception occurred");
+ QMessageBox::warning(0, QCoreApplication::tr("Search aborted"), QCoreApplication::tr("An internal error occurred while executing your search."));
+ return false;
+ }
+
+ qDeleteAll(list);
+ list.clear();
+
+ return (m_searchResult.Count() > 0);
+}
+
+/** Returns the last search result for this module. */
+sword::ListKey & CSwordModuleInfo::searchResult(const sword::ListKey * newResult) {
+ if (newResult) {
+ m_searchResult.copyFrom(*newResult);
+ }
+
+ return m_searchResult;
+}
+
+/** Clears the last search result. */
+void CSwordModuleInfo::clearSearchResult() {
+ m_searchResult.ClearList();
+}
+
+/** Returns the required Sword version for this module. Returns -1 if no special Sword version is required. */
+sword::SWVersion CSwordModuleInfo::minimumSwordVersion() {
+ return sword::SWVersion(config(CSwordModuleInfo::MinimumSwordVersion).toUtf8().constData());
+}
+
+QString CSwordModuleInfo::config(const CSwordModuleInfo::ConfigEntry entry) const {
+ switch (entry) {
+
+ case AboutInformation:
+ return getFormattedConfigEntry("About");
+
+ case CipherKey: {
+ if (CBTConfig::getModuleEncryptionKey(name()).isNull()) { //fall back!
+ return QString(m_module->getConfigEntry("CipherKey"));
+ }
+ else {
+ return CBTConfig::getModuleEncryptionKey(name());
+ }
+ }
+
+ case AbsoluteDataPath: {
+ QString path( getSimpleConfigEntry("AbsoluteDataPath") );
+ path.replace(QRegExp("/./"), "/"); // make /abs/path/./modules/ looking better
+ //make sure we have a trailing slash!
+
+ if (path.right(1) != "/") {
+ path.append('/');
+ }
+
+ return path;
+ }
+
+ case DataPath: { //make sure we remove the dataFile part if it's a Lexicon
+ QString path(getSimpleConfigEntry("DataPath"));
+
+ if ((type() == CSwordModuleInfo::GenericBook) || (type() == CSwordModuleInfo::Lexicon)) {
+ int pos = path.lastIndexOf("/"); //last slash in the string
+
+ if (pos != -1) {
+ path = path.left(pos + 1); //include the slash
+ }
+ }
+
+ return path;
+ }
+
+ case Description:
+ return getFormattedConfigEntry("Description");
+
+ case ModuleVersion: {
+ QString version(getSimpleConfigEntry("Version"));
+
+ if (version.isEmpty()) {
+ version = "1.0";
+ }
+
+ return version;
+ }
+
+ case MinimumSwordVersion: {
+ const QString minimumVersion(getSimpleConfigEntry("MinimumVersion"));
+ return !minimumVersion.isEmpty()? minimumVersion : QString("0.0");
+ }
+
+ case TextDir: {
+ const QString dir(getSimpleConfigEntry("Direction"));
+ return !dir.isEmpty()? dir : QString("LtoR");
+ }
+
+ case DisplayLevel: {
+ const QString level(getSimpleConfigEntry("DisplayLevel"));
+ return !level.isEmpty()? level : QString("1");
+ }
+
+ case GlossaryFrom: {
+ if (!category() == Glossary) {
+ return QString::null;
+ };
+
+ const QString lang(getSimpleConfigEntry("GlossaryFrom"));
+
+ return !lang.isEmpty()? lang : QString::null;
+ }
+
+ case GlossaryTo: {
+ if (!category() == Glossary) {
+ return QString::null;
+ };
+
+ const QString lang(getSimpleConfigEntry("GlossaryTo"));
+
+ return !lang.isEmpty()? lang : QString::null;
+ }
+
+ case Markup: {
+ const QString markup(getSimpleConfigEntry("SourceType"));
+ return !markup.isEmpty()? markup : QString("Unknown");
+ }
+
+ case DistributionLicense:
+ return getSimpleConfigEntry("DistributionLicense");
+
+ case DistributionSource:
+ return getSimpleConfigEntry("DistributionSource");
+
+ case DistributionNotes:
+ return getSimpleConfigEntry("DistributionNotes");
+
+ case TextSource:
+ return getSimpleConfigEntry("TextSource");
+
+ case CopyrightNotes:
+ return getSimpleConfigEntry("CopyrightNotes");
+
+ case CopyrightHolder:
+ return getSimpleConfigEntry("CopyrightHolder");
+
+ case CopyrightDate:
+ return getSimpleConfigEntry("CopyrightDate");
+
+ case CopyrightContactName:
+ return getSimpleConfigEntry("CopyrightContactName");
+
+ case CopyrightContactAddress:
+ return getSimpleConfigEntry("CopyrightContactAddress");
+
+ case CopyrightContactEmail:
+ return getSimpleConfigEntry("CopyrightContactEmail");
+
+ default:
+ return QString::null;
+ }
+}
+
+/** Returns true if the module supports the feature given as parameter. */
+bool CSwordModuleInfo::has(const CSwordModuleInfo::Feature feature) const {
+ switch (feature) {
+
+ // case StrongsNumbers:
+ // return m_module->getConfig().has("Feature", "StrongsNumber");
+
+ case GreekDef:
+ return m_module->getConfig().has("Feature", "GreekDef");
+
+ case HebrewDef:
+ return m_module->getConfig().has("Feature", "HebrewDef");
+
+ case GreekParse:
+ return m_module->getConfig().has("Feature", "GreekParse");
+
+ case HebrewParse:
+ return m_module->getConfig().has("Feature", "HebrewParse");
+ }
+
+ return false;
+}
+
+bool CSwordModuleInfo::has(const CSwordModuleInfo::FilterTypes option) const {
+ //BAD workaround to see if the filter is GBF, OSIS or ThML!
+ const QString name = backend()->configOptionName(option);
+
+ if (m_module->getConfig().has("GlobalOptionFilter", QString("OSIS").append(name).toUtf8().constData())) {
+ return true;
+ }
+
+ if (m_module->getConfig().has("GlobalOptionFilter", QString("GBF").append(name).toUtf8().constData())) {
+ return true;
+ }
+
+ if (m_module->getConfig().has("GlobalOptionFilter", QString("ThML").append(name).toUtf8().constData())) {
+ return true;
+ }
+
+ if (m_module->getConfig().has("GlobalOptionFilter", QString("UTF8").append(name).toUtf8().constData())) {
+ return true;
+ }
+
+ if (m_module->getConfig().has("GlobalOptionFilter", name.toUtf8().constData())) {
+ return true;
+ }
+
+ return false;
+}
+
+/** Returns the text direction of the module's text., */
+CSwordModuleInfo::TextDirection CSwordModuleInfo::textDirection() {
+ if (config(TextDir) == "RtoL") {
+ return CSwordModuleInfo::RightToLeft;
+ }
+ else {
+ return CSwordModuleInfo::LeftToRight;
+ }
+}
+
+/** Writes the new text at the given position into the module. This does only work for writable modules. */
+void CSwordModuleInfo::write(CSwordKey * key, const QString & newText) {
+ module()->KeyText(key->key().toUtf8().constData());
+
+ //don't store a pointer to the const char* value somewhere because QCString doesn't keep the value of it
+ module()->setEntry(isUnicode()? newText.toUtf8().constData() : newText.toLocal8Bit().constData());
+}
+
+/** Deletes the current entry and removes it from the module. */
+bool CSwordModuleInfo::deleteEntry(CSwordKey * const key) {
+ module()->KeyText(isUnicode()? key->key().toUtf8().constData() : key->key().toLocal8Bit().constData());
+
+ if (module()) {
+ module()->deleteEntry();
+ return true;
+ }
+
+ return false;
+}
+
+/** Returns the category of this module. See CSwordModuleInfo::Category for possible values. */
+CSwordModuleInfo::Category CSwordModuleInfo::category() const {
+ //qDebug("CSwordModuleInfo::category");
+ if (m_dataCache.category == CSwordModuleInfo::UnknownCategory) {
+ const QString cat(m_module->getConfigEntry("Category"));
+ //qDebug() << "the category was unknown, add a category "<< cat << "for module" << m_module->Name();
+
+ if (cat == "Cults / Unorthodox / Questionable Material") {
+ m_dataCache.category = Cult;
+ }
+ else if (cat == "Daily Devotional" || m_module->getConfig().has("Feature", "DailyDevotion")) {
+ m_dataCache.category = DailyDevotional;
+ }
+ else if (cat == "Glossaries" || m_module->getConfig().has("Feature", "Glossary")) { //allow both
+ m_dataCache.category = Glossary;
+ }
+ else if (cat == "Images" || cat == "Maps") {
+ m_dataCache.category = Images;
+ }
+ else if (type() == Commentary) {
+ m_dataCache.category = Commentaries;
+ }
+ else if (type() == Bible) {
+ m_dataCache.category = Bibles;
+ }
+ else if (type() == Lexicon) {
+ m_dataCache.category = Lexicons;
+ }
+ else if (type() == GenericBook) {
+ m_dataCache.category = Books;
+ }
+ }
+ //qDebug() << "assigned category: " << m_dataCache.category;
+ return m_dataCache.category;
+}
+
+/** Returns the display object for this module. */
+Rendering::CEntryDisplay * CSwordModuleInfo::getDisplay() const {
+ return dynamic_cast < Rendering::CEntryDisplay * >(m_module->Disp());
+}
+
+QString CSwordModuleInfo::aboutText() const {
+ QString text;
+ text += "<table>";
+
+ text += QString("<tr><td><b>%1</b></td><td>%2</td><tr>")
+ .arg(tr("Version"))
+ .arg(hasVersion()? config(CSwordModuleInfo::ModuleVersion) : tr("unknown"));
+
+ text += QString("<tr><td><b>%1</b></td><td>%2</td></tr>")
+ .arg(tr("Markup"))
+ .arg(!QString(m_module->getConfigEntry("SourceType")).isEmpty()? QString(m_module->
+ getConfigEntry("SourceType")) : tr("unknown"));
+
+ text += QString("<tr><td><b>%1</b></td><td>%2</td></tr>")
+ .arg(tr("Location"))
+ .arg(config(CSwordModuleInfo::AbsoluteDataPath));
+
+ text += QString("<tr><td><b>%1</b></td><td>%2</td></tr>")
+ .arg(tr("Language"))
+ .arg(language()->translatedName());
+
+ if (m_module->getConfigEntry("Category"))
+ text += QString("<tr><td><b>%1</b></td><td>%2</td></tr>")
+ .arg(tr("Category"))
+ .arg(m_module->getConfigEntry("Category"));
+
+ if (m_module->getConfigEntry("LCSH"))
+ text += QString("<tr><td><b>%1</b></td><td>%2</td></tr>")
+ .arg(tr("LCSH"))
+ .arg(m_module->getConfigEntry("LCSH"));
+
+ text += QString("<tr><td><b>%1</b></td><td>%2</td></tr>")
+ .arg(tr("Writable"))
+ .arg(isWritable()? tr("yes") : tr("no"));
+
+ if (isEncrypted())
+ text += QString("<tr><td><b>%1</b></td><td>%2</td></tr>")
+ .arg(tr("Unlock key"))
+ .arg(config(CSwordModuleInfo::CipherKey));
+
+ QString options;
+
+ unsigned int opts;
+
+ for (opts = CSwordModuleInfo::filterTypesMIN; opts <= CSwordModuleInfo::filterTypesMAX; ++opts) {
+ if (has(static_cast < CSwordModuleInfo::FilterTypes > (opts))) {
+ if (!options.isEmpty()) {
+ options += QString::fromLatin1(", ");
+ }
+
+ options += CSwordBackend::translatedOptionName(static_cast < CSwordModuleInfo::FilterTypes > (opts));
+ }
+ }
+
+ if (!options.isEmpty()) {
+ text += QString("<tr><td><b>%1</b></td><td>%2</td></tr>")
+ .arg(tr("Features"))
+ .arg(options);
+ }
+
+ text += "</table><hr>";
+
+ if (category() == Cult) //clearly say the module contains cult/questionable materials
+ text += QString("<br/><b>%1</b><br/><br/>")
+ .arg(tr("Take care, this work contains cult / questionable material!"));
+
+ text += QString("<b>%1:</b><br>%2</font>")
+ .arg(tr("About"))
+ .arg(config(AboutInformation));
+
+ typedef QList<CSwordModuleInfo::ConfigEntry> ListConfigEntry;
+
+ ListConfigEntry entries;
+
+ entries.append(DistributionLicense);
+
+ entries.append(DistributionSource);
+
+ entries.append(DistributionNotes);
+
+ entries.append(TextSource);
+
+ entries.append(CopyrightNotes);
+
+ entries.append(CopyrightHolder);
+
+ entries.append(CopyrightDate);
+
+ entries.append(CopyrightContactName);
+
+ entries.append(CopyrightContactAddress);
+
+ entries.append(CopyrightContactEmail);
+
+ typedef QMap<CSwordModuleInfo::ConfigEntry, QString> MapConfigEntry;
+
+ MapConfigEntry entryMap;
+
+ entryMap[DistributionLicense] = tr("Distribution license");
+
+ entryMap[DistributionSource] = tr("Distribution source");
+
+ entryMap[DistributionNotes] = tr("Distribution notes");
+
+ entryMap[TextSource] = tr("Text source");
+
+ entryMap[CopyrightNotes] = tr("Copyright notes");
+
+ entryMap[CopyrightHolder] = tr("Copyright holder");
+
+ entryMap[CopyrightDate] = tr("Copyright date");
+
+ entryMap[CopyrightContactName] = tr("Copyright contact name");
+
+ entryMap[CopyrightContactAddress] = tr("Copyright contact address");
+
+ entryMap[CopyrightContactEmail] = tr("Copyright contact email");
+
+ text += ("<hr><table>");
+
+ for (ListConfigEntry::iterator it(entries.begin()); it != entries.end(); ++it) {
+ QString t( config(*it) );
+
+ if (!t.isEmpty()) {
+ text += QString("<tr><td><b>%1</b></td><td>%2</td></tr>")
+ .arg(entryMap[*it])
+ .arg(config(*it));
+ }
+
+ }
+
+
+ text += "</table></font>";
+
+ return text;
+}
+
+/** Returns the language of the module. */
+const CLanguageMgr::Language* CSwordModuleInfo::language() const {
+ if (!m_dataCache.language) {
+ if (module()) {
+ if (category() == Glossary) {
+ //special handling for glossaries, we use the "from language" as language for the module
+ m_dataCache.language = (CPointers::languageMgr())->languageForAbbrev(config(GlossaryFrom));
+ }
+ else {
+ m_dataCache.language = (CPointers::languageMgr())->languageForAbbrev(module()->Lang());
+ }
+ }
+ else {
+ m_dataCache.language = (CPointers::languageMgr())->defaultLanguage(); //default language
+ }
+ }
+
+ return m_dataCache.language;
+}
+
+
+/*!
+ \fn CSwordModuleInfo::getSimpleConfigEntry(char* name)
+*/
+QString CSwordModuleInfo::getSimpleConfigEntry(const QString& name) const {
+ QString ret = isUnicode()
+ ? QString::fromUtf8(m_module->getConfigEntry(name.toUtf8().constData()))
+ : QString::fromLatin1(m_module->getConfigEntry(name.toUtf8().constData()));
+
+ return ret.isEmpty() ? QString::null : ret;
+}
+
+QString CSwordModuleInfo::getFormattedConfigEntry(const QString& name) const {
+ sword::SWBuf RTF_Buffer(m_module->getConfigEntry(name.toUtf8().constData()));
+ sword::RTFHTML RTF_Filter;
+ RTF_Filter.processText(RTF_Buffer, 0, 0);
+ QString ret = isUnicode()
+ ? QString::fromUtf8(RTF_Buffer.c_str())
+ : QString::fromLatin1(RTF_Buffer.c_str());
+
+ return ret.isEmpty() ? QString::null : ret;
+}
+
+void CSwordModuleInfo::setHidden(bool hidden)
+{
+ //qDebug("CSwordModuleInfo::setHidden");
+ QStringList hiddenModules = CBTConfig::get(CBTConfig::hiddenModules);
+ if (hidden && !hiddenModules.contains(this->name())) {
+ hiddenModules.append(this->name());
+ CBTConfig::set(CBTConfig::hiddenModules, hiddenModules);
+ }
+ if (!hidden && hiddenModules.contains(this->name()) ) {
+ hiddenModules.removeAll(this->name());
+ CBTConfig::set(CBTConfig::hiddenModules, hiddenModules);
+ }
+}
+
+bool CSwordModuleInfo::isHidden() const
+{
+ //qDebug("CSwordModuleInfo::isHidden");
+ QStringList hiddenModules = CBTConfig::get(CBTConfig::hiddenModules);
+ if (hiddenModules.contains(this->name())) {
+ return true;
+ }
+ return false;
+}
diff --git a/src/backend/drivers/cswordmoduleinfo.h b/src/backend/drivers/cswordmoduleinfo.h
new file mode 100644
index 0000000..0f612f9
--- /dev/null
+++ b/src/backend/drivers/cswordmoduleinfo.h
@@ -0,0 +1,384 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CSWORDMODULEINFO_H
+#define CSWORDMODULEINFO_H
+
+#include "backend/managers/clanguagemgr.h"
+
+//Qt
+#include <QString>
+#include <QList>
+
+//Sword
+#include <listkey.h>
+#include <swsearchable.h>
+#include <swmodule.h>
+#include <swversion.h>
+#include <swdisp.h>
+
+class CSwordBackend;
+class CSwordKey;
+
+namespace Rendering {
+
+ class CEntryDisplay;
+}
+
+/**
+ * Base class for Sword modules.
+ * This is the base class for all Sword modules. Every class handling a special Sword module type
+ * does inherit from this class.
+ *
+ * @author The BibleTime team
+ * @version $Id: cswordmoduleinfo.h,v 1.83 2007/02/04 23:12:32 joachim Exp $
+ */
+
+class CSwordModuleInfo: public QObject
+{
+ Q_OBJECT
+
+public:
+ /**
+ * These are the options which could be supported by modules and by this backend.
+ * It's used in @ref CSwordBackend::setOption.
+ */
+ enum FilterTypes {
+ footnotes, /**< Footnotes embedded in the module's text */
+ strongNumbers, /**< strong numbers, usually in the text for the info display */
+ headings, /**< additional section headings */
+ morphTags, /**< morphology */
+ lemmas, /**< lemma tags */
+ hebrewPoints,/**< Hebrew vowel points */
+ hebrewCantillation, /**<Hewbrew caantillation points */
+ greekAccents, /**< Greek accents may be switched on and off */
+ scriptureReferences, /**< scripture references may be switched on and off, just makes sense in Bibles */
+ redLetterWords, /**< Jesus words in red, color is template specific */
+ textualVariants, /**< variants */
+ morphSegmentation, /**< morph word segmentation, supported by OSIS */
+ filterTypesMIN = footnotes, /**< first entry of this enum */
+ filterTypesMAX = morphSegmentation /**< last item in this enum */
+ // transliteration /* The following are handled in a special way */
+ };
+ /** The text direction of a module */
+ enum TextDirection { /* The text direction of the modules's text */
+ LeftToRight, /**< Left to right text direction, the default setting */
+ RightToLeft /**< Right to left text directin, e.g. for hebrew */
+ };
+ /** The module type.
+ */
+ enum ModuleType {
+ Bible, /**< Bible module */
+ Commentary, /**< Commentary module */
+ Lexicon, /**< Lexicon module */
+ GenericBook, /**< Generic book module */
+ Unknown /**< Fall back type for unknown modules */
+ };
+ /**
+ * This enum is used to give
+ * back an error code after unlocking the module
+ * BibleTime stores the unlock key not in the module's config file but in BibleTime's
+ * configuration file.
+ */
+ enum UnlockErrorCode {
+ noError, /**< No error occured, everything worked ok. The key was written to the BibleTime config */
+ wrongUnlockKey, /**< The wrong key was used. Module is not unlocked */
+ notLocked, /**< The module was not locked so it can't be unlocked */
+ noPermission /**< The key was not written to config because we have no permissions */
+ };
+ enum ConfigEntry {
+ AboutInformation, /**< The about information of a module which is stored in the config file*/
+ AbsoluteDataPath, /**< The absolute data path stored in the config object */
+ CipherKey, /**< The cipher key which was used to unlock the module. Not necessarily set.*/
+ DataPath, /**< The relative path. See AbsoluteDataPath*/
+ Description, /**< The module description stored in the config file */
+ ModuleVersion, /**< The module's version.*/
+ MinimumSwordVersion, /**< The required Sword Version of this module. Otherwise some things may not work (compression etc.).*/
+ TextDir, /**< The text direction */
+ DisplayLevel, /**< Mostly used for books. Gives the level which should contain the connected entries.*/
+ GlossaryFrom, /**< lamguage from which the Glosaary tramslates */
+ GlossaryTo, /**< lamguages to which the glossary maps to */
+ DistributionLicense,
+ DistributionSource,
+ DistributionNotes,
+ TextSource,
+ CopyrightNotes,
+ CopyrightHolder,
+ CopyrightDate,
+ CopyrightContactName,
+ CopyrightContactAddress,
+ CopyrightContactEmail,
+ Markup /**< The markup of this module */
+ };
+ enum Feature {
+ //StrongsNumbers, /**< Use for Bibles which have embedded strong numbers */ BT does not use this as a user option
+ GreekDef,
+ HebrewDef,
+ GreekParse,
+ HebrewParse,
+ featureMin = GreekDef,
+ featureMax = HebrewParse
+ };
+ enum Category {
+ UnknownCategory = 0, /**< The category wasn't set or has an unknwon value */
+ Bibles,
+ Commentaries,
+ Books,
+ Lexicons,
+ Glossary,
+ DailyDevotional,
+ Images,
+ Cult /**< The module is a cult / sect / questionable module */
+ };
+
+ /**
+ * Returns the base directory for search indices
+ */
+ static QString getGlobalBaseIndexLocation();
+ /**
+ * Removes search index for this module, even if the module is not there any more
+ */
+ static void deleteIndexForModule( QString name );
+
+
+ /**
+ * Returns the config entry which is pecified by the parameter.
+ */
+ QString config( const CSwordModuleInfo::ConfigEntry entry ) const;
+
+ CSwordModuleInfo( sword::SWModule* module, CSwordBackend* const = 0 );
+ /** Copy constructor to copy the passed parameter.
+ * @param m The module to be copied
+ */
+ CSwordModuleInfo( const CSwordModuleInfo& m );
+ /** Reimplementation to return a valid clone.
+ */
+ virtual CSwordModuleInfo* clone();
+ /** Destructor.
+ */
+ virtual ~CSwordModuleInfo();
+
+ /**
+ * Returns the module object so all objects can access the original Sword module.
+ */
+ sword::SWModule* module() const;
+ /**
+ * Sets the unlock key of the modules and writes the key into the cofig file.
+ * @return True if the unlock process was succesful, if the key was wrong, or if the config file was write protected return false.
+ */
+ bool unlock( const QString& unlockKey );
+ /**
+ * Returns the display object for this module. Normally every module should have a Display object.
+ * Please don't use module()->Display() because this function does return the Sword display and does
+ * render the text, too.
+ * This function performs some casts to return the correct display. If it returns 0 there's no valid
+ * display object.
+ */
+ Rendering::CEntryDisplay* getDisplay() const;
+ /**
+ * This function does return true if the data files of the module are encrypted by the module author
+ * (the on who made the module) no matter if it's locked or not.
+ * @return True if this module is encryped
+ */
+ bool isEncrypted() const;
+ /**
+ * This function returns true if this module is locked (encrypted + correct cipher key),
+ * otherwise return false.
+ * @return True if this module is locked, i.e. encrypted but without a key set
+ */
+ bool isLocked();
+
+ bool unlockKeyIsValid();
+
+ /** The module version.
+ * @return true if this module has a version number and false if it doesn't have one.
+ */
+ inline bool hasVersion() const;
+
+ /**
+ * Returns true if the module's index has been built.
+ */
+ virtual bool hasIndex();
+ /**
+ * Returns the path to this module's index base dir
+ */
+ virtual QString getModuleBaseIndexLocation() const;
+ /**
+ * Returns the path to this module's standard index
+ */
+ virtual QString getModuleStandardIndexLocation() const;
+ /**
+ * Builds a search index for this module
+ */
+ virtual void buildIndex();
+ /**
+ * Returns index size
+ */
+ virtual unsigned long indexSize() const;
+ /**
+ * Returns true if something was found, otherwise return false.
+ * This function uses CLucene to perform and index based search. It also
+ * overwrites the variable containing the last search result.
+ */
+ virtual bool searchIndexed(const QString& searchedText, sword::ListKey& scope);
+ /**
+ * Returns the last search result for this module.
+ * The last result is cleared by @ref search
+ */
+ virtual sword::ListKey& searchResult( const sword::ListKey* newResult = 0 );
+ /**
+ * Clears the last search result.
+ * This does immediately clean the last search result,
+ * no matter if search is in progress or not.
+ */
+ void clearSearchResult();
+ /**
+ * Returns the type of the module.
+ */
+ virtual CSwordModuleInfo::ModuleType type() const;
+ /**
+ * Returns the required Sword version for this module.
+ * Returns -1 if no special Sword version is required.
+ */
+ sword::SWVersion minimumSwordVersion();
+ /**
+ * Returns the name of the module.
+ * @return The name of this module.
+ */
+ QString name() const;
+ /**
+ * Snaps to the closest entry in the module if the current key is
+ * not present in the data files.
+ */
+ virtual bool snap() {
+ return false;
+ };
+
+ bool has( const CSwordModuleInfo::Feature ) const;
+ bool has( const CSwordModuleInfo::FilterTypes ) const;
+ /**
+ * Returns the text direction of the module's text.,
+ */
+ virtual CSwordModuleInfo::TextDirection textDirection();
+ /**
+ * Writes the new text at the given position into the module. This does only work for writabe modules.
+ */
+ virtual void write( CSwordKey* key, const QString& newText );
+ /**
+ * Deletes the current entry and removes it from the module.
+ */
+ bool deleteEntry( CSwordKey* const key );
+ /**
+ * Returns the language of the module.
+ */
+ const CLanguageMgr::Language* language() const;
+ /**
+ * Returns true if this module may be written by the write display windows.
+ */
+ inline virtual bool isWritable() const;
+ /**
+ * Returns true if this module is hidden (not to be shown with other modules in certain views).
+ */
+ bool isHidden() const;
+
+ void setHidden(bool hidden);
+
+ /**
+ * Returns the category of this module. See CSwordModuleInfo::Category for possible values.
+ */
+ CSwordModuleInfo::Category category() const;
+ /**
+ * The about text which belongs to this module.
+ */
+ QString aboutText() const;
+ /**
+ * Returns true if this module is Unicode encoded. False if the charset is iso8859-1.
+ * Protected because it should not be used outside of the CSword*ModuleInfo classes.
+ */
+ inline bool isUnicode() const {
+ return m_dataCache.isUnicode;
+ }
+
+public slots:
+ inline void cancelIndexing() { m_cancelIndexing = true; };
+
+protected:
+ friend class CSwordBackend;
+
+ inline CSwordBackend* backend() const {
+ return m_backend;
+ }
+
+ inline void backend( CSwordBackend* newBackend ) {
+ if (newBackend) {
+ m_backend = newBackend;
+ }
+ }
+
+ QString getSimpleConfigEntry(const QString& name) const;
+ QString getFormattedConfigEntry(const QString& name) const;
+
+signals:
+ void indexingFinished();
+ void indexingProgress(int);
+
+private:
+ sword::SWModule* m_module;
+ sword::ListKey m_searchResult;
+
+ mutable struct DataCache {
+ DataCache() {
+ language = 0;
+ }
+
+ QString name;
+ bool isUnicode;
+ CSwordModuleInfo::Category category;
+ const CLanguageMgr::Language* language;
+ bool hasVersion;
+ }
+
+ m_dataCache;
+
+ CSwordBackend* m_backend;
+
+ bool m_hidden;
+
+ bool m_cancelIndexing;
+};
+
+inline CSwordModuleInfo::ModuleType CSwordModuleInfo::type() const {
+ return CSwordModuleInfo::Unknown;
+}
+
+inline sword::SWModule* CSwordModuleInfo::module() const {
+ return m_module;
+}
+
+inline bool CSwordModuleInfo::hasVersion() const {
+ return m_dataCache.hasVersion;
+}
+
+
+/**
+* Returns the name of the module.
+* The Sword library takes care of the duplicate names: _n is added after each duplicate.
+*/
+inline QString CSwordModuleInfo::name() const {
+ return m_dataCache.name;
+}
+
+/** Returns true if this module may be written by the write display windows. */
+inline bool CSwordModuleInfo::isWritable() const {
+ return false;
+}
+
+//#include "util/cpointers.h"
+
+#endif
diff --git a/src/backend/filters/bt_gbfhtml.cpp b/src/backend/filters/bt_gbfhtml.cpp
new file mode 100644
index 0000000..0627cee
--- /dev/null
+++ b/src/backend/filters/bt_gbfhtml.cpp
@@ -0,0 +1,296 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+//BibleTime includes
+#include "bt_gbfhtml.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/managers/cswordbackend.h"
+#include "util/cpointers.h"
+
+//Sword includes
+#include <utilxml.h>
+
+//Qt includes
+#include <QRegExp>
+#include <QString>
+
+Filters::BT_GBFHTML::BT_GBFHTML() : sword::GBFHTML() {
+
+ setEscapeStringCaseSensitive(true);
+ setPassThruUnknownEscapeString(true); //the HTML widget will render the HTML escape codes
+
+ removeTokenSubstitute("Rf");
+ // addTokenSubstitute("RB", "<span>"); //start of a footnote with embedded text
+
+ addTokenSubstitute("FI", "<span class=\"italic\">"); // italics begin
+ addTokenSubstitute("Fi", "</span>");
+
+ addTokenSubstitute("FB", "<span class=\"bold\">"); // bold begin
+ addTokenSubstitute("Fb", "</span>");
+
+ addTokenSubstitute("FR", "<span class=\"jesuswords\">");
+ addTokenSubstitute("Fr", "</span>");
+
+ addTokenSubstitute("FU", "<u>"); // underline begin
+ addTokenSubstitute("Fu", "</u>");
+
+ addTokenSubstitute("FO", "<span class=\"quotation\">"); // Old Testament quote begin
+ addTokenSubstitute("Fo", "</span>");
+
+
+ addTokenSubstitute("FS", "<span class=\"sup\">"); // Superscript begin// Subscript begin
+ addTokenSubstitute("Fs", "</span>");
+
+ addTokenSubstitute("FV", "<span class=\"sub\">"); // Subscript begin
+ addTokenSubstitute("Fv", "</span>");
+
+ addTokenSubstitute("TT", "<div class=\"booktitle\">");
+ addTokenSubstitute("Tt", "</div>");
+
+ addTokenSubstitute("TS", "<div class=\"sectiontitle\">");
+ addTokenSubstitute("Ts", "</div>");
+
+ //addTokenSubstitute("PP", "<span class=\"poetry\">"); // poetry begin
+ //addTokenSubstitute("Pp", "</span>");
+
+
+ addTokenSubstitute("Fn", "</font>"); // font end
+ addTokenSubstitute("CL", "<br/>"); // new line
+ addTokenSubstitute("CM", "<br/>"); // paragraph <!P> is a non showing comment that can be changed in the front end to <P> if desired
+
+ addTokenSubstitute("CG", "&gt;"); // literal greater-than sign
+ addTokenSubstitute("CT", "&lt;"); // literal less-than sign
+
+ addTokenSubstitute("JR", "<span class=\"right\">"); // right align begin
+ addTokenSubstitute("JC", "<span class=\"center\">"); // center align begin
+ addTokenSubstitute("JL", "</span>"); // align end
+}
+
+/** No descriptions */
+char Filters::BT_GBFHTML::processText(sword::SWBuf& buf, const sword::SWKey * key, const sword::SWModule * module) {
+ GBFHTML::processText(buf, key, module);
+
+ if (!module->isProcessEntryAttributes()) {
+ return 1; //no processing should be done, may happen in a search
+ }
+
+ CSwordModuleInfo* m = CPointers::backend()->findModuleByName( module->Name() );
+
+ if (m && !(m->has(CSwordModuleInfo::lemmas) || m->has(CSwordModuleInfo::morphTags) || m->has(CSwordModuleInfo::strongNumbers))) { //only parse if the module has strongs or lemmas
+ return 1; //WARNING: Return alread here
+ }
+
+ //Am Anfang<WH07225> schuf<WH01254><WTH8804> Gott<WH0430> Himmel<WH08064> und<WT> Erde<WH0776>.
+ //A simple word<WT> means: No entry for this word "word"
+ QString result;
+
+ QString t = QString::fromUtf8(buf.c_str());
+
+ QRegExp tag("([.,;:]?<W[HGT][^>]*>\\s*)+");
+
+ QStringList list;
+
+ int lastMatchEnd = 0;
+
+ int pos = tag.indexIn(t,0);
+
+ if (pos == -1) { //no strong or morph code found in this text
+ return 1; //WARNING: Return already here
+ }
+
+ //split the text into parts which end with the GBF tag marker for strongs/lemmas
+ while (pos != -1) {
+ list.append(t.mid(lastMatchEnd, pos+tag.matchedLength()-lastMatchEnd));
+
+ lastMatchEnd = pos + tag.matchedLength();
+ pos = tag.indexIn(t, pos + tag.matchedLength());
+ }
+
+ //append the trailing text to the list.
+ if (!t.right(t.length() - lastMatchEnd).isEmpty()) {
+ list.append(t.right(t.length() - lastMatchEnd));
+ }
+
+ //list is now a list of words with 1-n Strongs at the end, which belong to this word.
+
+ //now create the necessary HTML in list entries and concat them to the result
+ tag = QRegExp("<W([HGT])([^>]*)>");
+ tag.setMinimal(true);
+
+ for (QStringList::iterator it = list.begin(); it != list.end(); ++it) {
+ QString e = (*it); //current entry to process
+ //qWarning(e.latin1());
+
+ //check if there is a word to which the strongs info belongs to.
+ //If yes, wrap that word with the strongs info
+ //If not, leave out the strongs info, because it can't be tight to a text
+ //Comparing the first char with < is not enough, because the tokenReplace is done already
+ //so there might be html tags already.
+ const bool textPresent = (e.trimmed().remove(QRegExp("[.,;:]")).left(2) != "<W");
+
+ if (!textPresent) {
+ result += (*it);
+ continue;
+ }
+
+ int pos = tag.indexIn(e, 0); //try to find a strong number marker
+ bool insertedTag = false;
+ bool hasLemmaAttr = false;
+ bool hasMorphAttr = false;
+
+ QString value = QString::null;
+ int tagAttributeStart = -1;
+
+ while (pos != -1) { //work on all strong/lemma tags in this section, should be between 1-3 loops
+ const bool isMorph = (tag.cap(1) == "T");
+ value = isMorph ? tag.cap(2) : tag.cap(2).prepend( tag.cap(1) );
+
+ if (value.isEmpty()) {
+ break;
+ }
+
+ //insert the span
+ if (!insertedTag) { //we have to insert a new tag end and beginning, i.e. our first loop
+ e.replace(pos, tag.matchedLength(), "</span>");
+ pos += 7;
+
+ //skip blanks, commas, dots and stuff at the beginning, it doesn't belong to the morph code
+ QString rep("<span ");
+ rep.append(isMorph ? "morph" : "lemma").append("=\"").append(value).append("\">");
+
+ hasMorphAttr = isMorph;
+ hasLemmaAttr = !isMorph;
+
+ int startPos = 0;
+ QChar c = e[startPos];
+
+ while ((startPos < pos) && (c.isSpace() || c.isPunct())) {
+ ++startPos;
+
+ c = e[startPos];
+ }
+
+ e.insert( startPos, rep );
+ tagAttributeStart = startPos + 6; //to point to the start of the attributes
+ pos += rep.length();
+ }
+ else { //add the attribute to the existing tag
+ e.remove(pos, tag.matchedLength());
+
+ if (tagAttributeStart == -1) {
+ continue; //nothing valid found
+ }
+
+ if ((!isMorph && hasLemmaAttr) || (isMorph && hasMorphAttr)) { //we append another attribute value, e.g. 3000 gets 3000|5000
+ //search the existing attribute start
+ QRegExp attrRegExp( isMorph ? "morph=\".+(?=\")" : "lemma=\".+(?=\")" );
+ attrRegExp.setMinimal(true);
+ const int foundPos = e.indexOf(attrRegExp, tagAttributeStart);
+
+ if (foundPos != -1) {
+ e.insert(foundPos + attrRegExp.matchedLength(), QString("|").append(value));
+ pos += value.length() + 1;
+
+ hasLemmaAttr = !isMorph;
+ hasMorphAttr = isMorph;
+ }
+ }
+ else { //attribute was not yet inserted
+ QString attr = QString(isMorph ? "morph" : "lemma").append("=\"").append(value).append("\" ");
+
+ e.insert(tagAttributeStart, attr);
+ pos += attr.length();
+
+ hasMorphAttr = isMorph;
+ hasLemmaAttr = !isMorph;
+ }
+
+ //tagAttributeStart remains the same
+ }
+
+ insertedTag = true;
+ pos = tag.indexIn(e, pos);
+ }
+
+ result += e;
+ }
+
+ if (list.count()) {
+ buf = (const char*)result.toUtf8().constData();
+ }
+
+ return 1;
+}
+
+bool Filters::BT_GBFHTML::handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData) {
+ if (!substituteToken(buf, token)) { //more than a simple replace
+ const unsigned int tokenLength = strlen(token);
+ unsigned long i;
+ sword::SWBuf value;
+
+ BT_UserData* myUserData = dynamic_cast<BT_UserData*>(userData);
+ sword::SWModule* myModule = const_cast<sword::SWModule*>(myUserData->module); //hack to be able to call stuff like Lang()
+
+ if ( !strncmp(token, "WG", 2)
+ || !strncmp(token, "WH", 2)
+ || !strncmp(token, "WT", 2) ) {
+ buf.append('<');
+ buf.append(token);
+ buf.append('>');
+ }
+ else if (!strncmp(token, "RB", 2)) {
+ myUserData->hasFootnotePreTag = true;
+ buf.append("<span class=\"footnotepre\">");
+ }
+ else if (!strncmp(token, "RF", 2)) {
+ //we use several append calls because appendFormatted slows down filtering, which should be fast
+
+ if (myUserData->hasFootnotePreTag) {
+ // qWarning("inserted footnotepre end");
+ buf.append("</span>");
+ myUserData->hasFootnotePreTag = false;
+ }
+
+ buf.append(" <span class=\"footnote\" note=\"");
+ buf.append(myModule->Name());
+ buf.append('/');
+ buf.append(myUserData->key->getShortText());
+ buf.append('/');
+ buf.append( QString::number(myUserData->swordFootnote++).toUtf8().constData() );
+ buf.append("\">*</span> ");
+
+ userData->suspendTextPassThru = true;
+ }
+ else if (!strncmp(token, "Rf", 2)) { //end of footnote
+ userData->suspendTextPassThru = false;
+ }
+ else if (!strncmp(token, "FN", 2)) { //the end </font> tag is inserted in addTokenSubsitute
+ buf.append("<font face=\"");
+
+ for (i = 2; i < tokenLength; i++) {
+ if(token[i] != '\"') {
+ buf.append( token[i] );
+ }
+ }
+
+ buf.append("\">");
+ }
+ else if (!strncmp(token, "CA", 2)) { // ASCII value
+ buf.append( (char)atoi(&token[2]) );
+ }
+ else {
+ return GBFHTML::handleToken(buf, token, userData);
+ }
+ }
+
+ return true;
+}
diff --git a/src/backend/filters/bt_gbfhtml.h b/src/backend/filters/bt_gbfhtml.h
new file mode 100644
index 0000000..b9118aa
--- /dev/null
+++ b/src/backend/filters/bt_gbfhtml.h
@@ -0,0 +1,55 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+/* $Header: /cvsroot/bibletime/bibletime/bibletime/backend/filters/bt_gbfhtml.h,v 1.24 2006/02/25 11:38:15 joachim Exp $ */
+/* $Revision: 1.24 $ */
+
+#ifndef BT_GBFHTML_H
+#define BT_GBFHTML_H
+
+//Sword includes
+#include <gbfhtml.h>
+
+namespace Filters {
+
+ /** GBF to HTML filter,
+ * This filter converts GBF Text into HTML
+ */
+
+class BT_GBFHTML : public sword::GBFHTML/*, protected CFilterTool */
+ {
+
+protected:
+
+class BT_UserData : public sword::GBFHTML::MyUserData {
+
+public:
+BT_UserData(const sword::SWModule *module, const sword::SWKey *key) : sword::GBFHTML::MyUserData(module, key) {
+ swordFootnote = 1;
+ hasFootnotePreTag = false;
+ }
+
+ short unsigned int swordFootnote;
+ };
+
+ virtual sword::BasicFilterUserData *createUserData(const sword::SWModule* module, const sword::SWKey* key) {
+ return new BT_UserData(module, key);
+ }
+
+public:
+ BT_GBFHTML();
+ virtual bool handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData);
+ virtual char processText(sword::SWBuf& buf, const sword::SWKey*, const sword::SWModule * = 0);
+ };
+
+}
+
+#endif
diff --git a/src/backend/filters/bt_osishtml.cpp b/src/backend/filters/bt_osishtml.cpp
new file mode 100644
index 0000000..b9c9746
--- /dev/null
+++ b/src/backend/filters/bt_osishtml.cpp
@@ -0,0 +1,619 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//BibleTime includes
+#include "bt_osishtml.h"
+#include "backend/managers/clanguagemgr.h"
+#include "backend/managers/creferencemanager.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+
+#include "backend/config/cbtconfig.h"
+#include "util/cpointers.h"
+
+//Sword
+#include <swmodule.h>
+#include <swbuf.h>
+#include <utilxml.h>
+
+//Qt
+#include <QString>
+
+//KDE
+
+
+Filters::BT_OSISHTML::BT_OSISHTML() : sword::OSISHTMLHREF() {
+ setPassThruUnknownEscapeString(true); //the HTML widget will render the HTML escape codes
+
+ addTokenSubstitute("inscription", "<span class=\"inscription\">");
+ addTokenSubstitute("/inscription","</span>");
+
+ addTokenSubstitute("mentioned", "<span class=\"mentioned\">");
+ addTokenSubstitute("/mentioned", "</span>");
+
+// addTokenSubstitute("divineName", "<span class=\"name\"><span class=\"divine\">");
+// addTokenSubstitute("/divineName", "</span></span>");
+
+ //TODO Move that down to the real tag handling, segs without the type morph would generate incorrect markup, as the end span is always inserted
+// addTokenSubstitute("seg type=\"morph\"", "<span class=\"morphSegmentation\">");
+// addTokenSubstitute("/seg", "</span>");
+
+ // OSIS tables
+ addTokenSubstitute("table", "<table>");
+ addTokenSubstitute("/table", "</table>");
+ addTokenSubstitute("row", "<tr>");
+ addTokenSubstitute("/row", "</tr>");
+ addTokenSubstitute("cell", "<td>");
+ addTokenSubstitute("/cell", "</td>");
+
+}
+
+bool Filters::BT_OSISHTML::handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData) {
+ // manually process if it wasn't a simple substitution
+
+ if (!substituteToken(buf, token)) {
+ BT_UserData* myUserData = dynamic_cast<BT_UserData*>(userData);
+ sword::SWModule* myModule = const_cast<sword::SWModule*>(myUserData->module); //hack
+
+ sword::XMLTag tag(token);
+ // qWarning("found %s", token);
+ const bool osisQToTick = ((!userData->module->getConfigEntry("OSISqToTick")) || (strcmp(userData->module->getConfigEntry("OSISqToTick"), "false")));
+
+ if (!tag.getName()) {
+ return false;
+ }
+
+ // <div> tag
+ if (!strcmp(tag.getName(), "div")) {
+ //handle intro
+
+ if ((!tag.isEmpty()) && (!tag.isEndTag())) { //start tag
+ sword::SWBuf type( tag.getAttribute("type") );
+
+ if (type == "introduction") {
+ buf.append("<div class=\"introduction\">");
+ }
+ else if (type == "chapter") {
+ buf.append("<div class=\"chapter\" />"); //don't open a div here, that would lead to a broken XML structure
+ }
+ else {
+ buf.append("<div>");
+ }
+ }
+ else if (tag.isEndTag()) { //end tag
+ buf.append("</div>");
+ }
+ }
+ else if (!strcmp(tag.getName(), "w")) {
+ if ((!tag.isEmpty()) && (!tag.isEndTag())) { //start tag
+ const char *attrib;
+ const char *val;
+
+ sword::XMLTag outTag("span");
+ sword::SWBuf attrValue;
+
+ if ((attrib = tag.getAttribute("xlit"))) {
+ val = strchr(attrib, ':');
+ val = (val) ? (val + 1) : attrib;
+ outTag.setAttribute("xlit", val);
+ }
+
+ if ((attrib = tag.getAttribute("gloss"))) {
+ val = strchr(attrib, ':');
+ val = (val) ? (val + 1) : attrib;
+ outTag.setAttribute("gloss", val);
+ }
+
+ if ((attrib = tag.getAttribute("lemma"))) {
+ char splitChar = '|';
+ const int countSplit1 = tag.getAttributePartCount("lemma", '|');
+ const int countSplit2 = tag.getAttributePartCount("lemma", ' '); //TODO: not allowed, remove soon
+ int count = 0;
+
+ if (countSplit1 > countSplit2) { //| split char
+ splitChar = '|'; //TODO: not allowed, remove soon
+ count = countSplit1;
+ }
+ else {
+ splitChar = ' ';
+ count = countSplit2;
+ }
+
+ int i = (count > 1) ? 0 : -1; // -1 for whole value cuz it's faster, but does the same thing as 0
+ attrValue = "";
+
+ do {
+ if (attrValue.length()) {
+ attrValue.append( '|' );
+ }
+
+ attrib = tag.getAttribute("lemma", i, splitChar);
+
+ if (i < 0) { // to handle our -1 condition
+ i = 0;
+ }
+
+ val = strchr(attrib, ':');
+ val = (val) ? (val + 1) : attrib;
+
+ attrValue.append(val);
+ }
+ while (++i < count);
+
+ if (attrValue.length()) {
+ outTag.setAttribute("lemma", attrValue.c_str());
+ }
+ }
+
+ if ((attrib = tag.getAttribute("morph"))) {
+ char splitChar = '|';
+ const int countSplit1 = tag.getAttributePartCount("morph", '|');
+ const int countSplit2 = tag.getAttributePartCount("morph", ' '); //TODO: not allowed, remove soon
+ int count = 0;
+
+ if (countSplit1 > countSplit2) { //| split char
+ splitChar = '|';
+ count = countSplit1;
+ }
+ else {
+ splitChar = ' ';
+ count = countSplit2;
+ }
+
+ int i = (count > 1) ? 0 : -1; // -1 for whole value cuz it's faster, but does the same thing as 0
+
+ attrValue = "";
+
+ do {
+ if (attrValue.length()) {
+ attrValue.append('|');
+ }
+
+ attrib = tag.getAttribute("morph", i, splitChar);
+
+ if (i < 0) {
+ i = 0; // to handle our -1 condition
+ }
+
+ val = strchr(attrib, ':');
+
+ if (val) { //the prefix gives the modulename
+ //check the prefix
+ if (!strncmp("robinson:", attrib, 9)) { //robinson
+ attrValue.append( "Robinson:" ); //work is not the same as Sword's module name
+ attrValue.append( val+1 );
+ }
+ //strongs is handled by BibleTime
+ /*else if (!strncmp("strongs", attrib, val-atrrib)) {
+ attrValue.append( !strncmp(attrib, "x-", 2) ? attrib+2 : attrib );
+ }*/
+ else {
+ attrValue.append( !strncmp(attrib, "x-", 2) ? attrib+2 : attrib );
+ }
+ }
+ else { //no prefix given
+ val = attrib;
+ const bool skipFirst = ((val[0] == 'T') && ((val[1] == 'H') || (val[1] == 'H')));
+ attrValue.append( skipFirst ? val+1 : val );
+ }
+ }
+ while (++i < count);
+
+ if (attrValue.length()) {
+ outTag.setAttribute("morph", attrValue.c_str());
+ }
+ }
+
+ if ((attrib = tag.getAttribute("POS"))) {
+ val = strchr(attrib, ':');
+ val = (val) ? (val + 1) : attrib;
+ outTag.setAttribute("pos", val);
+ }
+
+ buf.append( outTag.toString() );
+ }
+ else if (tag.isEndTag()) { // end or empty <w> tag
+ buf.append("</span>");
+ }
+ }
+
+ // <note> tag
+ else if (!strcmp(tag.getName(), "note")) {
+ if (!tag.isEndTag()) { //start tag
+ const sword::SWBuf type( tag.getAttribute("type") );
+
+ if (type == "crossReference") { //note containing cross references
+ myUserData->inCrossrefNote = true;
+ myUserData->noteType = BT_UserData::CrossReference;
+ myUserData->swordFootnote++; // cross refs count as notes, too
+
+ /* //get the refList value of the right entry attribute
+ AttributeList notes = myModule->getEntryAttributes()["Footnote"];
+ bool foundNote = false;
+
+ SWBuf id( tag.getAttribute("osisID") );
+ SWBuf refList;
+
+ for (AttributeList::iterator list_it = notes.begin(); (list_it != notes.end()) && !foundNote; ++list_it ) {
+ for (AttributeValue::iterator val_it = list_it->second.begin(); (val_it != list_it->second.end()) && !foundNote; ++val_it ) {
+ if ((val_it->first == "osisID") && (val_it->second == id)) {
+ foundNote = true; //this break the loop
+ refList = list_it->second["refList"];
+ }
+ }
+ }
+
+ if (refList.length()) {
+ buf.append(" <span class=\"crossreference\" crossrefs=\"");
+ buf.append(refList.c_str());
+ buf.append("\"> ");
+
+ myUserData->noteType = BT_UserData::CrossReference;
+ }
+ else {
+ myUserData->noteType = BT_UserData::Unknown;
+ }*/
+
+ buf.append("<span class=\"crossreference\">");
+#ifdef SWORD_SIMPLERENDER
+ sword::SWBuf footnoteNumber = tag.getAttribute("swordFootnote");
+ sword::SWBuf footnoteBody = myModule->getEntryAttributes()["Footnote"][footnoteNumber]["body"];
+ buf += myModule->RenderText(footnoteBody);
+#endif
+ }
+
+ /* else if (type == "explanation") {
+ }
+ */
+ else if ((type == "strongsMarkup") || (type == "x-strongsMarkup")) {
+ /**
+ * leave strong's markup notes out, in the future we'll probably have
+ * different option filters to turn different note types on or off
+ */
+
+ myUserData->suspendTextPassThru = true;
+ myUserData->noteType = BT_UserData::StrongsMarkup;
+ }
+
+ else {
+ // qWarning("found note in %s", myUserData->key->getShortText());
+ buf.append(" <span class=\"footnote\" note=\"");
+ buf.append(myModule->Name());
+ buf.append('/');
+ buf.append(myUserData->key->getShortText());
+ buf.append('/');
+ buf.append( QString::number(myUserData->swordFootnote++).toUtf8().constData() ); //inefficient
+
+ const sword::SWBuf n = tag.getAttribute("n");
+
+ buf.append("\">");
+ buf.append( (n.length() > 0) ? n.c_str() : "*" );
+ buf.append("</span> ");
+
+ myUserData->noteType = BT_UserData::Footnote;
+ myUserData->suspendTextPassThru = true;
+ }
+ }
+ else { //if (tag.isEndTag()) {
+ Q_ASSERT(myUserData->noteType != BT_UserData::Unknown);
+
+ if (myUserData->noteType == BT_UserData::CrossReference) {
+ buf.append("</span> ");
+// myUserData->suspendTextPassThru = false;
+ myUserData->inCrossrefNote = false;
+ }
+
+ myUserData->noteType = BT_UserData::Unknown;
+ myUserData->suspendTextPassThru = false;
+ }
+ }
+ // The <p> paragraph tag is handled by OSISHTMLHref
+ else if (!strcmp(tag.getName(), "reference")) { // <reference> tag
+ if (!tag.isEndTag() && !tag.isEmpty()) {
+
+ renderReference(tag.getAttribute("osisRef"), buf, myModule, myUserData);
+
+ }
+ else if (tag.isEndTag()) {
+ buf.append("</a>");
+ }
+ else { // empty reference marker
+ // -- what should we do? nothing for now.
+ }
+ }
+
+ // <l> is handled by OSISHTMLHref
+ // <title>
+ else if (!strcmp(tag.getName(), "title")) {
+ if (!tag.isEndTag() && !tag.isEmpty()) {
+ buf.append("<div class=\"sectiontitle\">");
+ }
+ else if (tag.isEndTag()) {
+ buf.append("</div>");
+ }
+ else { // empty title marker
+ // what to do? is this even valid?
+ buf.append("<br/>");
+ }
+ }
+
+ // <hi> highlighted text
+ else if (!strcmp(tag.getName(), "hi")) {
+ const sword::SWBuf type = tag.getAttribute("type");
+
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ if (type == "bold") {
+ buf.append("<span class=\"bold\">");
+ }
+ else if (type == "illuminated") {
+ buf.append("<span class=\"illuminated\">");
+ }
+ else if (type == "italic") {
+ buf.append("<span class=\"italic\">");
+ }
+ else if (type == "line-through") {
+ buf.append("<span class=\"line-through\">");
+ }
+ else if (type == "normal") {
+ buf.append("<span class=\"normal\">");
+ }
+ else if (type == "small-caps") {
+ buf.append("<span class=\"small-caps\">");
+ }
+ else if (type == "underline") {
+ buf.append("<span class=\"underline\">");
+ }
+ else {
+ buf.append("<span>"); //don't break markup, </span> is inserted later
+ }
+ }
+ else if (tag.isEndTag()) { //all hi replacements are html spans
+ buf.append("</span>");
+ }
+ }
+
+ //name
+ else if (!strcmp(tag.getName(), "name")) {
+ const sword::SWBuf type = tag.getAttribute("type");
+
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ if (type == "geographic") {
+ buf.append("<span class=\"name\"><span class=\"geographic\">");
+ }
+ else if (type == "holiday") {
+ buf.append("<span class=\"name\"><span class=\"holiday\">");
+ }
+ else if (type == "nonhuman") {
+ buf.append("<span class=\"name\"><span class=\"nonhuman\">");
+ }
+ else if (type == "person") {
+ buf.append("<span class=\"name\"><span class=\"person\">");
+ }
+ else if (type == "ritual") {
+ buf.append("<span class=\"name\"><span class=\"ritual\">");
+ }
+ else {
+ buf.append("<span class=\"name\"><span>");
+ }
+ }
+ else if (tag.isEndTag()) { //all hi replacements are html spans
+ buf.append("</span></span> ");
+ }
+ }
+ else if (!strcmp(tag.getName(), "transChange")) {
+ sword::SWBuf type( tag.getAttribute("type") );
+
+ if ( !type.length() ) {
+ type = tag.getAttribute("changeType");
+ }
+
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ if (type == "added") {
+ buf.append("<span class=\"transchange\" title=\"");
+ buf.append(QObject::tr("Added text").toUtf8().constData());
+ buf.append("\"><span class=\"added\">");
+ }
+ else if (type == "amplified") {
+ buf.append("<span class=\"transchange\"><span class=\"amplified\">");
+ }
+ else if (type == "changed") {
+ buf.append("<span class=\"transchange\"><span class=\"changed\">");
+ }
+ else if (type == "deleted") {
+ buf.append("<span class=\"transchange\"><span class=\"deleted\">");
+ }
+ else if (type == "moved") {
+ buf.append("<span class=\"transchange\"><span class=\"moved\">");
+ }
+ else if (type == "tenseChange") {
+ buf.append("<span class=\"transchange\" title=\"");
+ buf.append(QObject::tr("Verb tense changed").toUtf8().constData());
+ buf.append("\"><span class=\"tenseChange\">");
+ }
+ else {
+ buf.append("<span class=\"transchange\"><span>");
+ }
+ }
+ else if (tag.isEndTag()) { //all hi replacements are html spans
+ buf.append("</span></span>");
+ }
+ }
+ else if (!strcmp(tag.getName(), "p")) {
+ if (tag.isEmpty()) {
+ buf.append("<p/>");
+ }
+ }
+
+ // <q> quote
+ else if (!strcmp(tag.getName(), "q")) {
+ sword::SWBuf type = tag.getAttribute("type");
+ sword::SWBuf who = tag.getAttribute("who");
+ const char *lev = tag.getAttribute("level");
+ int level = (lev) ? atoi(lev) : 1;
+ const char* quoteMarker = tag.getAttribute("marker");
+
+ if ((!tag.isEndTag())) {
+ myUserData->quote.who = who;
+ if (quoteMarker) {
+ buf.append(quoteMarker);
+ }
+ else if(osisQToTick) //alternate " and '
+ buf.append((level % 2) ? '\"' : '\'');
+
+ if (who == "Jesus") {
+ buf.append("<span class=\"jesuswords\">");
+ }
+ }
+ else if (tag.isEndTag()) {
+ if (myUserData->quote.who == "Jesus") {
+ buf.append("</span>");
+ }
+ if (quoteMarker) {
+ buf.append(quoteMarker);
+ }
+ else if (osisQToTick) { //alternate " and '
+ buf.append((level % 2) ? '\"' : '\'');
+ }
+
+ myUserData->quote.who = "";
+ }
+ }
+
+ // abbr tag
+ else if (!strcmp(tag.getName(), "abbr")) {
+ if (!tag.isEndTag() && !tag.isEmpty()) {
+ const sword::SWBuf expansion = tag.getAttribute("expansion");
+
+ buf.append("<span class=\"abbreviation\" expansion=\"");
+ buf.append(expansion);
+ buf.append("\">");
+ }
+ else if (tag.isEndTag()) {
+ buf.append("</span>");
+ }
+ }
+
+ // <milestone> tag
+ else if (!strcmp(tag.getName(), "milestone")) {
+ const sword::SWBuf type = tag.getAttribute("type");
+
+ if ((type == "screen") || (type == "line")) {//line break
+ buf.append("<br/>");
+ userData->supressAdjacentWhitespace = true;
+ }
+ else if (type == "x-p") { //e.g. occurs in the KJV2006 module
+ //buf.append("<br/>");
+ const sword::SWBuf marker = tag.getAttribute("marker");
+ if (marker.length() > 0) {
+ buf.append(marker);
+ }
+ }
+ }
+ //seg tag
+ else if (!strcmp(tag.getName(), "seg")) {
+ if (!tag.isEndTag() && !tag.isEmpty()) {
+
+ const sword::SWBuf type = tag.getAttribute("type");
+
+ if (type == "morph") {//line break
+ //This code is for WLC and MORPH (WHI)
+ sword::XMLTag outTag("span");
+ outTag.setAttribute("class", "morphSegmentation");
+ const char* attrValue;
+ //Transfer the values to the span
+ //Problem: the data is in hebrew/aramaic, how to encode in HTML/BibleTime?
+ if ((attrValue = tag.getAttribute("lemma"))) outTag.setAttribute("lemma", attrValue);
+ if ((attrValue = tag.getAttribute("morph"))) outTag.setAttribute("morph", attrValue);
+ if ((attrValue = tag.getAttribute("homonym"))) outTag.setAttribute("homonym", attrValue);
+
+ buf.append(outTag.toString());
+ //buf.append("<span class=\"morphSegmentation\">");
+ }
+ else{
+ buf.append("<span>");
+ }
+ }
+ else { // seg end tag
+ buf.append("</span>");
+ }
+ //qWarning(QString("handled <seg> token. result: %1").arg(buf.c_str()).latin1());
+ }
+
+ //divine name, don't use simple tag replacing because it may have attributes
+ else if (!strcmp(tag.getName(), "divineName")) {
+ if (!tag.isEndTag()) {
+ buf.append("<span class=\"name\"><span class=\"divine\">");
+ }
+ else { //all hi replacements are html spans
+ buf.append("</span></span>");
+ }
+ }
+
+ else { //all tokens handled by OSISHTMLHref will run through the filter now
+ return sword::OSISHTMLHREF::handleToken(buf, token, userData);
+ }
+ }
+
+ return false;
+}
+
+void Filters::BT_OSISHTML::renderReference(const char *osisRef, sword::SWBuf &buf, sword::SWModule *myModule, BT_UserData *myUserData) {
+ QString ref( osisRef );
+ QString hrefRef( ref );
+ //Q_ASSERT(!ref.isEmpty()); checked later
+
+ if (!ref.isEmpty()) {
+ //find out the mod, using the current module makes sense if it's a bible or commentary because the refs link into a bible by default.
+ //If the osisRef is something like "ModuleID:key comes here" then the
+ // modulename is given, so we'll use that one
+
+ CSwordModuleInfo* mod = CPointers::backend()->findSwordModuleByPointer(myModule);
+ //Q_ASSERT(mod); checked later
+ if (!mod || (mod->type() != CSwordModuleInfo::Bible
+ && mod->type() != CSwordModuleInfo::Commentary)) {
+
+ mod = CBTConfig::get( CBTConfig::standardBible );
+ }
+
+ // Q_ASSERT(mod); There's no necessarily a module or standard Bible
+
+ //if the osisRef like "GerLut:key" contains a module, use that
+ int pos = ref.indexOf(":");
+
+ if ((pos >= 0) && ref.at(pos-1).isLetter() && ref.at(pos+1).isLetter()) {
+ QString newModuleName = ref.left(pos);
+ hrefRef = ref.mid(pos+1);
+
+ if (CPointers::backend()->findModuleByName(newModuleName)) {
+ mod = CPointers::backend()->findModuleByName(newModuleName);
+ }
+ }
+
+ if (mod) {
+ CReferenceManager::ParseOptions options;
+ options.refBase = QString::fromUtf8(myUserData->key->getText());
+ options.refDestinationModule = QString(mod->name());
+ options.sourceLanguage = QString(myModule->Lang());
+ options.destinationLanguage = QString("en");
+
+ buf.append("<a href=\"");
+ buf.append( //create the hyperlink with key and mod
+ CReferenceManager::encodeHyperlink(
+ mod->name(),
+ CReferenceManager::parseVerseReference(hrefRef, options),
+ CReferenceManager::typeFromModule(mod->type())
+ ).toUtf8().constData()
+ );
+ buf.append("\" crossrefs=\"");
+ buf.append((const char*)CReferenceManager::parseVerseReference(ref, options).toUtf8().constData()); //ref must contain the osisRef module marker if there was any
+ buf.append("\">");
+ }
+ // should we add something if there were no referenced module available?
+ }
+}
+
diff --git a/src/backend/filters/bt_osishtml.h b/src/backend/filters/bt_osishtml.h
new file mode 100644
index 0000000..7ae5e6d
--- /dev/null
+++ b/src/backend/filters/bt_osishtml.h
@@ -0,0 +1,67 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BT_OSISHTML_H
+#define BT_OSISHTML_H
+
+//Sword includes
+#include <swbuf.h>
+#include <osishtmlhref.h>
+
+namespace Filters {
+
+ /** BibleTime's OSIS to HTMl filter.
+ * This filter works on OSIS tags and outputs HTML in the structure supported by BibleTime.
+ */
+
+class BT_OSISHTML : public sword::OSISHTMLHREF {
+
+protected:
+
+class BT_UserData : public sword::OSISHTMLHREF::MyUserData {
+
+public:
+BT_UserData(const sword::SWModule *module, const sword::SWKey *key) : sword::OSISHTMLHREF::MyUserData(module, key) {
+ noteType = Unknown;
+ swordFootnote = 1;
+ inCrossrefNote = false;
+ }
+
+ unsigned short int swordFootnote;
+ bool inCrossrefNote;
+
+ enum NoteType {
+ Unknown,
+ Alternative,
+ CrossReference,
+ Footnote,
+ StrongsMarkup
+ } noteType;
+
+ struct {
+ sword::SWBuf who;
+ }
+
+ quote;
+ };
+
+ virtual sword::BasicFilterUserData *createUserData(const sword::SWModule* module, const sword::SWKey* key) {
+ return new BT_UserData(module, key);
+ }
+
+public:
+ BT_OSISHTML();
+ virtual bool handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData);
+private:
+ void renderReference(const char *osisRef, sword::SWBuf &buf, sword::SWModule *myModule, BT_UserData *myUserData);
+ };
+
+} //end of Filters namespace
+
+#endif
diff --git a/src/backend/filters/bt_plainhtml.cpp b/src/backend/filters/bt_plainhtml.cpp
new file mode 100644
index 0000000..67557cc
--- /dev/null
+++ b/src/backend/filters/bt_plainhtml.cpp
@@ -0,0 +1,72 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "bt_plainhtml.h"
+
+Filters::BT_PLAINHTML::BT_PLAINHTML() : sword::SWFilter() {
+}
+
+/** No descriptions */
+char Filters::BT_PLAINHTML::processText(sword::SWBuf& text, const sword::SWKey* /*key*/, const sword::SWModule* /*module*/) {
+ int count = 0;
+
+ sword::SWBuf orig = text;
+ const char *from = orig.c_str();
+ for (text = ""; *from; from++)
+ {
+ if ((*from == '\n') && (from[1] == '\n')) // two newlinea are a paragraph
+ {
+ text += "<P>";
+ from++;
+ continue;
+ }
+ //This is a special case: Newlines in the plaintext editor are stored as <br />, not as \n
+ //we need to let them through
+ else if ((*from == '<') && (from[1] == 'b') && (from[2] == 'r') && (from[3] == ' ') && (from[4] == '/') && (from[5] == '>')){
+ text += "<br />";
+ from += 5;
+ continue;
+ }
+ else if ((*from == '\n')){ // only one new line
+ text += "<BR>";
+ continue;
+ }
+ else if (*from == '<') {
+ text += "&lt;";
+ continue;
+ }
+ else if (*from == '>') {
+ text += "&gt;";
+ continue;
+ }
+ else if (*from == '&'){
+ text += "&amp;";
+ continue;
+ }
+ else if (*from == '{') { //footnote start
+ text += "<FONT COLOR=\"#80000\"><SMALL> (";
+ continue;
+ }
+ else if (*from == '}') //footnote end
+ {
+ text += ") </SMALL></FONT>";
+ continue;
+ }
+ else if ((*from == ' ') && (count > 5000))
+ {
+ text += "<WBR>";
+ count = 0;
+ continue;
+ }
+
+ text += *from;
+ count++;
+ }
+ return 0;
+}
diff --git a/src/backend/filters/bt_plainhtml.h b/src/backend/filters/bt_plainhtml.h
new file mode 100644
index 0000000..ce1ef36
--- /dev/null
+++ b/src/backend/filters/bt_plainhtml.h
@@ -0,0 +1,33 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BT_PLAINHTML_H
+#define BT_PLAINHTML_H
+
+//Sword includes
+#include <swfilter.h>
+#include <swbuf.h>
+
+class SWKey;
+class SWModule;
+
+namespace Filters {
+
+ /** Plain to HTML filter,
+ * This filter converts Plain Text into HTML
+ */
+class BT_PLAINHTML : public sword::SWFilter{
+protected:
+ virtual char processText(sword::SWBuf& buf, const sword::SWKey*, const sword::SWModule * = 0);
+public:
+ BT_PLAINHTML();
+ };
+}
+
+#endif
diff --git a/src/backend/filters/bt_thmlhtml.cpp b/src/backend/filters/bt_thmlhtml.cpp
new file mode 100644
index 0000000..a5f17d2
--- /dev/null
+++ b/src/backend/filters/bt_thmlhtml.cpp
@@ -0,0 +1,385 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//BibleTime includes
+#include "bt_thmlhtml.h"
+#include "backend/managers/clanguagemgr.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/managers/creferencemanager.h"
+
+#include "backend/config/cbtconfig.h"
+#include "util/cpointers.h"
+#include <boost/scoped_ptr.hpp>
+
+//Sword includes
+#include <swmodule.h>
+#include <utilxml.h>
+#include <versekey.h>
+#include <utilstr.h>
+
+//Qt includes
+#include <QString>
+#include <QRegExp>
+
+Filters::BT_ThMLHTML::BT_ThMLHTML() {
+ setEscapeStringCaseSensitive(true);
+ setPassThruUnknownEscapeString(true); //the HTML widget will render the HTML escape codes
+
+ setTokenStart("<");
+ setTokenEnd(">");
+ setTokenCaseSensitive(true);
+
+ addTokenSubstitute("/foreign", "</span>");
+
+ removeTokenSubstitute("note");
+ removeTokenSubstitute("/note");
+}
+
+char Filters::BT_ThMLHTML::processText(sword::SWBuf& buf, const sword::SWKey* key, const sword::SWModule* module) {
+ sword::ThMLHTML::processText(buf, key, module);
+
+ CSwordModuleInfo* m = CPointers::backend()->findModuleByName( module->Name() );
+
+ if (m && !(m->has(CSwordModuleInfo::lemmas) || m->has(CSwordModuleInfo::strongNumbers))) { //only parse if the module has strongs or lemmas
+ return 1;
+ }
+
+ QString result;
+
+ QString t = QString::fromUtf8(buf.c_str());
+ QRegExp tag("([.,;]?<sync[^>]+(type|value)=\"([^\"]+)\"[^>]+(type|value)=\"([^\"]+)\"([^<]*)>)+");
+
+ QStringList list;
+ int lastMatchEnd = 0;
+ int pos = tag.indexIn(t,0);
+
+ if (pos == -1) { //no strong or morph code found in this text
+ return 1; //WARNING: Return alread here
+ }
+
+ while (pos != -1) {
+ list.append(t.mid(lastMatchEnd, pos+tag.matchedLength()-lastMatchEnd));
+
+ lastMatchEnd = pos+tag.matchedLength();
+ pos = tag.indexIn(t,pos+tag.matchedLength());
+ }
+
+ if (!t.right(t.length() - lastMatchEnd).isEmpty()) {
+ list.append(t.right(t.length() - lastMatchEnd));
+ }
+
+ tag = QRegExp("<sync[^>]+(type|value|class)=\"([^\"]+)\"[^>]+(type|value|class)=\"([^\"]+)\"[^>]+((type|value|class)=\"([^\"]+)\")*([^<]*)>");
+
+ for (QStringList::iterator it = list.begin(); it != list.end(); ++it) {
+ QString e( *it );
+
+ const bool textPresent = (e.trimmed().remove(QRegExp("[.,;:]")).left(1) != "<");
+
+ if (!textPresent) {
+ continue;
+ }
+
+
+ bool hasLemmaAttr = false;
+ bool hasMorphAttr = false;
+
+ int pos = tag.indexIn(e, 0);
+ bool insertedTag = false;
+ QString value;
+ QString valueClass;
+
+ while (pos != -1) {
+ bool isMorph = false;
+ bool isStrongs = false;
+ value = QString::null;
+ valueClass = QString::null;
+
+ // check 3 attribute/value pairs
+
+ for (int i = 1; i < 6; i += 2) {
+ if (i > 4)
+ i++;
+
+ if (tag.cap(i) == "type") {
+ isMorph = (tag.cap(i+1) == "morph");
+ isStrongs = (tag.cap(i+1) == "Strongs");
+ }
+ else if (tag.cap(i) == "value") {
+ value = tag.cap(i+1);
+ }
+ else if (tag.cap(i) == "class") {
+ valueClass = tag.cap(i+1);
+ }
+ }
+
+ // prepend the class qualifier to the value
+ if (!valueClass.isEmpty()) {
+ value = valueClass + ":" + value;
+ // value.append(":").append(value);
+ }
+
+ if (value.isEmpty()) {
+ break;
+ }
+
+ //insert the span
+ if (!insertedTag) {
+ e.replace(pos, tag.matchedLength(), "</span>");
+ pos += 7;
+
+ QString rep = QString("<span lemma=\"").append(value).append("\">");
+ int startPos = 0;
+ QChar c = e[startPos];
+
+ while ((startPos < pos) && (c.isSpace() || c.isPunct())) {
+ ++startPos;
+ c = e[startPos];
+ }
+
+ hasLemmaAttr = isStrongs;
+ hasMorphAttr = isMorph;
+
+ e.insert( startPos, rep );
+ pos += rep.length();
+ }
+ else { //add the attribute to the existing tag
+ e.remove(pos, tag.matchedLength());
+
+ if ((!isMorph && hasLemmaAttr) || (isMorph && hasMorphAttr)) { //we append another attribute value, e.g. 3000 gets 3000|5000
+ //search the existing attribute start
+ QRegExp attrRegExp( isMorph ? "morph=\".+(?=\")" : "lemma=\".+(?=\")" );
+ attrRegExp.setMinimal(true);
+ const int foundAttrPos = e.indexOf(attrRegExp, pos);
+
+ if (foundAttrPos != -1) {
+ e.insert(foundAttrPos + attrRegExp.matchedLength(), QString("|").append(value));
+ pos += value.length() + 1;
+
+ hasLemmaAttr = !isMorph;
+ hasMorphAttr = isMorph;
+ }
+ }
+ else { //attribute was not yet inserted
+ const int attrPos = e.indexOf(QRegExp("morph=|lemma="), 0);
+
+ if (attrPos >= 0) {
+ QString attr;
+ attr.append(isMorph ? "morph" : "lemma").append("=\"").append(value).append("\" ");
+ e.insert(attrPos, attr);
+
+ hasMorphAttr = isMorph;
+ hasLemmaAttr = !isMorph;
+
+ pos += attr.length();
+ }
+ }
+ }
+
+ insertedTag = true;
+ pos = tag.indexIn(e, pos);
+ }
+
+ result.append( e );
+ }
+
+ if (list.count()) {
+ buf = (const char*)result.toUtf8();
+ }
+
+ return 1;
+}
+
+
+bool Filters::BT_ThMLHTML::handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData) {
+ if (!substituteToken(buf, token) && !substituteEscapeString(buf, token)) {
+ sword::XMLTag tag(token);
+ BT_UserData* myUserData = dynamic_cast<BT_UserData*>(userData);
+ sword::SWModule* myModule = const_cast<sword::SWModule*>(myUserData->module); //hack to be able to call stuff like Lang()
+
+ if ( tag.getName() && !sword::stricmp(tag.getName(), "foreign") ) { // a text part in another language, we have to set the right font
+
+ if (tag.getAttribute("lang")) {
+ const char* abbrev = tag.getAttribute("lang");
+ //const CLanguageMgr::Language* const language = CPointers::languageMgr()->languageForAbbrev( QString::fromLatin1(abbrev) );
+
+ buf.append("<span class=\"foreign\" lang=\"");
+ buf.append(abbrev);
+ buf.append("\">");
+ }
+ }
+ else if (tag.getName() && !sword::stricmp(tag.getName(), "sync")) { //lemmas, morph codes or strongs
+
+ if (tag.getAttribute("type") && (!sword::stricmp(tag.getAttribute("type"), "morph") || !sword::stricmp(tag.getAttribute("type"), "Strongs") || !sword::stricmp(tag.getAttribute("type"), "lemma"))) { // Morph or Strong
+ buf.append('<');
+ buf.append(token);
+ buf.append('>');
+ }
+ }
+ else if (tag.getName() && !sword::stricmp(tag.getName(), "note")) { // <note> tag
+
+ if (!tag.isEndTag() && !tag.isEmpty()) {
+ //appending is faster than appendFormatted
+ buf.append(" <span class=\"footnote\" note=\"");
+ buf.append(myModule->Name());
+ buf.append('/');
+ buf.append(myUserData->key->getShortText());
+ buf.append('/');
+ buf.append( QString::number(myUserData->swordFootnote++).toUtf8().constData() );
+ buf.append("\">*</span> ");
+
+ myUserData->suspendTextPassThru = true;
+ myUserData->inFootnoteTag = true;
+ }
+ else if (tag.isEndTag() && !tag.isEmpty()) { //end tag
+ //buf += ")</span>";
+ myUserData->suspendTextPassThru = false;
+ myUserData->inFootnoteTag = false;
+ }
+ }
+ else if (tag.getName() && !sword::stricmp(tag.getName(), "scripRef")) { // a scripRef
+ //scrip refs which are embeded in footnotes may not be displayed!
+
+ if (!myUserData->inFootnoteTag) {
+ if (tag.isEndTag()) {
+ if (myUserData->inscriptRef) { // like "<scripRef passage="John 3:16">See John 3:16</scripRef>"
+ buf.append("</a></span>");
+
+ myUserData->inscriptRef = false;
+ myUserData->suspendTextPassThru = false;
+ }
+ else { // like "<scripRef>John 3:16</scripRef>"
+
+ CSwordModuleInfo* mod = CBTConfig::get(CBTConfig::standardBible);
+ //Q_ASSERT(mod); tested later
+ if (mod) {
+ CReferenceManager::ParseOptions options;
+ options.refBase = QString::fromUtf8(myUserData->key->getText()); //current module key
+ options.refDestinationModule = QString(mod->name());
+ options.sourceLanguage = QString(myModule->Lang());
+ options.destinationLanguage = QString("en");
+
+ //it's ok to split the reference, because to descriptive text is given
+ bool insertSemicolon = false;
+ buf.append("<span class=\"crossreference\">");
+ QStringList refs = QString::fromUtf8(myUserData->lastTextNode.c_str()).split(";");
+ QString oldRef; //the previous reference to use as a base for the next refs
+ for (QStringList::iterator it(refs.begin()); it != refs.end(); ++it) {
+
+ if (! oldRef.isEmpty() ){
+ options.refBase = oldRef; //use the last ref as a base, e.g. Rom 1,2-3, when the next ref is only 3:3-10
+ }
+ const QString completeRef( CReferenceManager::parseVerseReference((*it), options) );
+
+ oldRef = completeRef; //use the parsed result as the base for the next ref.
+
+ if (insertSemicolon) { //prepend a ref divider if we're after the first one
+ buf.append("; ");
+ }
+
+ buf.append("<a href=\"");
+ buf.append(
+ CReferenceManager::encodeHyperlink(
+ mod->name(),
+ completeRef,
+ CReferenceManager::typeFromModule(mod->type())
+ ).toUtf8().constData()
+ );
+
+ buf.append("\" crossrefs=\"");
+ buf.append((const char*)completeRef.toUtf8());
+ buf.append("\">");
+
+ buf.append((const char*)(*it).toUtf8());
+
+ buf.append("</a>");
+
+ insertSemicolon = true;
+ }
+ buf.append("</span>"); //crossref end
+ }
+
+ myUserData->suspendTextPassThru = false;
+ }
+ }
+ else if (tag.getAttribute("passage") ) { //the passage was given as a parameter value
+ myUserData->inscriptRef = true;
+ myUserData->suspendTextPassThru = false;
+
+ const char* ref = tag.getAttribute("passage");
+ Q_ASSERT(ref);
+
+ CSwordModuleInfo* mod = CBTConfig::get(CBTConfig::standardBible);
+ //Q_ASSERT(mod); tested later
+
+ CReferenceManager::ParseOptions options;
+ options.refBase = QString::fromUtf8(myUserData->key->getText());
+
+ options.sourceLanguage = myModule->Lang();
+ options.destinationLanguage = QString("en");
+
+ const QString completeRef = CReferenceManager::parseVerseReference(QString::fromUtf8(ref), options);
+
+ if (mod) {
+ options.refDestinationModule = QString(mod->name());
+ buf.append("<span class=\"crossreference\">");
+ buf.append("<a href=\"");
+ buf.append(
+ CReferenceManager::encodeHyperlink(
+ mod->name(),
+ completeRef,
+ CReferenceManager::typeFromModule(mod->type())
+ ).toUtf8().constData()
+ );
+ buf.append("\" crossrefs=\"");
+ buf.append((const char*)completeRef.toUtf8());
+ buf.append("\">");
+ }
+ else {
+ buf.append("<span><a>");
+ }
+ }
+ else if ( !tag.getAttribute("passage") ) { // we're starting a scripRef like "<scripRef>John 3:16</scripRef>"
+ myUserData->inscriptRef = false;
+
+ // let's stop text from going to output, the text get's added in the -tag handler
+ myUserData->suspendTextPassThru = true;
+ }
+ }
+ }
+ else if (tag.getName() && !sword::stricmp(tag.getName(), "div")) {
+ if (tag.isEndTag()) {
+ buf.append("</div>");
+ }
+ else if ( tag.getAttribute("class") && !sword::stricmp(tag.getAttribute("class"),"sechead") ) {
+ buf.append("<div class=\"sectiontitle\">");
+ }
+ else if (tag.getAttribute("class") && !sword::stricmp(tag.getAttribute("class"), "title")) {
+ buf.append("<div class=\"booktitle\">");
+ }
+ }
+ else if (tag.getName() && !sword::stricmp(tag.getName(), "img") && tag.getAttribute("src")) {
+ const char* value = tag.getAttribute("src");
+
+ if (value[0] == '/') {
+ value++; //strip the first /
+ }
+
+ buf.append("<img src=\"file:");
+ buf.append(myUserData->module->getConfigEntry("AbsoluteDataPath"));
+ buf.append('/');
+ buf.append(value);
+ buf.append("\" />");
+ }
+ else { // let unknown token pass thru
+ return sword::ThMLHTML::handleToken(buf, token, userData);
+ }
+ }
+
+ return true;
+}
diff --git a/src/backend/filters/bt_thmlhtml.h b/src/backend/filters/bt_thmlhtml.h
new file mode 100644
index 0000000..df20472
--- /dev/null
+++ b/src/backend/filters/bt_thmlhtml.h
@@ -0,0 +1,53 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BT_THMLHTML_H
+#define BT_THMLHTML_H
+
+//Sword
+#include <swbuf.h>
+#include <thmlhtml.h>
+
+namespace Filters {
+
+ /** ThML to HTML filter.
+ * This filter converts ThML text to HTML text
+ */
+
+class BT_ThMLHTML : public sword::ThMLHTML {
+
+protected:
+
+class BT_UserData : public sword::ThMLHTML::MyUserData {
+
+public:
+BT_UserData(const sword::SWModule *module, const sword::SWKey *key) : sword::ThMLHTML::MyUserData(module, key) {
+ inscriptRef = false;
+ swordFootnote = 1;
+ inFootnoteTag = false;
+ }
+
+ bool inscriptRef;
+ bool inFootnoteTag;
+ unsigned short int swordFootnote;
+ };
+
+ virtual sword::BasicFilterUserData *createUserData(const sword::SWModule* module, const sword::SWKey* key) {
+ return new BT_UserData(module, key);
+ }
+
+public:
+ BT_ThMLHTML ();
+ virtual bool handleToken(sword::SWBuf& buf, const char *token, sword::BasicFilterUserData *userData);
+ virtual char processText(sword::SWBuf& buf, const sword::SWKey*, const sword::SWModule* = 0);
+ };
+
+}
+
+#endif
diff --git a/src/backend/filters/bt_thmlplain.cpp b/src/backend/filters/bt_thmlplain.cpp
new file mode 100644
index 0000000..e08afb7
--- /dev/null
+++ b/src/backend/filters/bt_thmlplain.cpp
@@ -0,0 +1,221 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+/******************************************************************************
+ *
+ * thmlplain - SWFilter descendant to strip out all ThML tags or convert to
+ * ASCII rendered symbols.
+ */
+
+#include "bt_thmlplain.h"
+
+Filters::BT_ThMLPlain::BT_ThMLPlain() {
+}
+
+char Filters::BT_ThMLPlain::processText(sword::SWBuf &text, const sword::SWKey* /*key*/, const sword::SWModule* /*module*/)
+{
+ char token[2048];
+ int tokpos = 0;
+ bool intoken = false;
+ bool ampersand = false;
+
+ const char *from;
+ sword::SWBuf orig = text;
+ from = orig.c_str();
+ for (text = ""; *from; from++)
+ {
+ if (*from == 10 || *from == 13)
+ from++;
+ if (*from == '<') {
+ intoken = true;
+ tokpos = 0;
+ token[0] = 0;
+ token[1] = 0;
+ token[2] = 0;
+ ampersand = false;
+ continue;
+ }
+ else if (*from == '&') {
+ intoken = true;
+ tokpos = 0;
+ token[0] = 0;
+ token[1] = 0;
+ token[2] = 0;
+ ampersand = true;
+ continue;
+ }
+ if (*from == ';' && ampersand) {
+ intoken = false;
+ ampersand = false;
+
+ if (!strncmp("nbsp", token, 4)) text += " ";
+ else if (!strncmp("quot", token, 4)) text += "\"";
+ else if (!strncmp("amp", token, 3)) text += "&";
+ else if (!strncmp("lt", token, 2)) text += "<";
+ else if (!strncmp("gt", token, 2)) text += ">";
+ else if (!strncmp("brvbar", token, 6)) text += "¦";
+ else if (!strncmp("sect", token, 4)) text += "§";
+ else if (!strncmp("copy", token, 4)) text += "©";
+ else if (!strncmp("laquo", token, 5)) text += "«";
+ else if (!strncmp("reg", token, 3)) text += "®";
+ else if (!strncmp("acute", token, 5)) text += "´";
+ else if (!strncmp("para", token, 4)) text += "¶";
+ else if (!strncmp("raquo", token, 5)) text += "»";
+
+ else if (!strncmp("Aacute", token, 6)) text += "Á";
+ else if (!strncmp("Agrave", token, 6)) text += "À";
+ else if (!strncmp("Acirc", token, 5)) text += "Â";
+ else if (!strncmp("Auml", token, 4)) text += "Ä";
+ else if (!strncmp("Atilde", token, 6)) text += "Ã";
+ else if (!strncmp("Aring", token, 5)) text += "Å";
+ else if (!strncmp("aacute", token, 6)) text += "á";
+ else if (!strncmp("agrave", token, 6)) text += "à";
+ else if (!strncmp("acirc", token, 5)) text += "â";
+ else if (!strncmp("auml", token, 4)) text += "ä";
+ else if (!strncmp("atilde", token, 6)) text += "ã";
+ else if (!strncmp("aring", token, 5)) text += "å";
+ else if (!strncmp("Eacute", token, 6)) text += "É";
+ else if (!strncmp("Egrave", token, 6)) text += "È";
+ else if (!strncmp("Ecirc", token, 5)) text += "Ê";
+ else if (!strncmp("Euml", token, 4)) text += "Ë";
+ else if (!strncmp("eacute", token, 6)) text += "é";
+ else if (!strncmp("egrave", token, 6)) text += "è";
+ else if (!strncmp("ecirc", token, 5)) text += "ê";
+ else if (!strncmp("euml", token, 4)) text += "ë";
+ else if (!strncmp("Iacute", token, 6)) text += "Í";
+ else if (!strncmp("Igrave", token, 6)) text += "Ì";
+ else if (!strncmp("Icirc", token, 5)) text += "Î";
+ else if (!strncmp("Iuml", token, 4)) text += "Ï";
+ else if (!strncmp("iacute", token, 6)) text += "í";
+ else if (!strncmp("igrave", token, 6)) text += "ì";
+ else if (!strncmp("icirc", token, 5)) text += "î";
+ else if (!strncmp("iuml", token, 4)) text += "ï";
+ else if (!strncmp("Oacute", token, 6)) text += "Ó";
+ else if (!strncmp("Ograve", token, 6)) text += "Ò";
+ else if (!strncmp("Ocirc", token, 5)) text += "Ô";
+ else if (!strncmp("Ouml", token, 4)) text += "Ö";
+ else if (!strncmp("Otilde", token, 6)) text += "Õ";
+ else if (!strncmp("oacute", token, 6)) text += "ó";
+ else if (!strncmp("ograve", token, 6)) text += "ò";
+ else if (!strncmp("ocirc", token, 5)) text += "ô";
+ else if (!strncmp("ouml", token, 4)) text += "ö";
+ else if (!strncmp("otilde", token, 6)) text += "õ";
+ else if (!strncmp("Uacute", token, 6)) text += "Ú";
+ else if (!strncmp("Ugrave", token, 6)) text += "Ù";
+ else if (!strncmp("Ucirc", token, 5)) text += "Û";
+ else if (!strncmp("Uuml", token, 4)) text += "Ü";
+ else if (!strncmp("uacute", token, 6)) text += "ú";
+ else if (!strncmp("ugrave", token, 6)) text += "ù";
+ else if (!strncmp("ucirc", token, 5)) text += "û";
+ else if (!strncmp("uuml", token, 4)) text += "ü";
+ else if (!strncmp("Yacute", token, 6)) text += "Ý";
+ else if (!strncmp("yacute", token, 6)) text += "ý";
+ else if (!strncmp("yuml", token, 4)) text += "ÿ";
+
+ else if (!strncmp("deg", token, 3)) text += "°";
+ else if (!strncmp("plusmn", token, 6)) text += "±";
+ else if (!strncmp("sup2", token, 4)) text += "²";
+ else if (!strncmp("sup3", token, 4)) text += "³";
+ else if (!strncmp("sup1", token, 4)) text += "¹";
+ else if (!strncmp("nbsp", token, 4)) text += "º";
+ else if (!strncmp("pound", token, 5)) text += "£";
+ else if (!strncmp("cent", token, 4)) text += "¢";
+ else if (!strncmp("frac14", token, 6)) text += "¼";
+ else if (!strncmp("frac12", token, 6)) text += "½";
+ else if (!strncmp("frac34", token, 6)) text += "¾";
+ else if (!strncmp("iquest", token, 6)) text += "¿";
+ else if (!strncmp("iexcl", token, 5)) text += "¡";
+ else if (!strncmp("ETH", token, 3)) text += "Ð";
+ else if (!strncmp("eth", token, 3)) text += "ð";
+ else if (!strncmp("THORN", token, 5)) text += "Þ";
+ else if (!strncmp("thorn", token, 5)) text += "þ";
+ else if (!strncmp("AElig", token, 5)) text += "Æ";
+ else if (!strncmp("aelig", token, 5)) text += "æ";
+ else if (!strncmp("Oslash", token, 6)) text += "Ø";
+ else if (!strncmp("curren", token, 6)) text += "¤";
+ else if (!strncmp("Ccedil", token, 6)) text += "Ç";
+ else if (!strncmp("ccedil", token, 6)) text += "ç";
+ else if (!strncmp("szlig", token, 5)) text += "ß";
+ else if (!strncmp("Ntilde", token, 6)) text += "Ñ";
+ else if (!strncmp("ntilde", token, 6)) text += "ñ";
+ else if (!strncmp("yen", token, 3)) text += "¥";
+ else if (!strncmp("not", token, 3)) text += "¬";
+ else if (!strncmp("ordf", token, 4)) text += "ª";
+ else if (!strncmp("uml", token, 3)) text += "¨";
+ else if (!strncmp("shy", token, 3)) text += "­";
+ else if (!strncmp("macr", token, 4)) text += "¯";
+ else if (!strncmp("micro", token, 5)) text += "µ";
+ else if (!strncmp("middot", token, 6)) text +="·";
+ else if (!strncmp("cedil", token, 5)) text += "¸";
+ else if (!strncmp("ordm", token, 4)) text += "º";
+ else if (!strncmp("times", token, 5)) text += "×";
+ else if (!strncmp("divide", token, 6)) text +="÷";
+ else if (!strncmp("oslash", token, 6)) text +="ø";
+ continue;
+
+ }
+ else if (*from == '>' && !ampersand) {
+ intoken = false;
+ // process desired tokens
+ if (!strncmp(token, "sync type=\"Strongs\" value=\"", 27)) {
+ text += ' ';
+ text += '<';
+ for (unsigned int i = 27; token[i] != '\"'; i++)
+ text += token[i];
+ text += '>';
+ continue;
+ }
+ if (!strncmp(token, "sync type=\"morph\" value=\"", 25)) {
+ text += ' ';
+ text += '(';
+ for (unsigned int i = 25; token[i] != '\"'; i++)
+ text += token[i];
+ text += ')';
+ continue;
+ }
+ if (!strncmp("note", token, 4)) {
+ text += ' ';
+ text += '(';
+ }
+ else if (!strncmp("br", token, 2))
+ text += '\n';
+ else if (!strncmp("/p", token, 2))
+ text += '\n';
+ else if (!strncmp("/note", token, 5)) {
+ text += ')';
+ text += ' ';
+ }
+ continue;
+ }
+ if (intoken) {
+ if (tokpos < 2045)
+ token[tokpos++] = *from;
+ token[tokpos+2] = 0;
+ }
+ else text += *from;
+ }
+
+ orig = text;
+ from = orig.c_str();
+ for (text = ""; *from; from++) { //loop to remove extra spaces
+ if ((strchr(" \t\n\r", *from))) {
+ while (*(from+1) && (strchr(" \t\n\r", *(from+1)))) {
+ from++;
+ }
+ text += " ";
+ }
+ else {
+ text += *from;
+ }
+ }
+ text += (char)0;
+
+ return 0;
+}
+
diff --git a/src/backend/filters/bt_thmlplain.h b/src/backend/filters/bt_thmlplain.h
new file mode 100644
index 0000000..9d0a0c5
--- /dev/null
+++ b/src/backend/filters/bt_thmlplain.h
@@ -0,0 +1,28 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BT_THMLPLAIN_H
+#define BT_THMLPLAIN_H
+
+#include <swbuf.h>
+#include <swfilter.h>
+
+namespace Filters {
+
+ /** This filter converts ThML text to plain text
+ */
+class BT_ThMLPlain : public sword::SWFilter {
+protected:
+ virtual char processText(sword::SWBuf &text, const sword::SWKey *key = 0, const sword::SWModule *module = 0);
+public:
+ BT_ThMLPlain();
+};
+
+}
+#endif
diff --git a/src/backend/filters/osismorphsegmentation.cpp b/src/backend/filters/osismorphsegmentation.cpp
new file mode 100644
index 0000000..9ec00f7
--- /dev/null
+++ b/src/backend/filters/osismorphsegmentation.cpp
@@ -0,0 +1,83 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+#include "osismorphsegmentation.h"
+
+//Sword
+#include <utilxml.h>
+
+const char Filters::OSISMorphSegmentation::oName[] = "Morph segmentation";
+const char Filters::OSISMorphSegmentation::oTip[] = "Toggles morph segmentation On and Off if they exist";
+
+const sword::SWBuf Filters::OSISMorphSegmentation::choices[3] = {"Off", "On", ""};
+
+const sword::StringList Filters::OSISMorphSegmentation::oValues(&choices[0], &choices[2]);
+
+Filters::OSISMorphSegmentation::OSISMorphSegmentation() : sword::SWOptionFilter(oName, oTip, &oValues) {
+ setOptionValue("Off");
+ }
+
+Filters::OSISMorphSegmentation::~OSISMorphSegmentation() {}
+
+char Filters::OSISMorphSegmentation::processText(sword::SWBuf &text, const sword::SWKey */*key*/, const sword::SWModule */*module*/) {
+ sword::SWBuf token;
+ bool intoken = false;
+ bool hide = false;
+
+ sword::SWBuf orig( text );
+ const char *from = orig.c_str();
+
+ sword::XMLTag tag;
+
+ for (text = ""; *from; ++from) {
+ if (*from == '<') {
+ intoken = true;
+ token = "";
+ continue;
+ }
+
+ if (*from == '>') { // process tokens
+ intoken = false;
+
+ if (!strncmp(token.c_str(), "seg ", 4) || !strncmp(token.c_str(), "/seg", 4)) {
+ tag = token;
+
+ if (!tag.isEndTag() && tag.getAttribute("type") && !strcmp("morph", tag.getAttribute("type"))) { //<seg type="morph"> start tag
+ hide = (option == 0); //only hide if option is Off
+ }
+
+ if (hide) { //hides start and end tags as long as hide is set
+
+ if (tag.isEndTag()) { //</seg>
+ hide = false;
+ }
+
+ continue; //leave out the current token
+ }
+ } //end of seg tag handling
+
+ text.append('<');
+ text.append(token);
+ text.append('>');
+
+ // hide = false; //not right, because there may be child tags in seg. Only /seg may disable the seg hiding.
+
+ continue;
+ } //end of intoken part
+
+ if (intoken) { //copy token
+ token.append(*from);
+ }
+ else { //copy text which is not inside of a tag
+ text.append(*from);
+ }
+ }
+
+ return 0;
+}
+
diff --git a/src/backend/filters/osismorphsegmentation.h b/src/backend/filters/osismorphsegmentation.h
new file mode 100644
index 0000000..e419fe2
--- /dev/null
+++ b/src/backend/filters/osismorphsegmentation.h
@@ -0,0 +1,36 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef OSISMORPHSEGMENTATION_H
+#define OSISMORPHSEGMENTATION_H
+
+#include <swbuf.h>
+#include <swoptfilter.h>
+
+namespace Filters {
+
+/** This Filter shows/hides headings in a OSIS text.
+ * @author Martin Gruner
+ */
+class OSISMorphSegmentation : public sword::SWOptionFilter {
+ static const char oName[];
+ static const char oTip[];
+ static const sword::SWBuf choices[3];
+ static const sword::StringList oValues;
+
+public:
+ OSISMorphSegmentation();
+ virtual ~OSISMorphSegmentation();
+
+ virtual char processText(sword::SWBuf &text, const sword::SWKey *key = 0, const sword::SWModule *module = 0);
+};
+
+}
+
+#endif
diff --git a/src/backend/keys/cswordkey.cpp b/src/backend/keys/cswordkey.cpp
new file mode 100644
index 0000000..acb6da9
--- /dev/null
+++ b/src/backend/keys/cswordkey.cpp
@@ -0,0 +1,185 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cswordkey.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "cswordversekey.h"
+#include "cswordldkey.h"
+#include "cswordtreekey.h"
+
+#include "util/ctoolclass.h"
+
+//Sword
+#include <swmodule.h>
+#include <swkey.h>
+#include <versekey.h>
+#include <treekey.h>
+#include <treekeyidx.h>
+#include <utilstr.h>
+
+//Qt
+#include <QRegExp>
+#include <QString>
+#include <QTextCodec>
+
+CSwordKey::CSwordKey(CSwordModuleInfo* const module) : m_module(module) {}
+
+CSwordKey::CSwordKey(const CSwordKey& k) {
+ m_module = k.m_module;
+}
+
+QString CSwordKey::rawText() {
+ if (!m_module) return QString::null;
+
+ if (dynamic_cast<sword::SWKey*>(this)) {
+ char * buffer = new char[strlen(rawKey()) + 1];
+ strcpy(buffer, rawKey());
+ m_module->module()->getKey()->setText( buffer );
+ delete [] buffer;
+ }
+
+ if (key().isNull()) return QString::null;
+
+ return QString::fromUtf8( m_module->module()->getRawEntry() );
+}
+
+QString CSwordKey::renderedText( const CSwordKey::TextRenderType mode ) {
+ Q_ASSERT(m_module);
+ if (!m_module) {
+ return QString::null;
+ }
+
+ sword::SWKey* const k = dynamic_cast<sword::SWKey*>(this);
+
+ if (k) {
+ char * keyBuffer = new char[strlen(rawKey()) + 1];
+ strcpy(keyBuffer, rawKey());
+ sword::VerseKey* vk_mod = dynamic_cast<sword::VerseKey*>(m_module->module()->getKey());
+
+ if (vk_mod) {
+ vk_mod->Headings(1);
+ }
+
+ m_module->module()->getKey()->setText( keyBuffer );
+
+ if (m_module->type() == CSwordModuleInfo::Lexicon) {
+ m_module->snap();
+ /* In lexicons make sure that our key (e.g. 123) was successfully set to the module,
+ i.e. the module key contains this key (e.g. 0123 contains 123) */
+
+ if ( sword::stricmp(m_module->module()->getKey()->getText(), keyBuffer)
+ && !strstr(m_module->module()->getKey()->getText(), keyBuffer)
+ ) {
+ qDebug("return an empty key for %s", m_module->module()->getKey()->getText());
+ return QString::null;
+ }
+ }
+ delete [] keyBuffer;
+ }
+
+ //Q_ASSERT(!key().isNull());
+ if (!key().isNull()) { //we have valid text
+ QString text = QString::fromUtf8( m_module->module()->RenderText() );
+
+ // This is yucky, but if we want strong lexicon refs we have to do it here.
+ if (m_module->type() == CSwordModuleInfo::Lexicon) {
+ QString t(text);
+ QRegExp rx("(GREEK|HEBREW) for 0*([1-9]\\d*)"); // ignore 0's before number
+ int pos = 0;
+ while( (pos = rx.indexIn(t, pos)) != -1 ) {
+ QString language = rx.cap(1);
+ QString langcode = QString(language.at(0)); // "G" or "H"
+ QString number = rx.cap(2);
+ QString paddednumber = number.rightJustified(5, '0'); // Form 00123
+
+ text.replace(
+ QRegExp( QString(
+ "(>[^<>]+)" // Avoid replacing inside tags
+ "\\b(0*%1)\\b").arg(number) ), // And span around 0's
+ QString("\\1<span lemma=\"%1%2\"><a href=\"strongs://%3/%4\">\\2</a></span>")
+ .arg(langcode, paddednumber, language, paddednumber)
+ );
+ pos += rx.matchedLength();
+ }
+ }
+
+ if (mode == HTMLEscaped) {
+ //we have to encode all UTF-8 in HTML escapes
+ // go though every character and write down the escaped HTML unicode entity
+ // form is &#<decimal unicode value here>;
+ QString ret;
+ QChar c;
+ const unsigned int length = text.length();
+
+ for (unsigned int i = 0; i < length; ++i) {
+ c = text.at(i);
+
+ if (c.toLatin1()) { //normal latin1 character
+ ret.append(c);
+ }
+ else {//unicode character, needs to be escaped
+ ret.append("&#")
+ .append(c.unicode())
+ .append(";");
+ }
+ }
+
+ return ret;
+ }
+ else {
+ return text;
+ }
+ }
+
+ return QString::null;
+}
+
+QString CSwordKey::strippedText() {
+ if (!m_module) return QString::null;
+
+ if (dynamic_cast<sword::SWKey*>(this)) {
+ char * buffer = new char[strlen(rawKey()) + 1];
+ strcpy(buffer, rawKey());
+ m_module->module()->getKey()->setText( buffer );
+ delete [] buffer;
+ }
+
+ return QString::fromUtf8( m_module->module()->StripText() );
+}
+
+const QTextCodec* CSwordKey::cp1252Codec() {
+ static QTextCodec * codec = QTextCodec::codecForName("Windows-1252");
+ return codec;
+}
+
+
+/** This will create a proper key object from a given module */
+CSwordKey* CSwordKey::createInstance( CSwordModuleInfo* const module ) {
+ if (!module) {
+ return 0;
+ }
+
+ switch( module->type() ) {
+
+ case CSwordModuleInfo::Bible://fall through
+
+ case CSwordModuleInfo::Commentary:
+ return new CSwordVerseKey( (sword::VerseKey *) ( (sword::SWKey *)(*module->module()) ), module );
+
+ case CSwordModuleInfo::Lexicon:
+ return new CSwordLDKey( (sword::SWKey *)(*module->module()), module);
+
+ case CSwordModuleInfo::GenericBook:
+ return new CSwordTreeKey( (sword::TreeKeyIdx*)((sword::SWKey *)(*module->module())), module );
+
+ default:
+ return 0;
+ }
+}
diff --git a/src/backend/keys/cswordkey.h b/src/backend/keys/cswordkey.h
new file mode 100644
index 0000000..e0e6300
--- /dev/null
+++ b/src/backend/keys/cswordkey.h
@@ -0,0 +1,111 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CSWORDKEY_H
+#define CSWORDKEY_H
+
+//Qt
+#include <QString>
+
+class CSwordModuleInfo;
+class QTextCodec;
+
+/** Base class for all keys.
+ * The base class for all Sword based keys.
+ * @author The BibleTime team
+ * @version $Id: cswordkey.h,v 1.27 2006/10/30 19:53:32 mgruner Exp $
+ */
+
+class CSwordKey {
+
+protected:
+ /** Constructor. May only be called from sublasses because this class contains pure virtual methods.
+ * @param module The module which belongs to this key, may be NULL
+ */
+ CSwordKey(CSwordModuleInfo* const module = 0); //protected constructor, because CSwordKey shouldn't be used (it's an abstract base class).
+ /** Copy constructor.
+ */
+ CSwordKey(const CSwordKey&); //copy constructor
+
+public:
+ enum TextRenderType {
+ Normal = 0,
+ HTMLEscaped
+ };
+ /** Destructor.
+ * Public, not protected like the constructor, because CSwordKey pointers may be deleted by all others.
+ */
+ virtual ~CSwordKey() {};
+
+ //pure virtual functions
+ /** Returns the current key.
+ * @return The current key which belongs to the current object.
+ */
+ virtual QString key() const = 0;
+ /** Sets the current key. Sets the key using a utf8 enabled QString.
+ * @param key The key which should be used to set the current one
+ */
+ virtual bool key(const QString& key) = 0;
+ /** Set the key using a utf8-decoded c-string
+ * @param key The key which should be used to set the current one
+ */
+ virtual bool key(const char* key) = 0;
+ /** Clone this object. Clone this current object and return it.
+ * @return A clone of the current object.
+ */
+ virtual CSwordKey* copy() const = 0;
+
+ //implemented functions
+ /** Set/get the module. Set and get the module which belongs to this key.
+ * @return The module which belongs to this key.
+ */
+ inline virtual CSwordModuleInfo* module(CSwordModuleInfo* const newModule = 0);
+ /** Returns the raw, unchanged text. Returns the text without any filter modifications,
+ * just in the way it comes out of the module.
+ */
+ virtual QString rawText();
+ /** Returns the rendered text. Returns the text of the current key after passign it through the
+ * modules filters.
+ */
+ virtual QString renderedText( const CSwordKey::TextRenderType mode = CSwordKey::Normal );
+ /** Stripped down text. Returns the text after removing all markup tags from it.
+ */
+ virtual QString strippedText();
+ /**
+ * This returns a new object of the right CSwordKey* implementation
+ * (e.g. CSwordVerseKey or CSwordLDKey)
+ * The type is determined by the type of the module.
+ * @see CSwordModuleInfo, CSwordBibleModuleInfo, CSwordCommentaryModuleInfo, CSwordLexiconModukleInfo
+ */
+ static CSwordKey* createInstance(CSwordModuleInfo * const module);
+
+protected:
+ /**
+ * Returns the encoded key appropriate for use directly with Sword.
+ */
+ virtual const char * rawKey() const = 0;
+ static const QTextCodec* cp1252Codec();
+ CSwordModuleInfo* m_module; //module pointer used by all keys
+
+private:
+ /**
+ * Disable the assignment operator
+ */
+ CSwordKey& operator= ( const CSwordKey & );
+
+};
+
+inline CSwordModuleInfo* CSwordKey::module(CSwordModuleInfo* const newModule) {
+ if (newModule) {
+ m_module = newModule;
+ }
+ return m_module;
+}
+
+#endif
diff --git a/src/backend/keys/cswordldkey.cpp b/src/backend/keys/cswordldkey.cpp
new file mode 100644
index 0000000..3205827
--- /dev/null
+++ b/src/backend/keys/cswordldkey.cpp
@@ -0,0 +1,118 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cswordldkey.h"
+#include "backend/drivers/cswordlexiconmoduleinfo.h"
+
+//Sword includes
+#include <swmodule.h>
+#include <swld.h>
+#include <utilstr.h>
+
+//Qt includes
+#include <QTextCodec>
+
+CSwordLDKey::CSwordLDKey( CSwordModuleInfo* module ) {
+ if ((m_module = dynamic_cast<CSwordLexiconModuleInfo*>(module))) {
+ // *(m_module->module()) = TOP;
+ }
+
+ SWKey::operator= (" ");
+}
+
+/** No descriptions */
+CSwordLDKey::CSwordLDKey( const CSwordLDKey &k ) : CSwordKey(k), SWKey((const char*)k) {}
+
+/** No descriptions */
+CSwordLDKey::CSwordLDKey( const SWKey *k, CSwordModuleInfo* module) : CSwordKey(module), SWKey(*k) {}
+
+/** Clones this object by copying the members. */
+CSwordLDKey* CSwordLDKey::copy() const {
+ return new CSwordLDKey(*this);
+}
+
+/** Sets the module of this key. */
+CSwordModuleInfo* CSwordLDKey::module(CSwordModuleInfo* const newModule) {
+ if (newModule && newModule->type() == CSwordModuleInfo::Lexicon) {
+ const QString oldKey = key();
+ m_module = newModule;
+ key(oldKey);
+ }
+
+ return m_module;
+}
+
+QString CSwordLDKey::key() const {
+ //return QString::fromUtf8((const char*)*this);
+ Q_ASSERT(m_module);
+
+ if (m_module->isUnicode()) {
+ return QString::fromUtf8((const char*)*this);
+ } else {
+ return cp1252Codec()->toUnicode((const char*)*this);
+ }
+}
+
+const char * CSwordLDKey::rawKey() const {
+ return (const char*)*this;
+}
+
+bool CSwordLDKey::key( const QString& newKey ) {
+ Q_ASSERT(m_module);
+
+ if (m_module->isUnicode()) {
+ return key(newKey.toUtf8().constData());
+ } else {
+ return key((const char*)cp1252Codec()->fromUnicode(newKey));
+ }
+}
+
+
+/** Sets the key of this instance */
+bool CSwordLDKey::key( const char* newKey ) {
+ Q_ASSERT(newKey);
+
+ if (newKey) {
+ SWKey::operator = (newKey); //set the key
+ m_module->module()->SetKey(this);
+ m_module->snap();
+ }
+
+ return !Error();
+}
+
+/** Uses the parameter to returns the next entry afer this key. */
+CSwordLDKey* CSwordLDKey::NextEntry() {
+ m_module->module()->SetKey(this); //use this key as base for the next one!
+ // m_module->module()->getKey()->setText( (const char*)key().utf8() );
+
+ m_module->module()->setSkipConsecutiveLinks(true);
+ ( *( m_module->module() ) )++;
+ m_module->module()->setSkipConsecutiveLinks(false);
+
+ key(m_module->module()->KeyText());
+ SWKey::operator = (m_module->module()->KeyText());
+
+ return this;
+}
+
+/** Uses the parameter to returns the next entry afer this key. */
+CSwordLDKey* CSwordLDKey::PreviousEntry() {
+ m_module->module()->SetKey(this); //use this key as base for the next one!
+ // m_module->module()->getKey()->setText( (const char*)key().utf8() );
+
+ m_module->module()->setSkipConsecutiveLinks(true);
+ ( *( m_module->module() ) )--;
+ m_module->module()->setSkipConsecutiveLinks(false);
+
+ SWKey::operator = (m_module->module()->KeyText());
+
+ return this;
+}
+
diff --git a/src/backend/keys/cswordldkey.h b/src/backend/keys/cswordldkey.h
new file mode 100644
index 0000000..0349597
--- /dev/null
+++ b/src/backend/keys/cswordldkey.h
@@ -0,0 +1,110 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CSWORDLDKEY_H
+#define CSWORDLDKEY_H
+
+#include "cswordkey.h"
+class CSwordModuleInfo;
+
+//Qt
+#include <QString>
+
+//Sword includes
+#include <swkey.h>
+
+/**
+ * This class is the implementation of CSwordKey used for dictionaries and lexicons.
+ *
+ * CSwordLDKey is the implementation of CKey for Lexicons and dictionaries.
+ * It provides a simple interface to set the current key,
+ * to get the text for the key and functions to get the next and previous items
+ * of the used module in comparision to the current key.<BR>
+ * Here's an example how to use this class:<BR>
+ * @code
+ * CSwordLexiconModuleInfo* m_module = backend()->findModuleByName("ISBE");
+ * CSwordLDKey ldKey(m_module);
+ * ldKey.key("Adam");
+ * ldKey.nextEntry();
+ * qDebug( QString("The current key is: %1").arg(ldKey.key()));
+ * @endcode
+ *
+ * Please not, that the result will be invalid if use the operator const char*
+ * on the adress of the object, use something like this
+ *
+ * @code
+ * CSwordLDKey* key = new CSwordLDKey( lexicon_module );
+ * const QString keyname = key->getKey();
+ * @endcode
+ *
+ * @author The BibleTime team
+ * @version $Id: cswordldkey.h,v 1.24 2006/02/25 11:38:15 joachim Exp $
+ */
+
+class CSwordLDKey : public CSwordKey, public sword::SWKey {
+
+public:
+ /**
+ * Constructor of CSwordLDKey
+ */
+ CSwordLDKey( CSwordModuleInfo* module );
+ /**
+ * Copy constructor for this key class.
+ */
+ CSwordLDKey( const CSwordLDKey &k );
+ /**
+ * Copy constructor for this key class.
+ */
+ CSwordLDKey( const sword::SWKey *k, CSwordModuleInfo* module);
+ /**
+ * Clones this object by copying the members.
+ */
+ virtual CSwordLDKey* copy() const;
+ /**
+ * Uses the parameter to returns the next entry afer this key.
+ */
+ CSwordLDKey* NextEntry( void );
+ /**
+ * Uses the parameter to returns the previous entry afer this key.
+ */
+ CSwordLDKey* PreviousEntry( void );
+ /**
+ * Sets the module of this key.
+ */
+ virtual CSwordModuleInfo* module( CSwordModuleInfo* const module = 0 );
+ /**
+ * Returns the current key as a QString
+ */
+ virtual QString key() const;
+ /**
+ * Set the current key using unicode decoded QString.
+ */
+ virtual bool key( const QString& newKey );
+ /**
+ * Set the current key from char*. To avoid encoding problems use key(QString) instead.
+ */
+ virtual bool key( const char* );
+
+protected:
+ /**
+ * Returns the raw key appropriate for use directly with Sword.
+ */
+ virtual const char* rawKey() const;
+
+private:
+ /**
+ * Disable assignment operator
+ */
+ CSwordLDKey& operator= (const CSwordLDKey& );
+
+};
+
+
+#endif
+
diff --git a/src/backend/keys/cswordtreekey.cpp b/src/backend/keys/cswordtreekey.cpp
new file mode 100644
index 0000000..6e02806
--- /dev/null
+++ b/src/backend/keys/cswordtreekey.cpp
@@ -0,0 +1,93 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cswordtreekey.h"
+#include "backend/drivers/cswordbookmoduleinfo.h"
+
+#include <QTextCodec>
+
+#include <QDebug>
+
+CSwordTreeKey::CSwordTreeKey( const CSwordTreeKey& k ) : CSwordKey(k), TreeKeyIdx(k) {}
+
+CSwordTreeKey::CSwordTreeKey( const TreeKeyIdx *k, CSwordModuleInfo* module ) : CSwordKey(module), TreeKeyIdx(*k) {}
+
+CSwordTreeKey* CSwordTreeKey::copy() const {
+ return new CSwordTreeKey(*this);
+}
+
+/** Sets the key of this instance */
+QString CSwordTreeKey::key() const {
+ //return getTextUnicode();
+ Q_ASSERT(m_module);
+ if (m_module->isUnicode()) {
+ return QString::fromUtf8(getText());
+ } else {
+ return cp1252Codec()->toUnicode(getText());
+ }
+}
+
+const char * CSwordTreeKey::rawKey() const {
+ return getText();
+}
+
+bool CSwordTreeKey::key( const QString& newKey ) {
+ //return key( newKey.toLocal8Bit().constData() );
+ //return key(m_module->getTextCodec()->fromUnicode(newKey).constData());
+ Q_ASSERT(m_module);
+ if (m_module->isUnicode()) {
+ return key(newKey.toUtf8().constData());
+ } else {
+ return key((const char*)cp1252Codec()->fromUnicode(newKey));
+ }
+}
+
+bool CSwordTreeKey::key( const char* newKey ) {
+ Q_ASSERT(newKey);
+
+ if (newKey) {
+ TreeKeyIdx::operator = (newKey);
+ }
+ else {
+ root();
+ }
+
+ return !Error();
+}
+
+QString CSwordTreeKey::getLocalNameUnicode()
+{
+ //return m_module->getTextCodec()->toUnicode(getLocalName());
+ //Only UTF-8 and latin1 are legal Sword module encodings
+ Q_ASSERT(m_module);
+ if (m_module->isUnicode()) {
+ return QString::fromUtf8(getLocalName());
+ } else {
+ return cp1252Codec()->toUnicode(getLocalName());
+ }
+}
+
+CSwordModuleInfo* CSwordTreeKey::module( CSwordModuleInfo* const newModule ) {
+ if (newModule && (newModule != m_module) && (newModule->type() == CSwordModuleInfo::GenericBook) ) {
+ m_module = newModule;
+
+ const QString oldKey = key();
+
+ CSwordBookModuleInfo* newBook = dynamic_cast<CSwordBookModuleInfo*>(newModule);
+ copyFrom( *(newBook->tree()) );
+
+ key(oldKey); //try to restore our old key
+
+ //set the key to the root node
+ root();
+ firstChild();
+ }
+
+ return m_module;
+}
diff --git a/src/backend/keys/cswordtreekey.h b/src/backend/keys/cswordtreekey.h
new file mode 100644
index 0000000..4114652
--- /dev/null
+++ b/src/backend/keys/cswordtreekey.h
@@ -0,0 +1,79 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CSWORDTREEKEYIDX_H
+#define CSWORDTREEKEYIDX_H
+
+//BibleTime
+#include "cswordkey.h"
+
+//Sword
+#include <treekeyidx.h>
+
+class CSwordModuleInfo;
+
+/** BibleTime's implementation of Sword's TreeKeyIdx class.
+ * @short CSwordKey implementation for Sword's TreeKey
+ * @author The BibleTime team
+ */
+
+class CSwordTreeKey : public CSwordKey, public sword::TreeKeyIdx {
+
+public:
+ /** Constructor of this CSwordKey implementation.
+ * @param k The Sword tree key which belongs to this key
+ * @param module The module which belongs to this key
+ */
+ CSwordTreeKey( const sword::TreeKeyIdx *k, CSwordModuleInfo* module );
+ /** Copy constructor.
+ */
+ CSwordTreeKey( const CSwordTreeKey& k );
+ /** The module which belongs to this key.
+ * @return The module.
+ */
+ virtual CSwordModuleInfo* module( CSwordModuleInfo* const newModule );
+ /** Copy method.
+ * @return A new copy of this object.
+ */
+ virtual CSwordTreeKey* copy() const;
+
+ /**
+ * Returns the TreeKeyIdx::getLocalKey value in unicode.
+ * Local key is the last part of the tree key, for example "Subsection1" from "/Section1/Subsection1".
+ * Use this instead of getLocalKey() to avoid encoding problems.
+ */
+ QString getLocalNameUnicode();
+ /**
+ * Returns the current key as unicode decoded QString.
+ */
+ virtual QString key() const;
+ /**
+ * Set the key. If the parameter is empty or null, the key will be set to "/"
+ */
+ virtual bool key( const QString& key );
+ /**
+ * Set the key from char* To avoid encoding problems use key(QString instead),
+ * otherwise it is caller's responsibility to ensure the correct encoding (utf8/latin1).
+ */
+ virtual bool key( const char* key );
+
+protected:
+ /**
+ * Returns the raw key appropriate for use directly with Sword.
+ */
+ virtual const char * rawKey() const;
+
+private:
+ /** Disable assignment operator */
+ CSwordTreeKey& operator= (const CSwordTreeKey&);
+ /** Disable from base class to prevent compiler warnings */
+ inline virtual CSwordTreeKey& operator= (const sword::TreeKeyIdx&) { return (*this); };
+};
+
+#endif
diff --git a/src/backend/keys/cswordversekey.cpp b/src/backend/keys/cswordversekey.cpp
new file mode 100644
index 0000000..424b268
--- /dev/null
+++ b/src/backend/keys/cswordversekey.cpp
@@ -0,0 +1,303 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cswordversekey.h"
+#include "backend/drivers/cswordbiblemoduleinfo.h"
+#include "backend/drivers/cswordcommentarymoduleinfo.h"
+
+//Qt
+#include <QStringList>
+
+//Sword
+#include <swmodule.h>
+#include <localemgr.h>
+
+CSwordVerseKey::CSwordVerseKey( CSwordModuleInfo* const module ) : CSwordKey(module) {
+ if ( CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module) ) {
+ key( bible->lowerBound().key() );
+ }
+}
+
+CSwordVerseKey::CSwordVerseKey( const CSwordVerseKey& k ) : CSwordKey(k), VerseKey(k) {}
+
+CSwordVerseKey::CSwordVerseKey( const VerseKey* const k, CSwordModuleInfo* const module ) : CSwordKey(module), VerseKey(*k) {}
+
+/** Clones this object. */
+CSwordKey* CSwordVerseKey::copy() const {
+ return new CSwordVerseKey(*this);
+}
+
+/** Sets the module for this key */
+CSwordModuleInfo* CSwordVerseKey::module( CSwordModuleInfo* const newModule ) {
+ if (newModule && ((newModule->type() == CSwordModuleInfo::Bible) || (newModule->type() == CSwordModuleInfo::Commentary) ) ) {
+ m_module = newModule;
+
+ //check if the module contains the key we present
+ CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(newModule);
+
+ if (_compare(bible->lowerBound()) < 0) {
+ key( bible->lowerBound() );
+ }
+
+ if (_compare(bible->upperBound()) > 0) {
+ key( bible->upperBound() );
+ }
+ }
+
+ return dynamic_cast<CSwordBibleModuleInfo*>(m_module);
+}
+
+/** Returns the current book as Text, not as integer. */
+QString CSwordVerseKey::book( const QString& newBook ) {
+ int min = 0;
+ int max = 1;
+
+ if (CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module())) {
+ const bool hasOT = bible->hasTestament(CSwordBibleModuleInfo::OldTestament);
+ const bool hasNT = bible->hasTestament(CSwordBibleModuleInfo::NewTestament);
+
+ if (hasOT && hasNT) {
+ min = 0;
+ max = 1;
+ }
+ else if (hasOT && !hasNT) {
+ min = 0;
+ max = 0;
+ }
+ else if (!hasOT && hasNT) {
+ min = 1;
+ max = 1;
+ }
+ else if (!hasOT && !hasNT) {
+ min = 0;
+ max = -1; //no loop
+ }
+ }
+
+ if (!newBook.isEmpty()) {
+
+#ifdef SWORD_MULTIVERSE
+ setBookName(newBook.toUtf8().constData());
+#else
+
+ bool finished = false;
+
+ for (int testament = min; testament <= max && !finished; ++testament) {
+ for (int book = 0; book < BMAX[testament] && !finished; ++book) {
+ if ( !strcmp(newBook.toUtf8().constData(), books[testament][book].name ) ) {
+ Testament(testament+1);
+ Book(book+1);
+ finished = true;
+ }
+ }
+ }
+#endif
+ }
+
+ if ( (Testament() >= min+1) && (Testament() <= max+1) && (Book() <= BMAX[min]) ) {
+ return QString::fromUtf8( getBookName() );
+ }
+
+ //return QString::fromUtf8( books[min][0].name ); //return the first book, i.e. Genesis
+ return QString::null;
+}
+
+/** Sets the key we use to the parameter. */
+QString CSwordVerseKey::key() const {
+ return QString::fromUtf8(getText());
+}
+
+const char * CSwordVerseKey::rawKey() const {
+ return getText();
+}
+
+bool CSwordVerseKey::key( const QString& newKey ) {
+ return key( newKey.toUtf8().constData() );
+}
+
+bool CSwordVerseKey::key( const char* newKey ) {
+ if (newKey && (strlen(newKey)>0) ) {
+ VerseKey::operator = (newKey);
+ }
+ else if (newKey && !strlen(newKey)) {
+ CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module());
+
+ if ( bible ) {
+ VerseKey::operator = (bible->lowerBound().key().toUtf8().constData());
+ }
+ }
+
+ return !Error();
+}
+
+bool CSwordVerseKey::next( const JumpType type ) {
+ Error(); //clear Error status
+ bool ret = true;
+
+ switch (type) {
+
+ case UseBook: {
+ const int currentTestament = Testament();
+ const int currentBook = Book();
+
+ if ((currentTestament == 2) && (currentBook >= BMAX[currentTestament-1])) { //Revelation, i.e. end of navigation
+ return false;
+ }
+ else if ((currentTestament == 1) && (currentBook >= BMAX[currentTestament-1])) { //Malachi, switch to the NT
+ Testament(currentTestament+1);
+ Book(1);
+ }
+ else {
+ Book(Book()+1);
+ }
+ break;
+ }
+
+ case UseChapter: {
+ Chapter(Chapter()+1);
+ break;
+ }
+
+ case UseVerse: {
+ if (m_module && m_module->module()) {
+ const bool oldStatus = m_module->module()->getSkipConsecutiveLinks();
+ m_module->module()->setSkipConsecutiveLinks(true);
+
+ //disable headings for next verse
+ const bool useHeaders = (Verse() == 0);
+ const bool oldHeadingsStatus = ((VerseKey*)(m_module->module()->getKey()))->Headings( useHeaders );
+ //don't use setKey(), that would create a new key without Headings set
+ m_module->module()->getKey()->setText( key().toUtf8().constData() );
+
+ (*(m_module->module()) )++;
+
+ ((VerseKey*)(m_module->module()->getKey()))->Headings(oldHeadingsStatus);
+ m_module->module()->setSkipConsecutiveLinks(oldStatus);
+
+ if (!m_module->module()->Error()) {
+ key( QString::fromUtf8(m_module->module()->KeyText()) );
+ }
+ else {
+ // Verse(Verse()+1);
+ //don't change the key, restore the module's position
+ m_module->module()->getKey()->setText( key().toUtf8().constData() );
+ ret = false;
+ break;
+ }
+
+ }
+ else {
+ Verse(Verse()+1);
+ }
+
+ break;
+ }
+
+ default:
+ return false;
+ }
+
+ if ( CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module()) ) {
+ if (_compare(bible->lowerBound()) < 0 ) {
+ key( bible->lowerBound() );
+ ret = false;
+ }
+
+ if (_compare(bible->upperBound()) > 0 ) {
+ key( bible->upperBound() );
+ ret = false;
+ }
+
+ return ret;
+ }
+ else if (Error()) { //we have no module, so take care of VerseKey::Error()
+ return false;
+ }
+
+ return ret;
+}
+
+bool CSwordVerseKey::previous( const JumpType type ) {
+ bool ret = true;
+
+ switch (type) {
+
+ case UseBook: {
+ if ( (Book() == 1) && (Testament() == 1) ) { //Genesis
+ return false;
+ }
+ else if ( (Book() == 1) && (Testament() == 2) ){ //Matthew
+ Testament(1);
+ Book(BMAX[0]);
+ }
+ else{
+ Book( Book()-1 );
+ }
+
+ break;
+ }
+
+ case UseChapter: {
+ Chapter(Chapter()-1);
+ break;
+ }
+
+ case UseVerse: {
+ if (m_module && m_module->module()) {
+ const bool useHeaders = (Verse() == 0);
+ const bool oldHeadingsStatus = ((VerseKey*)(m_module->module()->getKey()))->Headings( useHeaders );
+
+ m_module->module()->getKey()->setText( key().toUtf8().constData() );
+
+ const bool oldStatus = m_module->module()->getSkipConsecutiveLinks();
+ m_module->module()->setSkipConsecutiveLinks(true);
+ ( *( m_module->module() ) )--;
+
+ ((VerseKey*)(m_module->module()->getKey()))->Headings( oldHeadingsStatus );
+ m_module->module()->setSkipConsecutiveLinks(oldStatus);
+
+ if (!m_module->module()->Error()) {
+ key( QString::fromUtf8(m_module->module()->KeyText()) );//don't use fromUtf8
+ }
+ else {
+ ret = false;
+ // Verse(Verse()-1);
+ m_module->module()->getKey()->setText( key().toUtf8().constData() ); //restore module's key
+ }
+ }
+ else {
+ Verse(Verse()-1);
+ }
+
+ break;
+ }
+
+ default:
+ return false;
+ }
+
+ if ( CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module()) ) {
+ if (_compare(bible->lowerBound()) < 0 ) {
+ key( bible->lowerBound() );
+ ret = false;
+ }
+
+ if (_compare(bible->upperBound()) > 0 ) {
+ key( bible->upperBound() );
+ ret = false;
+ }
+
+ return ret;
+ }
+ else if (Error()) {
+ return false;
+ }
+
+ return ret;
+}
diff --git a/src/backend/keys/cswordversekey.h b/src/backend/keys/cswordversekey.h
new file mode 100644
index 0000000..e421b6c
--- /dev/null
+++ b/src/backend/keys/cswordversekey.h
@@ -0,0 +1,122 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CSWORDVERSEKEY_H
+#define CSWORDVERSEKEY_H
+
+#include "cswordkey.h"
+class CSwordModuleInfo;
+
+//Qt
+#include <QString>
+
+//Sword
+#include <versekey.h>
+
+/**
+ * The CSwordKey implementation for verse based modules (Bibles and Commentaries)
+ *
+ * This class is the implementation of CKey for verse based modules like
+ * Bibles and commentaries.
+ * This class provides the special functions to work with the verse based modules.
+ *
+ * Useful functions are
+ * @see NextBook()
+ * @see PreviousBook()
+ * @see NextChapter()
+ * @see PreviousChapter()
+ * @see NextVerse()
+ * @see PreviousVerse().
+ *
+ * Call the constructor only with a valid verse based modules, otherwise this key will be invalid
+ * and the application will probably crash.
+ *
+ * @version $Id: cswordversekey.h,v 1.26 2006/02/25 11:38:15 joachim Exp $
+ * @short CSwordKey implementation for Sword's VerseKey.
+ * @author The BibleTime team
+ */
+
+class CSwordVerseKey : public CSwordKey, public sword::VerseKey {
+
+public:
+ enum JumpType {
+ UseBook,
+ UseChapter,
+ UseVerse
+ };
+
+ /**
+ * Constructor of this class.
+ *
+ * This function will construct a versekey with the current module position
+ * and it will setup the m_module members.
+ *
+ */
+ CSwordVerseKey( CSwordModuleInfo* const module );
+ /**
+ * Copy constructor.
+ */
+ CSwordVerseKey( const CSwordVerseKey& k );
+ /**
+ * VerseKey based constructor.
+ */
+ CSwordVerseKey( const sword::VerseKey* const k, CSwordModuleInfo* const module );
+ /**
+ * Clones this object.
+ */
+ virtual CSwordKey* copy() const;
+ /**
+ * Set/get the key. If the parameter is not set (means equal to QString::null)
+ * the used key is returned. Otherwise the key is set and the new on ei returned.
+ */
+ virtual QString key() const;
+ /**
+ * Set the current key.
+ */
+ virtual bool key( const QString& );
+ /**
+ * Set/get the key. If the parameter is not set (means equal to QString::null)
+ * the used key is returned. Otherwise the key is set and the new on ei returned.
+ */
+ virtual bool key( const char* key );
+
+ /**
+ * Jumps to the next entry of the given type
+ */
+ bool next( const JumpType type );
+ /**
+ * Jumps to the previous entry of the given type
+ */
+ bool previous ( const JumpType type );
+ /**
+ * This functions returns the current book as localised text, not as book numer.
+ *
+ * Use "char Book()" to retrieve the book number of the current book.
+ * @return The name of the current book
+ */
+ QString book(const QString& newBook = QString::null);
+ /**
+ * Sets the module for this key
+ */
+ virtual CSwordModuleInfo* module( CSwordModuleInfo* const newModule = 0 );
+
+protected:
+ /**
+ * Returns the raw key appropriate for use directly with Sword.
+ */
+ virtual const char * rawKey() const;
+
+private:
+ /** Disable assignment operator */
+ CSwordVerseKey& operator= (const CSwordVerseKey&);
+ /** Disable from base class to prevent compiler warnings */
+ inline virtual CSwordVerseKey& operator= (const sword::VerseKey&) { return (*this); };
+};
+
+#endif
diff --git a/src/backend/managers/btstringmgr.cpp b/src/backend/managers/btstringmgr.cpp
new file mode 100644
index 0000000..9f57258
--- /dev/null
+++ b/src/backend/managers/btstringmgr.cpp
@@ -0,0 +1,139 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btstringmgr.h"
+
+char* BTStringMgr::upperUTF8(char* text, unsigned int maxlen) const {
+ const int max = (maxlen>0) ? maxlen : strlen(text);
+
+ if (isUtf8(text)) {
+ strncpy(text, (const char*)QString::fromUtf8(text).toUpper().toUtf8(), max);
+
+ return text;
+ }
+ else {
+ char* ret = text;
+
+ while (*text) {
+ *text = toupper(*text);
+ text++;
+ }
+
+ return ret;
+ }
+
+ return text;
+}
+
+char* BTStringMgr::upperLatin1(char* text, unsigned int /*max*/) const {
+ char* ret = text;
+
+ while (*text) {
+ *text = toupper(*text);
+ text++;
+ }
+
+ return ret;
+}
+
+bool BTStringMgr::supportsUnicode() const {
+ return true;
+}
+
+bool BTStringMgr::isUtf8(const char *buf) const {
+ int i, n;
+ register unsigned char c;
+ bool gotone = false;
+
+ #define F 0 /* character never appears in text */
+ #define T 1 /* character appears in plain ASCII text */
+ #define I 2 /* character appears in ISO-8859 text */
+ #define X 3 /* character appears in non-ISO extended ASCII (Mac, IBM PC) */
+
+ static const unsigned char text_chars[256] = {
+ /* BEL BS HT LF FF CR */
+ F, F, F, F, F, F, F, T, T, T, T, F, T, T, F, F, /* 0x0X */
+ /* ESC */
+ F, F, F, F, F, F, F, F, F, F, F, T, F, F, F, F, /* 0x1X */
+ T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x2X */
+ T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x3X */
+ T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x4X */
+ T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x5X */
+ T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x6X */
+ T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, F, /* 0x7X */
+ /* NEL */
+ X, X, X, X, X, T, X, X, X, X, X, X, X, X, X, X, /* 0x8X */
+ X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, /* 0x9X */
+ I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xaX */
+ I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xbX */
+ I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xcX */
+ I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xdX */
+ I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xeX */
+ I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I /* 0xfX */
+ };
+
+ /* *ulen = 0; */
+
+ for (i = 0; (c = buf[i]); i++) {
+ if ((c & 0x80) == 0) { /* 0xxxxxxx is plain ASCII */
+ /*
+ * Even if the whole file is valid UTF-8 sequences,
+ * still reject it if it uses weird control characters.
+ */
+
+ if (text_chars[c] != T)
+ return false;
+
+ }
+ else if ((c & 0x40) == 0) { /* 10xxxxxx never 1st byte */
+ return false;
+ }
+ else { /* 11xxxxxx begins UTF-8 */
+ int following;
+
+ if ((c & 0x20) == 0) { /* 110xxxxx */
+ following = 1;
+ }
+ else if ((c & 0x10) == 0) { /* 1110xxxx */
+ following = 2;
+ }
+ else if ((c & 0x08) == 0) { /* 11110xxx */
+ following = 3;
+ }
+ else if ((c & 0x04) == 0) { /* 111110xx */
+ following = 4;
+ }
+ else if ((c & 0x02) == 0) { /* 1111110x */
+ following = 5;
+ }
+ else
+ return false;
+
+ for (n = 0; n < following; n++) {
+ i++;
+
+ if (!(c = buf[i]))
+ goto done;
+
+ if ((c & 0x80) == 0 || (c & 0x40))
+ return false;
+ }
+
+ gotone = true;
+ }
+ }
+
+done:
+ return gotone; /* don't claim it's UTF-8 if it's all 7-bit */
+}
+
+#undef F
+#undef T
+#undef I
+#undef X
diff --git a/src/backend/managers/btstringmgr.h b/src/backend/managers/btstringmgr.h
new file mode 100644
index 0000000..d202c7f
--- /dev/null
+++ b/src/backend/managers/btstringmgr.h
@@ -0,0 +1,53 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTSTRINGMGR_H
+#define BTSTRINGMGR_H
+
+//Sword includes
+#include <stringmgr.h>
+
+//Qt includes
+#include <QString>
+
+/** Unicode string manager implementation.
+ * This is the StringManager implementation which works with QString.
+ * @author The BibleTime developers
+ */
+
+class BTStringMgr : public sword::StringMgr {
+
+public:
+ /** Converts the param to an upper case Utf8 string
+ * @param The text encoded in utf8 which should be turned into an upper case string
+ */
+ virtual char *upperUTF8(char *text, unsigned int max = 0) const;
+
+ /** Converts the param to an uppercase latin1 string
+ * @param The text encoded in latin1 which should be turned into an upper case string
+ */
+ virtual char *upperLatin1(char *text, unsigned int max = 0) const;
+
+protected:
+ /** Enable Unicode support.
+ * Reimplementation to show unicode support.
+ */
+ virtual bool supportsUnicode() const;
+
+ /** CODE TAKEN FROM KDELIBS 3.2, which is licensed under the LGPL 2.
+ *
+ * This code was taken from KStringHandler, which is part of the KDE libraries.
+ *
+ * This function checks whether a string is utf8 or not.
+ * It was taken from kdelibs so we do not depend on KDE 3.2.
+ */
+ bool isUtf8(const char *buf) const;
+};
+
+#endif
diff --git a/src/backend/managers/cdisplaytemplatemgr.cpp b/src/backend/managers/cdisplaytemplatemgr.cpp
new file mode 100644
index 0000000..6ddd6b7
--- /dev/null
+++ b/src/backend/managers/cdisplaytemplatemgr.cpp
@@ -0,0 +1,170 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cdisplaytemplatemgr.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/managers/clanguagemgr.h"
+#include "backend/config/cbtconfig.h"
+#include "util/cpointers.h"
+#include "util/directoryutil.h"
+
+//Qt
+#include <QStringList>
+#include <QFile>
+#include <QFileInfo>
+#include <QTextStream>
+#include <QDebug>
+
+CDisplayTemplateMgr::CDisplayTemplateMgr() {
+ loadTemplates();
+}
+
+CDisplayTemplateMgr::~CDisplayTemplateMgr() {
+}
+
+const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QString& content, Settings& settings )
+{
+ qDebug() << "CDisplayTemplateMgr::fillTemplate";
+
+ const QString templateName = m_templateMap.contains(name) ? name : defaultTemplate();
+
+ QString displayTypeString;
+
+ if (!settings.pageCSS_ID.isEmpty()) {
+ displayTypeString = settings.pageCSS_ID;
+ }
+ else {
+ if (settings.modules.count()) {
+ switch (settings.modules.first()->type()) {
+
+ case CSwordModuleInfo::Bible:
+ displayTypeString = "bible";
+ break;
+
+ case CSwordModuleInfo::GenericBook:
+ displayTypeString = "book";
+ break;
+
+ case CSwordModuleInfo::Commentary:
+ case CSwordModuleInfo::Lexicon:
+ default:
+ displayTypeString = "singleentry";
+ break;
+ };
+ }
+ else { //use bible as default type if no modules are set
+ displayTypeString = "bible";
+ };
+ }
+
+ QString newContent = content;
+ const int moduleCount = settings.modules.count();
+
+ if (moduleCount >= 2) {
+ //create header for the modules
+ qDebug("There were more than 1 module, create headers");
+ QString header;
+
+ QList<CSwordModuleInfo*>::iterator end_it = settings.modules.end();
+
+ for (QList<CSwordModuleInfo*>::iterator it(settings.modules.begin()); it != end_it; ++it) {
+ header.append("<th style=\"width:")
+ .append(QString::number(int( 100.0 / (float)moduleCount )))
+ .append("%;\">")
+ .append((*it)->name())
+ .append("</th>");
+ }
+
+ newContent = QString("<table><tr>")
+ .append(header)
+ .append("</tr>")
+ .append(content)
+ .append("</table>");
+ }
+
+ QString langCSS;
+ CLanguageMgr::LangMap langMap = CPointers::languageMgr()->availableLanguages();
+
+ qDebug() << "langMap length:" << langMap.count();
+ qDebug("loop through langMap");
+ foreach(const CLanguageMgr::Language* lang, langMap) {
+ //const CLanguageMgr::Language* lang = *it;
+ //qDebug() << "foreach, lang: ";
+ //qDebug() << lang;
+
+ //if (lang->isValid() && CBTConfig::get(lang).first) {
+ if (!lang->abbrev().isEmpty() && CBTConfig::get(lang).first) {
+ const QFont f = CBTConfig::get(lang).second;
+
+ //don't use important, because it would reset the title formatting, etc. to the setup font
+ QString css("{ ");
+ css.append("font-family:").append(f.family())/*.append(" !important")*/;
+ css.append("; font-size:").append(QString::number(f.pointSize())).append("pt /*!important*/");
+ css.append("; font-weight:").append(f.bold() ? "bold" : "normal /*!important*/");
+ css.append("; font-style:").append(f.italic() ? "italic" : "normal /*!important*/");
+ css.append("; }\n");
+
+ langCSS +=
+ QString("\n*[lang=%1] %2")
+ .arg(lang->abbrev())
+ .arg(css);
+ }
+ }
+
+ //at first append the font standard settings for all languages without configured font
+ // Create a dummy language (the langmap may be empty)
+ CLanguageMgr::Language lang_v(QString("en"), QString("English"), QString());
+ CLanguageMgr::Language* lang = &lang_v;
+
+ if (lang && !lang->abbrev().isEmpty()/*&& lang->isValid()*/) {
+ const QFont standardFont = CBTConfig::getDefault(lang); //we just need a dummy lang param
+ langCSS.prepend(
+ QString("\n#content {font-family:%1; font-size:%2pt; font-weight:%3; font-style: %4;}\n")
+ .arg(standardFont.family())
+ .arg(standardFont.pointSize())
+ .arg(standardFont.bold() ? "bold" : "normal")
+ .arg(standardFont.italic() ? "italic" : "normal")
+ );
+ }
+
+// qWarning("Outputing unformated text");
+ const QString t = QString(m_templateMap[ templateName ]) //don't change the map's content directly, use a copy
+ .replace("#TITLE#", settings.title)
+ .replace("#LANG_ABBREV#", settings.langAbbrev.isEmpty() ? QString("en") : settings.langAbbrev)
+ .replace("#DISPLAYTYPE#", displayTypeString)
+ .replace("#LANG_CSS#", langCSS)
+ .replace("#PAGE_DIRECTION#", settings.pageDirection)
+ .replace("#CONTENT#", newContent);
+
+ return t;
+}
+
+void CDisplayTemplateMgr::loadTemplates() {
+ QStringList files;
+ foreach (QString file, util::filesystem::DirectoryUtil::getDisplayTemplatesDir().entryList(QStringList("*.tmpl")))
+ {
+ files += util::filesystem::DirectoryUtil::getDisplayTemplatesDir().canonicalPath() + "/" + file;
+ }
+ foreach (QString file, util::filesystem::DirectoryUtil::getUserDisplayTemplatesDir().entryList(QStringList("*.tmpl")))
+ {
+ files += util::filesystem::DirectoryUtil::getUserDisplayTemplatesDir().canonicalPath() + "/" + file;
+ }
+
+ foreach (QString file, files) {
+ QFile f(file);
+ if (f.exists() && f.open( QIODevice::ReadOnly )) {
+ QString fileContent = QTextStream( &f ).readAll();
+
+ if (!fileContent.isEmpty()) {
+ m_templateMap[ QFileInfo(file).fileName() ] = fileContent;
+ }
+ }
+ }
+}
diff --git a/src/backend/managers/cdisplaytemplatemgr.h b/src/backend/managers/cdisplaytemplatemgr.h
new file mode 100644
index 0000000..c791e16
--- /dev/null
+++ b/src/backend/managers/cdisplaytemplatemgr.h
@@ -0,0 +1,91 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CDISPLAYTEMPLATEMGR_H
+#define CDISPLAYTEMPLATEMGR_H
+
+//BibleTime include
+class CSwordModuleInfo;
+
+//Qt includes
+#include <QMap>
+#include <QString>
+#include <QStringList>
+
+/**
+ * Manages the display templates used in the filters and display classes.
+ * @author The BibleTime team
+*/
+
+class CDisplayTemplateMgr {
+
+public:
+ /** Settings which are used to fill the content into the template.
+ */
+
+ struct Settings {
+ /** Constructor. Constructs the new settings object. The default values are empty.
+ */
+ Settings() {
+ title = QString::null;
+ langAbbrev = QString::null;
+ pageCSS_ID = QString::null;
+ pageDirection = QString("ltr");
+ };
+
+ QList<CSwordModuleInfo*> modules; /**< the list of modules */
+ QString title; /**< the title which is used for the new processed HTML page */
+ QString langAbbrev; /**< the language for the HTML page. */
+ QString pageDirection; /**< the language for the HTML page. */
+ QString pageCSS_ID; /**< the CSS ID which is used in the content part of the page */
+ };
+
+ /** Available templates.
+ * @return The list of templates, which are available.
+ */
+ inline const QStringList availableTemplates();
+ /** Fill template. Fill rendered content into the template given by the name.
+ * @param name The name of the template
+ * @param content The content which should be filled into the template
+ * @param settings The settings which are used to process the templating process
+ * @return The full HTML template HTML code including the CSS data.
+ */
+ const QString fillTemplate( const QString& name, const QString& content, Settings& settings);
+ /** Default template.
+ * @return The i18n'ed name of the default template
+ */
+ inline static const QString defaultTemplate();
+
+protected:
+ friend class CPointers;
+ /** Display template manager constructor. Protected to just allow CPointers to create objects. */
+ CDisplayTemplateMgr();
+ /** Destructor. */
+ ~CDisplayTemplateMgr();
+ /** Does the actual work of loading templates from disk */
+ void loadTemplates();
+
+private:
+ QMap<QString, QString> m_templateMap;
+};
+
+inline const QString CDisplayTemplateMgr::defaultTemplate() {
+ return QString("Blue.tmpl");
+}
+
+/**
+ * CDisplayTemplateMgr::availableTemplates()
+ */
+inline const QStringList CDisplayTemplateMgr::availableTemplates() {
+ return m_templateMap.keys();
+}
+
+
+
+#endif
diff --git a/src/backend/managers/clanguagemgr.cpp b/src/backend/managers/clanguagemgr.cpp
new file mode 100644
index 0000000..4dcc411
--- /dev/null
+++ b/src/backend/managers/clanguagemgr.cpp
@@ -0,0 +1,546 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "clanguagemgr.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "cswordbackend.h"
+
+#include "util/cpointers.h"
+
+//KDE
+
+
+CLanguageMgr::Language::Language() {}
+
+CLanguageMgr::Language::Language(const Language& l) {
+ m_abbrev = l.m_abbrev;
+ m_englishName = l.m_englishName;
+ m_translatedName = l.m_translatedName;
+ m_altAbbrevs = l.m_altAbbrevs;
+}
+
+CLanguageMgr::Language::Language( const QString& abbrev, const QString& name, const QString& translatedName, const QStringList& altAbbrevs ) {
+ m_abbrev = abbrev;
+ m_englishName = name;
+ m_translatedName = translatedName;
+ m_altAbbrevs = altAbbrevs;
+}
+
+CLanguageMgr::Language::~Language() {
+}
+
+
+/****************************************************/
+/******************** CLanguageMgr ******************/
+/****************************************************/
+CLanguageMgr::CLanguageMgr() : m_langMap() {
+ m_availableModulesCache.moduleCount = 0;
+ init();
+}
+
+CLanguageMgr::~CLanguageMgr() {
+ qDeleteAll(m_cleanupLangPtrs);
+ m_cleanupLangPtrs.clear();
+ qDeleteAll(m_langList);
+ m_langList.clear();
+}
+
+const CLanguageMgr::LangMap& CLanguageMgr::availableLanguages() {
+ QList<CSwordModuleInfo*> mods = CPointers::backend()->moduleList();
+
+ if ( m_availableModulesCache.moduleCount != (unsigned int)mods.count() ) { //we have to refill the cached map
+ m_availableModulesCache.availableLanguages.clear();
+ m_availableModulesCache.moduleCount = mods.count();
+
+ //collect the languages abbrevs of all modules
+ QStringList abbrevs;
+
+ foreach (const CSwordModuleInfo* mod, mods) {
+ if (!abbrevs.contains(mod->module()->Lang())){
+ abbrevs.append(mod->module()->Lang());
+ }
+ }
+
+ //now create a map of available langs
+ foreach ( QString abbrev, abbrevs ) {
+ const Language* const lang = languageForAbbrev(abbrev);
+
+ if (lang->isValid()) {
+ m_availableModulesCache.availableLanguages.insert( abbrev, lang );
+ }
+ else { //invalid lang used by a module, create a new language using the abbrev
+ Language* newLang = new Language(abbrev, abbrev, abbrev);
+ m_cleanupLangPtrs.append(newLang);
+ m_availableModulesCache.availableLanguages.insert( abbrev, newLang );
+ }
+ }
+ }
+ return m_availableModulesCache.availableLanguages;
+}
+
+const CLanguageMgr::Language* CLanguageMgr::languageForAbbrev( const QString& abbrev ) const {
+ LangMapIterator it = m_langMap.find(abbrev);
+ if (it != m_langMap.constEnd()) return *it; //Language is already here
+
+ //try to search in the alternative abbrevs
+ foreach (const Language* lang, m_langList ) {
+ if (lang->alternativeAbbrevs().contains(abbrev)) return lang;
+ }
+
+ // Invalid lang used by a modules, create a new language using the abbrev
+ Language* newLang = new Language(abbrev, abbrev, abbrev); //return a language which holds the valid abbrev
+ m_cleanupLangPtrs.append(newLang);
+
+ return newLang;
+}
+
+const CLanguageMgr::Language* CLanguageMgr::languageForName( const QString& name ) const {
+ foreach ( const Language* lang, m_langList ) {
+ if (lang->name() == name) return lang;
+ }
+ return &m_defaultLanguage;//invalid language
+}
+
+const CLanguageMgr::Language* CLanguageMgr::languageForTranslatedName( const QString& name ) const {
+ foreach ( const Language* lang, m_langList ) {
+ if (lang->translatedName() == name) return lang;
+ }
+ return &m_defaultLanguage; //invalid language
+}
+
+void CLanguageMgr::init() {
+
+ // The main() sets string literal codec to utf8:
+ // QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
+ // The language names include escape sequences \uxxxx
+
+ //if we've already inserted all items we do not proceed
+ if (m_langMap.count() > 0) return;
+
+ // Developers: It's easy to get a list of used language codes from all modules:
+ // Refresh all sources; go to .sword/InstallMgr/; run:
+ // grep -R -hs Lang= *|cut -c 6-|sort|uniq
+ // Don't remove unused languages from the source code unless you know it won't be used
+ // anymore.in any module ever.
+
+ /*:
+ The string "Names of languages" doesn't actually need translation.
+ It is put here to help translators notice this help text.
+ -------
+ The names of the languages should follow the conventions of your
+ language. You can write the names with a capital first letter even if your language
+ uses non-capitalized language names (they look better with capital
+ first letter when they are listed).
+ -------
+ To find the names of all languages from internet try searching for
+ "names of languages in language_x" but in your own language, e.g.
+ "kielten nimet suomeksi" in Finnish or "names of languages in english"
+ in English.
+ -------
+ You can find the language codes and names by googling for the standards
+ mentioned below.
+ -------
+ Preference order for locale codes are:
+ -------
+ ISO 639-1 -------
+ ISO 639-2 -------
+ ISO 639-3
+ -------
+ x-E-XXX form is deprecated and no modules in repositories use it.
+ If you find a module with x-E-XXX language, update the module.
+ */
+ QObject::tr("Names of languages", "No need to translate - see the longer comment (If there is no longer comment, it doesn't work yet :)) ------ ");
+ // m_langList.append( new Language("aa", "Afar", QObject::tr("Afar")) );
+ // m_langList.append( new Language("ab", "Abkhazian", QObject::tr("Abkhazian")) );
+ // m_langList.append( new Language("ae", "Avestan", QObject::tr("Avestan")) );
+ //: Language name af
+ m_langList.append( new Language("af", "Afrikaans", QObject::tr("Afrikaans")) );
+ // m_langList.append( new Language("am", "Amharic", QObject::tr("Amharic")) );
+ //: Language name amu
+ m_langList.append( new Language("amu", "Amuzgo, Guerrero", QObject::tr("Amuzgo, Guerrero")) );
+ //: Language name ang
+ m_langList.append( new Language("ang", "English, Old (ca.450-1100)", QObject::tr("English, Old (ca.450-1100)")) );
+ //: Language name ar
+ m_langList.append( new Language("ar", "Arabic", QObject::tr("Arabic")) );
+ // m_langList.append( new Language("as", "Assamese", QObject::tr("Assamese")) );
+ //: Language name az
+ m_langList.append( new Language("az", "Azerbaijani", QObject::tr("Azerbaijani")) );
+ //: Language name azb
+ m_langList.append( new Language("azb", "Azerbaijani, South", QObject::tr("Azerbaijani, South")) );
+ // m_langList.append( new Language("ba", "Bashkir", QObject::tr("Bashkir")) );
+ //: Language name bar
+ m_langList.append( new Language("bar", "Bavarian", QObject::tr("Bavarian")) );
+ //: Language name be
+ m_langList.append( new Language("be", "Belarusian", QObject::tr("Belarusian")) );
+ //: Language name bg
+ m_langList.append( new Language("bg", "Bulgarian", QObject::tr("Bulgarian")) );
+ // m_langList.append( new Language("bh", "Bihari", QObject::tr("Bihari")) );
+ // m_langList.append( new Language("bi", "Bislama", QObject::tr("Bislama")) );
+ // m_langList.append( new Language("bn", "Bengali", QObject::tr("Bengali")) );
+ // m_langList.append( new Language("bo", "Tibetan", QObject::tr("Tibetan")) );
+ //: Language name br
+ m_langList.append( new Language("br", "Breton", QObject::tr("Breton")) );
+ //: Language name bs
+ m_langList.append( new Language("bs", "Bosnian", QObject::tr("Bosnian")) );
+ //: Language name ca
+ m_langList.append( new Language("ca", "Catalan", QObject::tr("Catalan")) );
+ // m_langList.append( new Language("ce", "Chechen", QObject::tr("Chechen")) );
+ //: Language name cco
+ m_langList.append( new Language("cco", "Chinantec, Comaltepec", QObject::tr("Chinantec, Comaltepec")) );
+ //: Language name ceb
+ m_langList.append( new Language("ceb", "Cebuano", QObject::tr("Cebuano")) );
+ //: Language name ch
+ m_langList.append( new Language("ch", "Chamorro", QObject::tr("Chamorro")) );
+ //: Language name chd
+ m_langList.append( new Language("chd", "Chontal, Highland Oaxaca", QObject::tr("Chontal, Highland Oaxaca")) );
+ //: Language name chq
+ m_langList.append( new Language("chq", "Chinantec, Quiotepec", QObject::tr("Chinantec, Quiotepec")) );
+ //: Language name chz
+ m_langList.append( new Language("chz", "Chinantec, Ozumac\u00edn", QObject::tr("Chinantec, Ozumac\u00edn")) );
+ // m_langList.append( new Language("co", "Corsican", QObject::tr("Corsican")) );
+ //: Language name ckw
+ m_langList.append( new Language("ckw", "Cakchiquel, Western", QObject::tr("Cakchiquel, Western")) );
+ //: Language name cnl
+ m_langList.append( new Language("cnl", "Chinantec, Lalana", QObject::tr("Chinantec, Lalana")) );
+ //: Language name cnt
+ m_langList.append( new Language("cnt", "Chinantec, Tepetotutla", QObject::tr("Chinantec, Tepetotutla")) );
+ //: Language name cop
+ m_langList.append( new Language("cop", "Coptic", QObject::tr("Coptic")) );
+ //: Language name cs
+ m_langList.append( new Language("cs", "Czech", QObject::tr("Czech")) );
+ //: Language name cso
+ m_langList.append( new Language("cso", "Chinantec, Sochiapan", QObject::tr("Chinantec, Sochiapan")) );
+ //: Language name cti
+ m_langList.append( new Language("cti", "Chol, Tila", QObject::tr("Chol, Tila")) );
+ //: Language name ctp
+ m_langList.append( new Language("ctp", "Chatino, Western Highland", QObject::tr("Chatino, Western Highland")) );
+ //: Language name cu
+ m_langList.append( new Language("cu", "Church Slavic", QObject::tr("Church Slavic")) );
+ // m_langList.append( new Language("cv", "Chuvash", QObject::tr("Chuvash")) );
+ //: Language name cy
+ m_langList.append( new Language("cy", "Welsh", QObject::tr("Welsh")) );
+ //: Language name da
+ m_langList.append( new Language("da", "Danish", QObject::tr("Danish")) );
+ //: Language name de
+ m_langList.append( new Language("de", "German", QObject::tr("German")) );
+ //: Language name dug
+ m_langList.append( new Language("dug", "Duruma", QObject::tr("Duruma")) );
+ // m_langList.append( new Language("dz", "Dzongkha", QObject::tr("Dzongkha")) );
+ //: Language name el
+ m_langList.append( new Language("el", "Greek, Modern (1453-)", QObject::tr("Greek, Modern (1453-)"), makeStringList("gre;ell")) );
+ //: Language name en
+ m_langList.append( new Language("en", "English", QObject::tr("English")) );
+ //: Language name en_US
+ m_langList.append( new Language("en_US","American English", QObject::tr("American English")) );
+ //: Language name enm
+ m_langList.append( new Language("enm", "English, Middle (1100-1500)", QObject::tr("English, Middle (1100-1500)")) );
+ //: Language name eo
+ m_langList.append( new Language("eo", "Esperanto", QObject::tr("Esperanto")) );
+ //: Language name es
+ m_langList.append( new Language("es", "Spanish", QObject::tr("Spanish")) );
+ //: Language name et
+ m_langList.append( new Language("et", "Estonian", QObject::tr("Estonian")) );
+ //: Language name eu
+ m_langList.append( new Language("eu", "Basque", QObject::tr("Basque")) );
+ //: Language name fa
+ m_langList.append( new Language("fa", "Persian", QObject::tr("Persian")) );
+ //: Language name fi
+ m_langList.append( new Language("fi", "Finnish", QObject::tr("Finnish")) );
+ // m_langList.append( new Language("fj", "Fijian", QObject::tr("Fijian")) );
+ // m_langList.append( new Language("fo", "Faroese", QObject::tr("Faroese")) );
+ //: Language name fr
+ m_langList.append( new Language("fr", "French", QObject::tr("French")) );
+ //: Language name fy
+ m_langList.append( new Language("fy", "Frisian", QObject::tr("Frisian")) );
+ //: Language name ga
+ m_langList.append( new Language("ga", "Irish", QObject::tr("Irish")) );
+ //: Language name gd
+ m_langList.append( new Language("gd", "Gaelic (Scots)", QObject::tr("Gaelic (Scots)")) );
+ //: Language name gez
+ m_langList.append( new Language("gez", "Geez", QObject::tr("Geez")) );
+ // m_langList.append( new Language("gl", "Gallegan", QObject::tr("Gallegan")) );
+ // m_langList.append( new Language("gn", "Guarani", QObject::tr("Guarani")) );
+ // m_langList.append( new Language("gn", "Gujarati", QObject::tr("Gujarati")) );
+ //: Language name got
+ m_langList.append( new Language("got", "Gothic", QObject::tr("Gothic")) );
+ //: Language name gv
+ m_langList.append( new Language("gv", "Manx", QObject::tr("Manx")) );
+ //: Language name grc
+ m_langList.append( new Language("grc", "Greek, Ancient (to 1453)", QObject::tr("Greek, Ancient (to 1453)")) );
+ //: Language name he
+ m_langList.append( new Language("he", "Hebrew", QObject::tr("Hebrew")) );
+ //: Language name hau
+ m_langList.append( new Language("hau", "Hausa", QObject::tr("Hausa")) );
+ //: Language name haw
+ m_langList.append( new Language("haw", "Hawaiian", QObject::tr("Hawaiian")) );
+ //: Language name hi
+ m_langList.append( new Language("hi", "Hindi", QObject::tr("Hindi")) );
+ // m_langList.append( new Language("ho", "Hiri Motu", QObject::tr("Hiri Motu")) );
+ //: Language name hr
+ m_langList.append( new Language("hr", "Croatian", QObject::tr("Croatian")) );
+ //: Language name ht
+ m_langList.append( new Language("ht", "Haitian Creole", QObject::tr("Haitian Creole")) );
+ //: Language name hu
+ m_langList.append( new Language("hu", "Hungarian", QObject::tr("Hungarian")) );
+ //: Language name huv
+ m_langList.append( new Language("huv", "Huave, San Mateo Del Mar", QObject::tr("Huave, San Mateo Del Mar")) );
+ //: Language name hy
+ m_langList.append( new Language("hy", "Armenian", QObject::tr("Armenian")) );
+ // m_langList.append( new Language("hz", "Herero", QObject::tr("Herero")) );
+ // m_langList.append( new Language("ia", "Interlingua", QObject::tr("Interlingua")) );
+ //: Language name id
+ m_langList.append( new Language("id", "Indonesian", QObject::tr("Indonesian")) );
+ // m_langList.append( new Language("ie", "Interlingue", QObject::tr("Interlingue")) );
+ // m_langList.append( new Language("ik", "Inupiaq", QObject::tr("Inupiaq")) );
+ //: Language name is
+ m_langList.append( new Language("is", "Icelandic", QObject::tr("Icelandic")) );
+ //: Language name it
+ m_langList.append( new Language("it", "Italian", QObject::tr("Italian")) );
+ //: Language name itz
+ m_langList.append( new Language("itz", "Itz\u00e1", QObject::tr("Itz\u00e1")) );
+ //: Language name ixl
+ m_langList.append( new Language("ixl", "Ixil, San Juan Cotzal", QObject::tr("Ixil, San Juan Cotzal")) );
+ // m_langList.append( new Language("iu", "Inuktitut", QObject::tr("Inuktitut")) );
+ //: Language name ja
+ m_langList.append( new Language("ja", "Japanese", QObject::tr("Japanese")) );
+ //: Language name jac
+ m_langList.append( new Language("jac", "Jacalteco, Eastern", QObject::tr("Jacalteco, Eastern")) );
+ //: Language name jvn
+ m_langList.append( new Language("jvn", "Javanese, Caribbean", QObject::tr("Javanese, Caribbean")) );
+ //: Language name ka
+ m_langList.append( new Language("ka", "Georgian", QObject::tr("Georgian")) );
+ //: Language name kek
+ m_langList.append( new Language("kek", "Kekch\u00ed", QObject::tr("Kekch\u00ed", "kek")) );
+ // m_langList.append( new Language("ki", "Kikuyu", QObject::tr("Kikuyu")) );
+ // m_langList.append( new Language("kj", "Kuanyama", QObject::tr("Kuanyama")) );
+ // m_langList.append( new Language("kk", "Kazakh", QObject::tr("Kazakh")) );
+ // m_langList.append( new Language("kl", "Kalaallisut", QObject::tr("Kalaallisut")) );
+ // m_langList.append( new Language("km", "Khmer", QObject::tr("Khmer")) );
+ // m_langList.append( new Language("kn", "Kannada", QObject::tr("Kannada")) );
+ //: Language name ko
+ m_langList.append( new Language("ko", "Korean", QObject::tr("Korean")) );
+ // m_langList.append( new Language("ks", "Kashmiri", QObject::tr("Kashmiri")) );
+ //: Language name ku
+ m_langList.append( new Language("ku", "Kurdish", QObject::tr("Kurdish")) );
+ // m_langList.append( new Language("kv", "Komi", QObject::tr("Komi")) );
+ // m_langList.append( new Language("kw", "Cornish", QObject::tr("Cornish")) );
+ //: Language name ky
+ m_langList.append( new Language("ky", "Kirghiz", QObject::tr("Kirghiz")) );
+ //: Language name la
+ m_langList.append( new Language("la", "Latin", QObject::tr("Latin")) );
+ //: Language name lac
+ m_langList.append( new Language("lac", "Lacandon", QObject::tr("Lacandon")) );
+ // m_langList.append( new Language("lb", "Letzeburgesch", QObject::tr("Letzeburgesch")) );
+ //: Language name lmo
+ m_langList.append( new Language("lmo", "Lombard", QObject::tr("Lombard")) );
+ // m_langList.append( new Language("ln", "Lingala", QObject::tr("Lingala")) );
+ // m_langList.append( new Language("lo", "Lao", QObject::tr("Lao")) );
+ //: Language name lt
+ m_langList.append( new Language("lt", "Lithuanian", QObject::tr("Lithuanian")) );
+ //: Language name lv
+ m_langList.append( new Language("lv", "Latvian", QObject::tr("Latvian")) );
+ //: Language name mg
+ m_langList.append( new Language("mg", "Malagasy", QObject::tr("Malagasy")) );
+ // m_langList.append( new Language("mh", "Marshall", QObject::tr("Marshall")) );
+ //: Language name mi
+ m_langList.append( new Language("mi", "Maori", QObject::tr("Maori")) );
+ //: Language name mir
+ m_langList.append( new Language("mir", "Mixe, Isthmus", QObject::tr("Mixe, Isthmus")) );
+ //: Language name miz
+ m_langList.append( new Language("miz", "Mixtec, Coatzospan", QObject::tr("Mixtec, Coatzospan")) );
+ //: Language name mk
+ m_langList.append( new Language("mk", "Macedonian", QObject::tr("Macedonian")) );
+ //: Language name mks
+ m_langList.append( new Language("mks", "Mixtec, Silacayoapan", QObject::tr("Mixtec, Silacayoapan")) );
+ // m_langList.append( new Language("ml", "Malayalam", QObject::tr("Malayalam")) );
+ // m_langList.append( new Language("mn", "Mongolian", QObject::tr("Mongolian")) );
+ // m_langList.append( new Language("mo", "Moldavian", QObject::tr("Moldavian")) );
+ //: Language name mos
+ m_langList.append( new Language("mos", "More", QObject::tr("More")) );
+ // m_langList.append( new Language("mr", "Marathi", QObject::tr("Marathi")) );
+ //: Language name ms
+ m_langList.append( new Language("ms", "Malay", QObject::tr("Malay")) );
+ //: Language name mt
+ m_langList.append( new Language("mt", "Maltese", QObject::tr("Maltese")) );
+ //: Language name mul (meaning that the work has multiple languages)
+ m_langList.append( new Language("mul", "(Multiple languages)", QObject::tr("(Multiple languages)")) );
+ //: Language name mvc
+ m_langList.append( new Language("mvc", "Mam, Central", QObject::tr("Mam, Central")) );
+ //: Language name mvj
+ m_langList.append( new Language("mvj", "Mam, Todos Santos Cuchumat\u00e1n", QObject::tr("Mam, Todos Santos Cuchumat\u00e1n")) );
+ //: Language name mxq
+ m_langList.append( new Language("mxq", "Mixe, Juquila", QObject::tr("Mixe, Juquila")) );
+ //: Language name mxt
+ m_langList.append( new Language("mxt", "Mixtec, Jamiltepec", QObject::tr("Mixtec, Jamiltepec")) );
+ //: Language name my
+ m_langList.append( new Language("my", "Burmese", QObject::tr("Burmese")) );
+ // m_langList.append( new Language("na", "Nauru", QObject::tr("Nauru")) );
+ //: Language name nb
+ m_langList.append( new Language("nb", "Norwegian Bokm\u00e5l", QObject::tr("Norwegian Bokm\u00e5l")) );
+ //: Language name ncl
+ m_langList.append( new Language("ncl", "Nahuatl, Michoac\u00e1n", QObject::tr("Nahuatl, Michoac\u00e1n")) );
+ // m_langList.append( new Language("nd", "Ndebele, North", QObject::tr("Ndebele, North")) );
+ //: Language name nds
+ m_langList.append( new Language("nds", "Low German; Low Saxon", QObject::tr("Low German; Low Saxon")) );
+ //: Language name ne
+ m_langList.append( new Language("ne", "Nepali", QObject::tr("Nepali")) );
+ //: Language name ngu
+ m_langList.append( new Language("ngu", "Nahuatl, Guerrero", QObject::tr("Nahuatl, Guerrero")) );
+ //: Language name nhy
+ m_langList.append( new Language("nhy", "Nahuatl, Northern Oaxaca", QObject::tr("Nahuatl, Northern Oaxaca")) );
+ // m_langList.append( new Language("ng", "Ndonga", QObject::tr("Ndonga")) );
+ //: Language name nl
+ m_langList.append( new Language("nl", "Dutch", QObject::tr("Dutch")) );
+ //: Language name nn
+ m_langList.append( new Language("nn", "Norwegian Nynorsk", QObject::tr("Norwegian Nynorsk")) );
+ //: Language name no
+ m_langList.append( new Language("no", "Norwegian", QObject::tr("Norwegian")) );
+ // m_langList.append( new Language("nr", "Ndebele, South", QObject::tr("Ndebele, South")) );
+ // m_langList.append( new Language("nv", "Navajo", QObject::tr("Navajo")) );
+ // m_langList.append( new Language("ny", "Chichewa; Nyanja", QObject::tr("Chichewa; Nyanja")) );
+ // m_langList.append( new Language("oc", "Occitan (post 1500); Provençal", QObject::tr("Occitan (post 1500); Provençal")) );
+ // m_langList.append( new Language("om", "Oromo", QObject::tr("Oromo")) );
+ // m_langList.append( new Language("or", "Oriya", QObject::tr("Oriya")) );
+ // m_langList.append( new Language("os", "Ossetian; Ossetic", QObject::tr("Ossetian; Ossetic")) );
+ //: Language name otq
+ m_langList.append( new Language("otq", "Otomi, Quer\u00e9taro", QObject::tr("Otomi, Quer\u00e9taro")) );
+ // m_langList.append( new Language("pa", "Panjabi", QObject::tr("Panjabi")) );
+ //: Language name pap
+ m_langList.append( new Language("pap", "Papiamento", QObject::tr("Papiamento")) );
+ // m_langList.append( new Language("pi", "Pali", QObject::tr("Pali")) );
+ //: Language name ppk
+ m_langList.append( new Language("ppk", "Uma", QObject::tr("Uma")) );
+ //: Language name pl
+ m_langList.append( new Language("pl", "Polish", QObject::tr("Polish")) );
+ //: Language name pot
+ m_langList.append( new Language("pot", "Potawatomi", QObject::tr("Potawatomi")) );
+ //: Language name ppk
+ m_langList.append( new Language("ppk", "Uma", QObject::tr("Uma")) );
+ //: Language name prs
+ m_langList.append( new Language("prs", "Persian (Dari)", QObject::tr("Persian (Dari)")) );
+
+ // m_langList.append( new Language("ps", "Pushto", QObject::tr("Pushto")) );
+ //: Language name pt
+ m_langList.append( new Language("pt", "Portuguese", QObject::tr("Portuguese")) );
+ //: Language name pt_BR
+ m_langList.append( new Language("pt_BR", "Brasilian Portuguese", QObject::tr("Brasilian Portuguese")) );//added by ourself
+ // m_langList.append( new Language("qu", "Quechua", QObject::tr("Quechua")) );
+ //: Language name qut
+ m_langList.append( new Language("qut", "Quich\u00e9, West Central", QObject::tr("Quich\u00e9, West Central")) );
+ // m_langList.append( new Language("rm", "Raeto-Romance", QObject::tr("Raeto-Romance")) );
+ // m_langList.append( new Language("rn", "Rundi", QObject::tr("Rundi")) );
+ //: Language name ro
+ m_langList.append( new Language("ro", "Romanian", QObject::tr("Romanian")) );
+ //: Language name ru
+ m_langList.append( new Language("ru", "Russian", QObject::tr("Russian")) );
+ // m_langList.append( new Language("rw", "Kinyarwanda", QObject::tr("Kinyarwanda")) );
+ // m_langList.append( new Language("sa", "Sanskrit", QObject::tr("Sanskrit")) );
+ // m_langList.append( new Language("sc", "Sardinian", QObject::tr("Sardinian")) );
+ //: Language name sco
+ m_langList.append( new Language("sco", "Scots", QObject::tr("Scots")) );
+ // m_langList.append( new Language("sd", "Sindhi", QObject::tr("Sindhi")) );
+ // m_langList.append( new Language("se", "Northern Sami", QObject::tr("Northern Sami")) );
+ // m_langList.append( new Language("sg", "Sango", QObject::tr("Sango")) );
+ // m_langList.append( new Language("si", "Sinhalese", QObject::tr("Sinhalese")) );
+ //: Language name sk
+ m_langList.append( new Language("sk", "Slovak", QObject::tr("Slovak")) );
+ //: Language name sl
+ m_langList.append( new Language("sl", "Slovenian", QObject::tr("Slovenian")) );
+ // m_langList.append( new Language("sm", "Samoan", QObject::tr("Samoan")) );
+ // m_langList.append( new Language("sn", "Shona", QObject::tr("Shona")) );
+ //: Language name so
+ m_langList.append( new Language("so", "Somali", QObject::tr("Somali")) );
+ //: Language name sq
+ m_langList.append( new Language("sq", "Albanian", QObject::tr("Albanian")) );
+ // m_langList.append( new Language("sr", "Serbian", QObject::tr("Serbian")) );
+ //: Language name srn
+ m_langList.append( new Language("srn", "Sranan", QObject::tr("Sranan")) );
+ // m_langList.append( new Language("ss", "Swati", QObject::tr("Swati")) );
+ // m_langList.append( new Language("st", "Sotho, Southern", QObject::tr("Sotho, Southern")) );
+ // m_langList.append( new Language("su", "Sundanese", QObject::tr("Sundanese")) );
+ //: Language name sv
+ m_langList.append( new Language("sv", "Swedish", QObject::tr("Swedish")) );
+ //: Language name sw
+ m_langList.append( new Language("sw", "Swahili", QObject::tr("Swahili")) );
+ //: Language name syr
+ m_langList.append( new Language("syr", "Syriac", QObject::tr("Syriac")) );
+ //: Language name ta
+ m_langList.append( new Language("ta", "Tamil", QObject::tr("Tamil")) );
+ // m_langList.append( new Language("te", "Telugu", QObject::tr("Telugu")) );
+ // m_langList.append( new Language("tg", "Tajik", QObject::tr("Tajik")) );
+ //: Language name th
+ m_langList.append( new Language("th", "Thai", QObject::tr("Thai")) );
+ // m_langList.append( new Language("tk", "Turkmen", QObject::tr("Turkmen")) );
+ //: Language name tl
+ m_langList.append( new Language("tl", "Tagalog", QObject::tr("Tagalog")) );
+ //: Language name tlh
+ m_langList.append( new Language("tlh", "Klingon", QObject::tr("Klingon")) );
+ //: Language name tn
+ m_langList.append( new Language("tn", "Tswana", QObject::tr("Tswana")) );
+ //: Language name tr
+ m_langList.append( new Language("tr", "Turkish", QObject::tr("Turkish")) );
+ // m_langList.append( new Language("ts", "Tsonga", QObject::tr("Tsonga")) );
+ // m_langList.append( new Language("tt", "Tatar", QObject::tr("Tatar")) );
+ //: Language name ttc
+ m_langList.append( new Language("ttc", "Tektiteko", QObject::tr("Tektiteko")) );
+ // m_langList.append( new Language("tw", "Twi", QObject::tr("Twi")) );
+ //: Language name ty
+ m_langList.append( new Language("ty", "Tahitian", QObject::tr("Tahitian")) );
+ //: Language name tzz
+ m_langList.append( new Language("tzz", "Tzotzil, Zinacant\u00e1n", QObject::tr("Tzotzil, Zinacant\u00e1n")) );
+ // m_langList.append( new Language("ug", "Uighur", QObject::tr("Uighur")) );
+ //: Language name uk
+ m_langList.append( new Language("uk", "Ukrainian", QObject::tr("Ukrainian")) );
+ // m_langList.append( new Language("ur", "Urdu", QObject::tr("Urdu")) );
+ //: Language name ury
+ m_langList.append( new Language("ury", "Orya", QObject::tr("Orya")) );
+ //: Language name usp
+ m_langList.append( new Language("usp", "Uspanteco", QObject::tr("Uspanteco")) );
+ // m_langList.append( new Language("uz", "Uzbek", QObject::tr("Uzbek")) );
+ //: Language name vi
+ m_langList.append( new Language("vi", "Vietnamese", QObject::tr("Vietnamese")) );
+ // m_langList.append( new Language("vo", "Volapük", QObject::tr("Volapük")) );
+ // m_langList.append( new Language("wo", "Wolof", QObject::tr("Wolof")) );
+ //: Language name xh
+ m_langList.append( new Language("xh", "Xhosa", QObject::tr("Xhosa")) );
+ //: Language name xtd
+ m_langList.append( new Language("xtd", "Mixtec, Diuxi-Tilantongo", QObject::tr("Mixtec, Diuxi-Tilantongo")) );
+ //: Language name yi
+ m_langList.append( new Language("yi", "Yiddish", QObject::tr("Yiddish")) );
+ //: Language name yo
+ m_langList.append( new Language("yo", "Yoruba", QObject::tr("Yoryba")) );
+ // m_langList.append( new Language("za", "Zhuang", QObject::tr("Zhuang")) );
+ //: Language name zab
+ m_langList.append( new Language("zab", "Zapotec, San Juan Guelav\u00eda", QObject::tr("Zapotec, San Juan Guelav\u00eda")) );
+ //: Language name zaw
+ m_langList.append( new Language("zaw", "Zapotec, Mitla", QObject::tr("Zapotec, Mitla")) );
+ //: Language name zh
+ m_langList.append( new Language("zh", "Chinese", QObject::tr("Chinese")) );
+ //: Language name zpo
+ m_langList.append( new Language("zpo", "Zapotec, Amatl\u00e1n", QObject::tr("Zapotec, Amatl\u00e1n")) );
+ //: Language name zpq
+ m_langList.append( new Language("zpq", "Zapotec, Zoogocho", QObject::tr("Zapotec, Zoogocho")) );
+ //: Language name zpu
+ m_langList.append( new Language("zpu", "Zapotec, Yal\u00e1lag", QObject::tr("Zapotec, Yal\u00e1lag")) );
+ //: Language name zpv
+ m_langList.append( new Language("zpv", "Zapotec, Chichicapan", QObject::tr("Zapotec, Chichicapan")) );
+ //: Language name zsr
+ m_langList.append( new Language("zsr", "Zapotec, Southern Rincon", QObject::tr("Zapotec, Southern Rincon")) );
+ //: Language name ztq
+ m_langList.append( new Language("ztq", "Zapotec, Quioquitani-Quier\u00ed", QObject::tr("Zapotec, Quioquitani-Quier\u00ed")) );
+ //: Language name zty
+ m_langList.append( new Language("zty", "Zapotec, Yatee", QObject::tr("Zapotec, Yatee")) );
+ //: Language name zu
+ m_langList.append( new Language("zu", "Zulu", QObject::tr("Zulu")) );
+
+ foreach (Language* lang, m_langList) {
+ m_langMap.insert( lang->abbrev(), lang);
+ }
+}
diff --git a/src/backend/managers/clanguagemgr.h b/src/backend/managers/clanguagemgr.h
new file mode 100644
index 0000000..f421e62
--- /dev/null
+++ b/src/backend/managers/clanguagemgr.h
@@ -0,0 +1,151 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CLANGUAGEMGR_H
+#define CLANGUAGEMGR_H
+
+//Qt includes
+#include <QString>
+#include <QStringList>
+#include <QList>
+#include <QHash>
+
+/** Manages the languages of BibleTime and provides functions to work with them.
+ * @author The BibleTime team
+ */
+
+class CLanguageMgr {
+
+public:
+ /** Language container.
+ * This class (Language) contains the information about the chosen language.
+ */
+ class Language {
+ public:
+ /** Default constructor of a language object.
+ * Uses the abbreviation parameter to lookup the
+ * language name and to be able to return the name, flag etc.
+ * Possible values for abbrev are de, en, fr, it etc.
+ */
+ Language();
+ /** Copy constructor.
+ */
+ Language(const Language&);
+ /** Constructor which takes all necessary data.
+ */
+ Language(const QString& abbrev, const QString& englishName, const QString& translatedName, const QStringList& altAbbrevs = QStringList());
+ /** Destructor.
+ */
+ ~Language();
+ /** Returns the abbreviation.
+ * @return The abbreviation of the chosen language.
+ */
+ inline const QString& abbrev() const {
+ if (m_abbrev.isEmpty() && m_altAbbrevs.count()) { //no standard abbrev but alternative ones
+ return m_altAbbrevs.first();
+ }
+ return m_abbrev;
+ }
+ /** Returns the translated name.
+ * @return The translated name of the language.
+ */
+ inline const QString& translatedName() const {
+ return m_translatedName;
+ }
+ /** The english name of the language.
+ * @return The english name of the chosen language.
+ */
+ inline const QString& name() const {
+ return m_englishName;
+ }
+ /** The alternative abbreviations which are avalable for this language.
+ * @return The List of alternate abbreviations
+ */
+ inline const QStringList alternativeAbbrevs() const {
+ return m_altAbbrevs;
+ }
+ /**
+ * Returns true if this language object is valid, i.e. has an abbrev and name.
+ * @return True if the data is valid for this language.
+ */
+ inline bool isValid() const {
+ return (!abbrev().isEmpty() && !name().isEmpty());
+ }
+
+ private:
+ QString m_abbrev;
+ QString m_englishName;
+ QString m_translatedName;
+ QStringList m_altAbbrevs;
+ };
+
+ typedef QList<Language*> LanguageList;
+ typedef QHash<QString, const Language*> LangMap;
+ typedef QHash<QString, const Language*>::const_iterator LangMapIterator;
+
+ /** Constructor.
+ */
+ CLanguageMgr();
+ /** Destructor
+ */
+ virtual ~CLanguageMgr();
+ /**
+ * Returns the standard languages available as standard. Does nothing for Sword.
+ * @return A LangMap map which contains all known languages
+ */
+ inline const CLanguageMgr::LangMap* languages() const {
+ return &m_langMap;
+ }
+ /**
+ * Returns the languages which are available. The languages cover all available modules, but nothing more.
+ * @return A map of all languages with modules available for them
+ */
+ const CLanguageMgr::LangMap& availableLanguages();
+ /** Language for abbreviation.
+ * @param abbrev The language abbreviation
+ * @return Pointer to a language for the given string abbreviation.
+ */
+ const CLanguageMgr::Language* languageForAbbrev( const QString& abbrev ) const;
+ /** Language for english name.
+ * @param abbrev The english language name.
+ * @return Pointer to a language for the given name
+ */
+ const CLanguageMgr::Language* languageForName( const QString& language ) const;
+ /** Language for translated language name.
+ * @param abbrev The translated language name
+ * @return Pointer to a language for the given translated language name
+ */
+ const CLanguageMgr::Language* languageForTranslatedName( const QString& language ) const;
+ /** Default language so we don't return NULL pointers.
+ * @return Pointer to the default language
+ */
+ inline const CLanguageMgr::Language* defaultLanguage() const {
+ return &m_defaultLanguage;
+ }
+
+private:
+ void init();
+ inline const QStringList makeStringList(const QString& abbrevs) {
+ return abbrevs.split( ";", QString::KeepEmptyParts, Qt::CaseSensitive );
+ }
+
+ Language m_defaultLanguage;
+ mutable LanguageList m_langList;
+ mutable LangMap m_langMap;
+ mutable LanguageList m_cleanupLangPtrs;
+
+ struct ModuleCache {
+ unsigned int moduleCount;
+ LangMap availableLanguages;
+ }
+ m_availableModulesCache;
+};
+
+#endif
+
diff --git a/src/backend/managers/creferencemanager.cpp b/src/backend/managers/creferencemanager.cpp
new file mode 100644
index 0000000..adae180
--- /dev/null
+++ b/src/backend/managers/creferencemanager.cpp
@@ -0,0 +1,422 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "creferencemanager.h"
+#include "backend/keys/cswordversekey.h"
+
+#include "backend/config/cbtconfig.h"
+#include "util/cpointers.h"
+
+//QT
+#include <QRegExp>
+
+//stl
+#include <algorithm> // STL algorithms class library
+
+/** Returns a hyperlink used to be imbedded in the display windows. At the moment the format is sword://module/key */
+const QString CReferenceManager::encodeHyperlink( const QString moduleName, const QString key, const CReferenceManager::Type type) {
+ QString ret = QString::null;
+
+ switch (type) {
+
+ case Bible:
+ ret = QString("sword://Bible/");
+ break;
+ case Commentary:
+ ret = QString("sword://Commentary/");
+ break;
+ case Lexicon:
+ ret = QString("sword://Lexicon/");
+ break;
+ case GenericBook:
+ ret = QString("sword://Book/");
+ break;
+ case MorphHebrew:
+ ret = QString("morph://Hebrew/");
+ break;
+ case MorphGreek:
+ ret = QString("morph://Greek/");
+ break;
+ case StrongsHebrew:
+ ret = QString("strongs://Hebrew/");
+ break;
+ case StrongsGreek:
+ ret = QString("strongs://Greek/");
+ break;
+ default:
+ break;
+ }
+
+ if (!moduleName.isEmpty()) {
+ ret.append( moduleName ).append('/');
+ }
+ else { //if module is empty use fallback module
+ ret.append( preferredModule(type) ).append('/');
+ }
+
+ if (type == GenericBook) {
+ const QString s = (!key.isEmpty() ? key : QString::null);
+ QString newKey = QString::null;
+ //replace all / of the key (e.g. of a CSwordTreeKey) with
+ // the escape sequence \/ so we know it's a link internal divider (e.g. of CSwordTreeKey)!
+
+ QChar c;
+
+ for(int i = 0; i < s.length(); ++i) {
+ c = s.at(i);
+
+ if (c == '/') {
+ newKey.append("\\/");
+ }
+ else {
+ newKey.append(c);
+ }
+ }
+
+ ret.append( newKey );
+ }
+ else { //slashes do not appear in verses and dictionary entries
+
+ switch (type) {
+
+ case Bible: //bibles or commentary keys need parsing
+
+ case Commentary: {
+/* CSwordModuleInfo* mod = CPointers::backend()->findModuleByName(moduleName);
+
+ ParseOptions options;
+ options.refDestinationModule = mod->name();
+ options.refBase =
+ options.sourceLanguage = mod->module()->Lang();
+ options.destinationLanguage = "en";
+
+ ret.append( parseVerseReference(key, options) ); //we add the english key, so drag and drop will work in all cases*/
+ ret.append(key);
+ break;
+ }
+
+ default:
+ ret.append( key ); //use the standard key, no parsing required
+ break;
+ }
+ }
+
+ return ret;
+}
+
+/** Decodes the given hyperlink to module and key. */
+bool CReferenceManager::decodeHyperlink( const QString& hyperlink, QString& module, QString& key, CReferenceManager::Type& type ) {
+ /**
+ * We have to decide between three types of URLS: sword://Type/Module/Key, morph://Testament/key and strongs://Testament/Key
+ */
+ module = QString::null;
+ key = QString::null;
+
+ type = Unknown; //not yet known
+ QString ref = hyperlink;
+ //remove the trailing slash
+
+ if (ref.right(1)=="/" && ref.right(2) != "\\/") //trailing slash, but not escaped
+ ref = ref.left(ref.length()-1);
+
+ //find out which type we have by looking at the beginning (protocoll section of URL)
+ if (ref.left(8).toLower() == "sword://") { //Bible, Commentary or Lexicon
+ ref = ref.mid(8);
+
+ if (ref.left(5).toLower() == "bible") { //a bible hyperlink
+ type = CReferenceManager::Bible;
+ ref = ref.mid(6); //inclusive trailing slash
+ }
+ else if (ref.left(10).toLower() == "commentary") { // a Commentary hyperlink
+ type = CReferenceManager::Commentary;
+ ref = ref.mid(11); //inclusive trailing slash
+ }
+ else if (ref.left(7).toLower() == "lexicon") { // a Lexicon hyperlink
+ type = CReferenceManager::Lexicon;
+ ref = ref.mid(8); //inclusive trailing slash
+ }
+ else if (ref.left(4).toLower() == "book") { // a Book hyperlink
+ type = CReferenceManager::GenericBook;
+ ref = ref.mid(5); //inclusive trailing slash
+ }
+
+ // string up to next slash is the modulename
+ if (ref.at(0) != '/' ) { //we have a module given
+
+ while (true) {
+ const int pos = ref.indexOf("/");
+
+ if ((pos>0) && ref.at(pos-1) != '\\') { //found a slash which is not escaped
+ module = ref.mid(0,pos);
+ ref = ref.mid(pos+1);
+ break;
+ }
+ else if (pos == -1) {
+ break;
+ }
+ }
+
+ // the rest is the key
+ key = ref;
+ }
+ else {
+ key = ref.mid(1);
+ }
+
+ //the key may be an osis key like "NASBLex:Moses", which sets the module, too
+ // const int modPos = key.find(":");
+ // if (modPos != -1 && key.at(modPos-1).isLetter() && key.at(modPos+1).isLetter()) {
+ // module = key.left(modPos);
+ // key = key.mid(modPos+1);
+ //
+ // qWarning("found the module name %s with key %s", module.latin1(), key.latin1());
+ // }
+
+ //replace \/ escapes with /
+ key.replace(QRegExp("\\\\/"), "/");
+ }
+ else if (ref.left(8).toLower() == "morph://" || ref.left(10).toLower() == "strongs://") { //strongs or morph URL have the same format
+ enum PreType {IsMorph, IsStrongs};
+ PreType preType = IsMorph;
+
+ if (ref.left(8).toLower() == "morph://") { //morph code hyperlink
+ ref = ref.mid(8);
+ preType = IsMorph;
+ }
+ else if (ref.left(10).toLower() == "strongs://") {
+ ref = ref.mid(10);
+ preType = IsStrongs;
+ }
+
+ //part up to next slash is the language
+ const int pos = ref.indexOf("/");
+
+ if (pos>0) { //found
+ const QString language = ref.mid(0,pos);
+
+ if (language.toLower() == "hebrew") {
+ switch (preType) {
+
+ case IsMorph:
+ type = CReferenceManager::MorphHebrew;
+ break;
+
+ case IsStrongs:
+ type = CReferenceManager::StrongsHebrew;
+ break;
+ }
+ }
+ else if (language.toLower() == "greek") {
+ switch (preType) {
+
+ case IsMorph:
+ type = CReferenceManager::MorphGreek;
+ break;
+
+ case IsStrongs:
+ type = CReferenceManager::StrongsGreek;
+ break;
+ }
+ }
+
+ ref = ref.mid(pos+1);
+ key = ref; //the remaining part is the key
+
+ module = preferredModule(type);
+ }
+ }
+
+ if (key.isEmpty() && module.isEmpty())
+ return false;
+
+ return true;
+}
+
+const QString CReferenceManager::encodeReference(const QString &module, const QString &reference) {
+ //return QString("(%1)%2").arg(module).arg(reference);
+ return QString("(").append(module).append(")").append(reference);
+}
+
+void CReferenceManager::decodeReference(QString &dragreference, QString &module, QString &reference) {
+ const int pos = dragreference.indexOf(")");
+ const QString fallbackModule = dragreference.mid( 1, pos - 1);
+ dragreference = dragreference.mid(pos+1);
+
+ module = fallbackModule;
+ reference = dragreference;
+}
+
+/** Returns true if the parameter is a hyperlink. */
+bool CReferenceManager::isHyperlink( const QString& hyperlink ) {
+ return ( hyperlink.left(8) == "sword://")
+ || (hyperlink.left(10) == "strongs://")
+ || (hyperlink.left(8) == "morph://");
+}
+
+/** Returns the preferred module name for the given type. */
+const QString CReferenceManager::preferredModule( const CReferenceManager::Type type ) {
+ QString moduleName = QString::null;
+ CSwordModuleInfo* module = 0;
+
+ switch (type) {
+
+ case CReferenceManager::Bible:
+
+ module = CBTConfig::get
+ ( CBTConfig::standardBible );
+
+ break;
+
+ case CReferenceManager::Commentary:
+ module = CBTConfig::get
+ ( CBTConfig::standardCommentary );
+
+ break;
+
+ case CReferenceManager::Lexicon:
+ module = CBTConfig::get
+ ( CBTConfig::standardLexicon );
+
+ break;
+
+ case CReferenceManager::StrongsHebrew:
+ module = CBTConfig::get
+ ( CBTConfig::standardHebrewStrongsLexicon );
+
+ break;
+
+ case CReferenceManager::StrongsGreek:
+ module = CBTConfig::get
+ ( CBTConfig::standardGreekStrongsLexicon );
+
+ break;
+
+ case CReferenceManager::MorphHebrew:
+ module = CBTConfig::get
+ ( CBTConfig::standardHebrewMorphLexicon );
+
+ break;
+
+ case CReferenceManager::MorphGreek:
+ module = CBTConfig::get
+ ( CBTConfig::standardGreekMorphLexicon );
+
+ break;
+
+ default:
+ module = 0;
+
+ break;
+ }
+
+ return module ? module->name() : QString::null;
+}
+
+/** No descriptions */
+CReferenceManager::Type CReferenceManager::typeFromModule( const CSwordModuleInfo::ModuleType type) {
+ switch (type) {
+
+ case CSwordModuleInfo::Bible:
+ return CReferenceManager::Bible;
+
+ case CSwordModuleInfo::Commentary:
+ return CReferenceManager::Commentary;
+
+ case CSwordModuleInfo::Lexicon:
+ return CReferenceManager::Lexicon;
+
+ case CSwordModuleInfo::GenericBook:
+ return CReferenceManager::GenericBook;
+
+ default:
+ return CReferenceManager::Unknown;
+ }
+}
+
+/** Parses the given verse references using the given language and the module.*/
+const QString CReferenceManager::parseVerseReference( const QString& ref, const CReferenceManager::ParseOptions& options) {
+
+ CSwordModuleInfo* const mod = CPointers::backend()->findModuleByName(options.refDestinationModule);
+ //Q_ASSERT(mod); tested later
+
+ if (!mod) {
+ //parsing of non-verse based references is not supported
+ return ref;
+ }
+
+ if ((mod->type() != CSwordModuleInfo::Bible) && (mod->type() != CSwordModuleInfo::Commentary)) {
+ qDebug("CReferenceManager: Only verse based modules are supported as ref destination module");
+ return QString::null;
+ }
+
+ QString sourceLanguage = options.sourceLanguage;
+ QString destinationLanguage = options.destinationLanguage;
+
+ sword::StringList locales = sword::LocaleMgr::getSystemLocaleMgr()->getAvailableLocales();
+ if (/*options.sourceLanguage == "en" ||*/ std::find(locales.begin(), locales.end(), sourceLanguage.toUtf8().constData()) == locales.end()) { //sourceLanguage not available
+ sourceLanguage = "en_US";
+ }
+
+ if (/*options.destinationLanguage == "en" ||*/ std::find(locales.begin(), locales.end(), sourceLanguage.toUtf8().constData()) == locales.end()) { //destination not available
+ destinationLanguage = "en_US";
+ }
+
+ QString ret;
+ QStringList refList = ref.split(";");
+
+ CSwordVerseKey baseKey(0);
+ baseKey.setLocale( sourceLanguage.toUtf8().constData() );
+ baseKey.key( options.refBase ); //probably in the sourceLanguage
+ baseKey.setLocale( "en_US" ); //english works in all environments as base
+
+// CSwordVerseKey dummy(0);
+ //HACK: We have to workaround a Sword bug, we have to set the default locale to the same as the sourceLanguage !
+ const QString oldLocaleName = CPointers::backend()->booknameLanguage();
+ CPointers::backend()->booknameLanguage(sourceLanguage);
+
+ sword::VerseKey dummy;
+ dummy.setLocale( sourceLanguage.toUtf8().constData() );
+ Q_ASSERT( !strcmp(dummy.getLocale(), sourceLanguage.toUtf8().constData()) );
+
+// qDebug("Parsing '%s' in '%s' using '%s' as base, source lang '%s', dest lang '%s'", ref.latin1(), options.refDestinationModule.latin1(), baseKey.key().latin1(), sourceLanguage.latin1(), destinationLanguage.latin1());
+
+ for (QStringList::iterator it = refList.begin(); it != refList.end(); it++) {
+ //The listkey may contain more than one item, because a ref lik "Gen 1:3,5" is parsed into two single refs
+ sword::ListKey lk = dummy.ParseVerseList((*it).toUtf8().constData(), baseKey.key().toUtf8().constData(), true);
+ Q_ASSERT(!dummy.Error());
+
+ //Q_ASSERT(lk.Count());
+ if (!lk.Count()) {
+ ret.append( *it ); //don't change the original
+ continue;
+ }
+
+ for (int i = 0; i < lk.Count(); ++i) {
+ if (dynamic_cast<sword::VerseKey*>(lk.getElement(i))) { // a range
+ sword::VerseKey* k = dynamic_cast<sword::VerseKey*>(lk.getElement(i));
+ Q_ASSERT(k);
+ k->setLocale( destinationLanguage.toUtf8().constData() );
+
+ ret.append( QString::fromUtf8(k->getRangeText()) ).append("; ");
+ }
+ else { // a single ref
+ sword::VerseKey vk;
+ vk.setLocale( sourceLanguage.toUtf8().constData() );
+ vk = lk.getElement(i)->getText();
+ vk.setLocale( destinationLanguage.toUtf8().constData() );
+
+ ret.append( QString::fromUtf8(vk.getText()) ).append("; ");
+ }
+ }
+
+ }
+
+ CPointers::backend()->booknameLanguage(oldLocaleName);
+ return ret;
+}
diff --git a/src/backend/managers/creferencemanager.h b/src/backend/managers/creferencemanager.h
new file mode 100644
index 0000000..19baae7
--- /dev/null
+++ b/src/backend/managers/creferencemanager.h
@@ -0,0 +1,110 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CREFERENCEMANAGER_H
+#define CREFERENCEMANAGER_H
+
+#include "backend/drivers/cswordmoduleinfo.h"
+
+//Qt includes
+#include <QString>
+
+/** Contains static functions to work with references used for Drag & Drop and for hyperlinks used in our
+ * rendered HTML code.
+ * @author The BibleTime team
+ */
+
+class CReferenceManager {
+
+public:
+ enum Type {
+ Bible, /**< Bibles */
+ Commentary, /**< Commentary */
+ Lexicon, /**< Lexicon */
+ GenericBook, /**< Generic Book */
+ MorphHebrew, /**< Module for hebrew morphology*/
+ MorphGreek, /**< Module for greek morphology */
+ StrongsHebrew, /**< Module for hebrew strongs */
+ StrongsGreek, /**< Module for greek strongs */
+ Unknown /**< Unknown */
+ };
+
+ /** Turn a hyperlink into module, key and type.
+ * Decodes the given hyperlink into module, key and type.
+ * @param hyperlink The hyperlink to decode
+ * @param module The string which will contain the module name after decoding
+ * @param key The string which will contain the key after decoding
+ * @param type The type param will contain the reference type after decoding
+ */
+ static bool decodeHyperlink( const QString& hyperlink, QString& module, QString& key, Type& type);
+ /**
+ * Returns a hyperlink used to be embedded in the display windows.
+ * At the moment the format is sword://module/key
+ * @param module The module which is used to encode the hyperlink
+ * @param key The key which is used to encode the hyperlink
+ * @param type The type which is used to encode the hyperlink
+ * @return The encoded hyperlink
+ */
+ static const QString encodeHyperlink( const QString module, const QString key, const Type type);
+ /**
+ * Puts a module Name and a Reference together in the 'draggable' form
+ * (module)reference
+ * @param module The name of the module
+ * @param reference The key reference as text
+ * @return The encoded reference using module and reference
+ * @author Martin Gruner
+ */
+ static const QString encodeReference(const QString &module, const QString &reference);
+ /**
+ * decodes a 'draggable' reference into a modulename and a reference
+ * @author Martin Gruner
+ */
+ static void decodeReference(QString &dragreference, QString &module, QString &reference);
+ /**
+ * Returns true if the parameter is a hyperlink.
+ * @param hyperlink The string which is tested
+ * @return True if the passed string is a hyperlink
+ */
+ static bool isHyperlink( const QString& hyperlink );
+ /**
+ * Returns the preferred module name for the given type.
+ * @param type The type which is used to find the module
+ * @return The default module name for the passed type
+ */
+ static const QString preferredModule( const Type type );
+ /**
+ * Returns the type of the passed module type
+ * @param type The CSwordModuleInfo module typpe
+ * @return The ReferenceManager type
+ */
+ static CReferenceManager::Type typeFromModule( const CSwordModuleInfo::ModuleType type );
+
+
+ struct ParseOptions {
+ QString refDestinationModule;
+ QString refBase; /* only valid for verse based destination modules*/
+ QString sourceLanguage; /* only valid for verse based destination modules*/
+ QString destinationLanguage; /* only valid for verse based destination modules*/
+
+ ParseOptions() {
+ destinationLanguage = "en";
+ };
+ };
+
+ /** Parses the given verse references using the given language and the module.
+ * @param moduleName The name of the module to use. Required for the language checking before parsing the key.
+ * @param ref The verse reference.
+ * @param lang The language of the verse reference
+ * @param newLang The language of the reference, which will be returned. For example: If BibleTime using an english environment parses a spanish ref (lang=es) the returned ref should be in english (newLang=en), because his english standard module only understands en.
+ */
+ static const QString parseVerseReference( const QString& ref, const ParseOptions& options);
+};
+
+#endif
+
diff --git a/src/backend/managers/cswordbackend.cpp b/src/backend/managers/cswordbackend.cpp
new file mode 100644
index 0000000..0afe467
--- /dev/null
+++ b/src/backend/managers/cswordbackend.cpp
@@ -0,0 +1,555 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cswordbackend.h"
+
+#include "backend/rendering/centrydisplay.h"
+#include "backend/rendering/cbookdisplay.h"
+#include "backend/rendering/cchapterdisplay.h"
+#include "backend/drivers/cswordbiblemoduleinfo.h"
+#include "backend/drivers/cswordcommentarymoduleinfo.h"
+#include "backend/drivers/cswordlexiconmoduleinfo.h"
+#include "backend/drivers/cswordbookmoduleinfo.h"
+#include "backend/filters/bt_thmlhtml.h"
+#include "backend/filters/bt_thmlplain.h"
+#include "backend/filters/bt_osishtml.h"
+#include "backend/filters/bt_gbfhtml.h"
+#include "backend/filters/bt_plainhtml.h"
+#include "backend/filters/osismorphsegmentation.h"
+
+#include "backend/config/cbtconfig.h"
+
+#include "util/directoryutil.h"
+
+#include <dirent.h>
+
+//Qt
+#include <QString>
+#include <QDir>
+#include <QFileInfo>
+#include <QSet>
+#include <QDebug>
+
+//Sword
+#include <swdisp.h>
+#include <swfiltermgr.h>
+#include <encfiltmgr.h>
+#include <rtfhtml.h>
+#include <filemgr.h>
+#include <utilstr.h>
+#include <swfilter.h>
+
+using namespace Filters;
+using namespace Rendering;
+
+CSwordBackend::CSwordBackend()
+ : sword::SWMgr(0, 0, false, new sword::EncodingFilterMgr( sword::ENC_UTF8 ), true)
+{
+ m_filters.gbf = new BT_GBFHTML();
+ m_filters.plain = new BT_PLAINHTML();
+ m_filters.thml = new BT_ThMLHTML();
+ m_filters.osis = new BT_OSISHTML();
+
+ m_displays.entry = new CEntryDisplay();
+ m_displays.chapter = new CChapterDisplay();
+ m_displays.book = new CBookDisplay();
+
+ filterInit();
+}
+
+CSwordBackend::CSwordBackend(const QString& path, const bool augmentHome)
+ : sword::SWMgr(!path.isEmpty() ? path.toLocal8Bit().constData() : 0, false, new sword::EncodingFilterMgr( sword::ENC_UTF8 ), false, augmentHome) // don't allow module renaming, because we load from a path
+{
+ m_filters.gbf = new BT_GBFHTML();
+ m_filters.plain = new BT_PLAINHTML();
+ m_filters.thml = new BT_ThMLHTML();
+ m_filters.osis = new BT_OSISHTML();
+
+ m_displays.entry = new CEntryDisplay();
+ m_displays.chapter = new CChapterDisplay();
+ m_displays.book = new CBookDisplay();
+
+ filterInit();
+}
+
+CSwordBackend::~CSwordBackend() {
+ shutdownModules();
+
+ delete m_filters.gbf;
+ delete m_filters.plain;
+ delete m_filters.thml;
+ delete m_filters.osis;
+
+ delete m_displays.book;
+ delete m_displays.chapter;
+ delete m_displays.entry;
+}
+
+void CSwordBackend::filterInit() {
+ //HACK: replace Sword's OSISMorphSegmentation filter, seems to be buggy, ours works
+ if (sword::SWOptionFilter* filter = optionFilters["OSISMorphSegmentation"])
+ {
+ cleanupFilters.remove(filter);
+ optionFilters.erase("OSISMorphSegmentation");
+ delete filter;
+ }
+ sword::SWOptionFilter* tmpFilter = new OSISMorphSegmentation();
+ optionFilters.insert(sword::OptionFilterMap::value_type("OSISMorphSegmentation", tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+
+ //HACK: replace Sword's ThML strip filter with our own version
+ //remove this hack as soon as Sword is fixed
+ cleanupFilters.remove(thmlplain);
+ delete thmlplain;
+ thmlplain = new BT_ThMLPlain();
+ cleanupFilters.push_back(thmlplain);
+}
+
+QList<CSwordModuleInfo*> CSwordBackend::takeModulesFromList(QStringList names)
+{
+ int numberOfRemoved = 0;
+ QList<CSwordModuleInfo*> list;
+ foreach(QString name, names) {
+ CSwordModuleInfo* mInfo = findModuleByName(name);
+ if (mInfo) {
+ m_moduleList.removeAll(mInfo);
+ ++numberOfRemoved;
+ list.append(mInfo);
+ }
+ }
+ if (numberOfRemoved > 0)
+ emit sigSwordSetupChanged(RemovedModules);
+ return list;
+}
+
+/** Initializes the Sword modules. */
+CSwordBackend::LoadError CSwordBackend::initModules(SetupChangedReason reason) {
+ // qWarning("globalSwordConfigPath is %s", globalConfPath);
+ LoadError ret = NoError;
+
+ shutdownModules(); //remove previous modules
+ m_moduleList.clear();
+
+ sword::ModMap::iterator end = Modules.end();
+ ret = LoadError( Load() );
+
+ for (sword::ModMap::iterator it = Modules.begin(); it != end; it++) {
+ sword::SWModule* const curMod = (*it).second;
+ CSwordModuleInfo* newModule = 0;
+
+ if (!strcmp(curMod->Type(), "Biblical Texts")) {
+ newModule = new CSwordBibleModuleInfo(curMod, this);
+ newModule->module()->Disp(m_displays.chapter);
+ }
+ else if (!strcmp(curMod->Type(), "Commentaries")) {
+ newModule = new CSwordCommentaryModuleInfo(curMod, this);
+ newModule->module()->Disp(m_displays.entry);
+ }
+ else if (!strcmp(curMod->Type(), "Lexicons / Dictionaries")) {
+ newModule = new CSwordLexiconModuleInfo(curMod, this);
+ newModule->module()->Disp(m_displays.entry);
+ }
+ else if (!strcmp(curMod->Type(), "Generic Books")) {
+ newModule = new CSwordBookModuleInfo(curMod, this);
+ newModule->module()->Disp(m_displays.book);
+ }
+
+ if (newModule) {
+ //Append the new modules to our list, but only if it's supported
+ //The constructor of CSwordModuleInfo prints a warning on stdout
+ if (!newModule->hasVersion() || (newModule->minimumSwordVersion() <= sword::SWVersion::currentVersion)) {
+ m_moduleList.append( newModule );
+ }
+ else
+ {
+ delete newModule;
+ }
+ }
+ }
+
+ QList<CSwordModuleInfo*>::iterator end_it = m_moduleList.end();
+
+ foreach (CSwordModuleInfo* mod, m_moduleList) {
+ m_moduleDescriptionMap.insert( mod->config(CSwordModuleInfo::Description), mod->name() );
+ //unlock modules if keys are present
+ if ( mod->isEncrypted() ) {
+ const QString unlockKey = CBTConfig::getModuleEncryptionKey( mod->name() );
+ if (!unlockKey.isNull()) {
+ setCipherKey( mod->name().toUtf8().constData(), unlockKey.toUtf8().constData() );
+ }
+ }
+ }
+
+ emit sigSwordSetupChanged(reason);
+ return ret;
+}
+
+void CSwordBackend::AddRenderFilters(sword::SWModule *module, sword::ConfigEntMap &section) {
+ sword::SWBuf moduleDriver;
+ sword::SWBuf sourceformat;
+ sword::ConfigEntMap::iterator entry;
+ bool noDriver = true;
+
+ sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (sword::SWBuf) "";
+ moduleDriver = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (sword::SWBuf) "";
+
+ if (sourceformat == "GBF") {
+ module->AddRenderFilter(m_filters.gbf);
+ noDriver = false;
+ }
+ else if (sourceformat == "PLAIN") {
+ module->AddRenderFilter(m_filters.plain);
+ noDriver = false;
+ }
+ else if (sourceformat == "ThML") {
+ module->AddRenderFilter(m_filters.thml);
+ noDriver = false;
+ }
+ else if (sourceformat == "OSIS") {
+ module->AddRenderFilter(m_filters.osis);
+ noDriver = false;
+ }
+
+ if (noDriver) { //no driver found
+ if ( (moduleDriver == "RawCom") || (moduleDriver == "RawLD") ) {
+ module->AddRenderFilter(m_filters.plain);
+ noDriver = false;
+ }
+ }
+}
+
+/** This function deinitializes the modules and deletes them. */
+bool CSwordBackend::shutdownModules() {
+ QList<CSwordModuleInfo*>::iterator it = m_moduleList.begin();
+ QList<CSwordModuleInfo*>::iterator end = m_moduleList.end();
+
+ while (it != end) {
+ CSwordModuleInfo* current = (*it);
+ it = m_moduleList.erase(it);
+ delete current;
+ }
+
+ Q_ASSERT(m_moduleList.count() == 0);
+ //BT mods are deleted now, delete Sword mods, too.
+ DeleteMods();
+
+ /* Cipher filters must be handled specially, because SWMgr creates them,
+ * stores them in cipherFilters and cleanupFilters and attaches them to locked
+ * modules. If these modules are removed, the filters need to be removed as well,
+ * so that they are re-created for the new module objects.
+ */
+ sword::FilterMap::iterator cipher_it;
+ for (cipher_it = cipherFilters.begin(); cipher_it != cipherFilters.end(); cipher_it++)
+ {
+ //Delete the Filter and remove it from the cleanup list
+ cleanupFilters.remove(cipher_it->second);
+ delete cipher_it->second;
+ }
+ cipherFilters.clear();
+
+ return true;
+}
+
+void CSwordBackend::setOption( const CSwordModuleInfo::FilterTypes type, const int state ) {
+ sword::SWBuf value;
+
+ switch (type) {
+
+ case CSwordModuleInfo::textualVariants:
+
+ if (state == 0) {
+ value = "Primary Reading";
+ }
+ else if (state == 1) {
+ value = "Secondary Reading";
+ }
+ else {
+ value = "All Readings";
+ }
+
+ break;
+
+ default:
+ value = state ? "On": "Off";
+ break;
+ };
+
+ if (value.length())
+ setGlobalOption(optionName(type).toUtf8().constData(), value.c_str());
+}
+
+void CSwordBackend::setFilterOptions( const CSwordBackend::FilterOptions options) {
+ setOption( CSwordModuleInfo::footnotes, options.footnotes );
+ setOption( CSwordModuleInfo::strongNumbers, options.strongNumbers );
+ setOption( CSwordModuleInfo::headings, options.headings );
+ setOption( CSwordModuleInfo::morphTags, options.morphTags );
+ setOption( CSwordModuleInfo::lemmas, options.lemmas );
+ setOption( CSwordModuleInfo::hebrewPoints, options.hebrewPoints );
+ setOption( CSwordModuleInfo::hebrewCantillation, options.hebrewCantillation );
+ setOption( CSwordModuleInfo::greekAccents, options.greekAccents );
+ setOption( CSwordModuleInfo::redLetterWords, options.redLetterWords );
+ setOption( CSwordModuleInfo::textualVariants, options.textualVariants );
+ setOption( CSwordModuleInfo::morphSegmentation, options.morphSegmentation );
+ // setOption( CSwordModuleInfo::transliteration, options.transliteration );
+ setOption( CSwordModuleInfo::scriptureReferences, options.scriptureReferences);
+}
+
+/** This function searches for a module with the specified description */
+CSwordModuleInfo* CSwordBackend::findModuleByDescription(const QString& description) {
+ foreach(CSwordModuleInfo* mod, m_moduleList) {
+ if (mod->config(CSwordModuleInfo::Description) == description) return mod;
+ }
+ return 0;
+}
+
+/** This function searches for a module with the specified description */
+const QString CSwordBackend::findModuleNameByDescription(const QString& description) {
+ if (m_moduleDescriptionMap.contains(description)) {
+ return m_moduleDescriptionMap[description];
+ }
+ return QString::null;
+}
+
+/** This function searches for a module with the specified name */
+CSwordModuleInfo* CSwordBackend::findModuleByName(const QString& name) {
+ foreach(CSwordModuleInfo* mod, m_moduleList) {
+ if (mod->name() == name) return mod;
+ }
+ return 0;
+}
+
+CSwordModuleInfo* CSwordBackend::findSwordModuleByPointer(const sword::SWModule* const swmodule) {
+ foreach(CSwordModuleInfo* mod, m_moduleList) {
+ if (mod->module() == swmodule ) return mod;
+ }
+ return 0;
+}
+
+CSwordModuleInfo* CSwordBackend::findModuleByPointer(const CSwordModuleInfo* const module) {
+ foreach(CSwordModuleInfo* mod, m_moduleList) {
+ if (mod == module) return mod;
+ }
+ return 0;
+}
+
+/** Returns our local config object to store the cipher keys etc. locally for each user. The values of the config are merged with the global config. */
+bool CSwordBackend::moduleConfig(const QString& module, sword::SWConfig& moduleConfig) {
+ sword::SectionMap::iterator section;
+ DIR *dir = opendir(configPath);
+
+ struct dirent *ent;
+
+ bool foundConfig = false;
+ QString modFile;
+
+ if (dir) { // find and update .conf file
+ rewinddir(dir);
+
+ while ((ent = readdir(dir)) && !foundConfig) {
+ if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
+ modFile = QString(configPath);
+ modFile.append("/");
+ modFile.append( QString::fromLocal8Bit(ent->d_name) );
+
+ moduleConfig = sword::SWConfig( modFile.toLocal8Bit().constData() );
+ section = moduleConfig.Sections.find( module.toLocal8Bit().constData() );
+ foundConfig = ( section != moduleConfig.Sections.end() );
+ }
+ }
+
+ closedir(dir);
+ }
+ else { //try to read mods.conf
+ moduleConfig = sword::SWConfig("");//global config
+ section = config->Sections.find( module.toLocal8Bit().constData() );
+ foundConfig = ( section != config->Sections.end() );
+
+ sword::ConfigEntMap::iterator entry;
+
+ if (foundConfig) { //copy module section
+
+ for (entry = section->second.begin(); entry != section->second.end(); entry++) {
+ moduleConfig.Sections[section->first].insert(sword::ConfigEntMap::value_type(entry->first, entry->second));
+ }
+ }
+ }
+
+ if (!foundConfig && configType != 2) { //search in $HOME/.sword/
+
+ QString myPath = util::filesystem::DirectoryUtil::getUserHomeDir().absolutePath();
+ myPath.append("/.sword/mods.d");
+ dir = opendir(myPath.toUtf8().constData());
+
+ if (dir) {
+ rewinddir(dir);
+
+ while ((ent = readdir(dir)) && !foundConfig) {
+ if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
+ modFile = myPath;
+ modFile.append('/');
+ modFile.append(ent->d_name);
+ moduleConfig = sword::SWConfig( modFile.toLocal8Bit().constData() );
+ section = moduleConfig.Sections.find( module.toLocal8Bit().constData() );
+ foundConfig = ( section != moduleConfig.Sections.end() );
+ }
+ }
+
+ closedir(dir);
+ }
+ }
+
+ return foundConfig;
+}
+
+/** Returns the text used for the option given as parameter. */
+const QString CSwordBackend::optionName( const CSwordModuleInfo::FilterTypes option ) {
+ switch (option) {
+ case CSwordModuleInfo::footnotes: return QString("Footnotes");
+ case CSwordModuleInfo::strongNumbers: return QString("Strong's Numbers");
+ case CSwordModuleInfo::headings: return QString("Headings");
+ case CSwordModuleInfo::morphTags: return QString("Morphological Tags");
+ case CSwordModuleInfo::lemmas: return QString("Lemmas");
+ case CSwordModuleInfo::hebrewPoints: return QString("Hebrew Vowel Points");
+ case CSwordModuleInfo::hebrewCantillation: return QString("Hebrew Cantillation");
+ case CSwordModuleInfo::greekAccents: return QString("Greek Accents");
+ case CSwordModuleInfo::redLetterWords: return QString("Words of Christ in Red");
+ case CSwordModuleInfo::textualVariants: return QString("Textual Variants");
+ case CSwordModuleInfo::scriptureReferences: return QString("Cross-references");
+ case CSwordModuleInfo::morphSegmentation: return QString("Morph Segmentation");
+ }
+ return QString::null;
+}
+
+/** Returns the translated name of the option given as parameter. */
+const QString CSwordBackend::translatedOptionName(const CSwordModuleInfo::FilterTypes option) {
+ switch (option) {
+ case CSwordModuleInfo::footnotes: return QObject::tr("Footnotes");
+ case CSwordModuleInfo::strongNumbers: return QObject::tr("Strong's numbers");
+ case CSwordModuleInfo::headings: return QObject::tr("Headings");
+ case CSwordModuleInfo::morphTags: return QObject::tr("Morphological tags");
+ case CSwordModuleInfo::lemmas: return QObject::tr("Lemmas");
+ case CSwordModuleInfo::hebrewPoints: return QObject::tr("Hebrew vowel points");
+ case CSwordModuleInfo::hebrewCantillation: return QObject::tr("Hebrew cantillation marks");
+ case CSwordModuleInfo::greekAccents: return QObject::tr("Greek accents");
+ case CSwordModuleInfo::redLetterWords: return QObject::tr("Red letter words");
+ case CSwordModuleInfo::textualVariants: return QObject::tr("Textual variants");
+ case CSwordModuleInfo::scriptureReferences: return QObject::tr("Scripture cross-references");
+ case CSwordModuleInfo::morphSegmentation: return QObject::tr("Morph segmentation");
+ }
+ return QString::null;
+}
+
+
+const QString CSwordBackend::configOptionName( const CSwordModuleInfo::FilterTypes option ) {
+ switch (option) {
+ case CSwordModuleInfo::footnotes: return QString("Footnotes");
+ case CSwordModuleInfo::strongNumbers: return QString("Strongs");
+ case CSwordModuleInfo::headings: return QString("Headings");
+ case CSwordModuleInfo::morphTags: return QString("Morph");
+ case CSwordModuleInfo::lemmas: return QString("Lemma");
+ case CSwordModuleInfo::hebrewPoints: return QString("HebrewPoints");
+ case CSwordModuleInfo::hebrewCantillation: return QString("Cantillation");
+ case CSwordModuleInfo::greekAccents: return QString("GreekAccents");
+ case CSwordModuleInfo::redLetterWords: return QString("RedLetterWords");
+ case CSwordModuleInfo::textualVariants: return QString("Variants");
+ case CSwordModuleInfo::scriptureReferences: return QString("Scripref");
+ case CSwordModuleInfo::morphSegmentation: return QString("MorphSegmentation");
+ }
+ return QString::null;
+}
+
+const QString CSwordBackend::booknameLanguage( const QString& language ) {
+ if (!language.isEmpty()) {
+ sword::LocaleMgr::getSystemLocaleMgr()->setDefaultLocaleName( language.toUtf8().constData() );
+
+ //refresh the locale of all Bible and commentary modules!
+ //use what sword returns, language may be different
+ QString newLocaleName( sword::LocaleMgr::getSystemLocaleMgr()->getDefaultLocaleName() );
+
+ foreach(CSwordModuleInfo* mod, m_moduleList) {
+ if ( (mod->type() == CSwordModuleInfo::Bible) || (mod->type() == CSwordModuleInfo::Commentary) ) {
+ //Create a new key, it will get the default bookname language
+ ((sword::VerseKey*)(mod->module()->getKey()))->setLocale( newLocaleName.toUtf8().constData() );
+ }
+ }
+
+ }
+ return QString( sword::LocaleMgr::getSystemLocaleMgr()->getDefaultLocaleName() );
+}
+
+
+/** Reload all Sword modules. */
+void CSwordBackend::reloadModules(SetupChangedReason reason) {
+ shutdownModules();
+
+ //delete Sword's config to make Sword reload it!
+
+ if (myconfig) { // force reload on config object because we may have changed the paths
+ delete myconfig;
+ config = myconfig = 0;
+ // we need to call findConfig to make sure that augPaths are reloaded
+#ifdef SWORD_SYSCONF_CHANGED
+ findConfig(&configType, &prefixPath, &configPath, &augPaths, &sysConfig);
+#else
+ findConfig(&configType, &prefixPath, &configPath, &augPaths, sysconfig);
+#endif
+ // now re-read module configuration files
+ loadConfigDir(configPath);
+ }
+ else if (config) {
+ config->Load();
+ }
+
+ initModules(reason);
+}
+
+const QStringList CSwordBackend::swordDirList() {
+ QSet<QString> ret;
+ const QString home = util::filesystem::DirectoryUtil::getUserHomeDir().absolutePath();
+
+ //return a list of used Sword dirs. Useful for the installer
+ QString configPath = QString("%1/.sword/sword.conf").arg(home);
+
+ if (!QFile(configPath).exists()) {
+ configPath = globalConfPath; //e.g. /etc/sword.conf, /usr/local/etc/sword.conf
+ }
+
+ QStringList configs = configPath.split(":");
+
+ for (QStringList::const_iterator it = configs.begin(); it != configs.end(); ++it) {
+ if (!QFileInfo(*it).exists()) {
+ continue;
+ }
+
+ //get all DataPath and AugmentPath entries from the config file and add them to the list
+ sword::SWConfig conf( (*it).toUtf8().constData() );
+ ret << conf["Install"]["DataPath"].c_str();
+ sword::ConfigEntMap group = conf["Install"];
+ sword::ConfigEntMap::iterator start = group.equal_range("AugmentPath").first;
+ sword::ConfigEntMap::iterator end = group.equal_range("AugmentPath").second;
+
+ for (sword::ConfigEntMap::const_iterator it = start; it != end; ++it) {
+ ret << QDir(it->second.c_str()).absolutePath(); //added augment path
+ }
+ }
+
+ if (!home.isEmpty()) {
+ // This is added to the set if not there already. Notice that
+ // this prevents duplication only if the QDir::absolutePath() returns
+ // string without the prepended "/".
+ ret << home + "/.sword";
+ }
+
+ return ret.values();
+}
+
+void CSwordBackend::notifyChange(SetupChangedReason reason)
+{
+ emit sigSwordSetupChanged(reason);
+}
diff --git a/src/backend/managers/cswordbackend.h b/src/backend/managers/cswordbackend.h
new file mode 100644
index 0000000..0ffb484
--- /dev/null
+++ b/src/backend/managers/cswordbackend.h
@@ -0,0 +1,273 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CSWORDBACKEND_H
+#define CSWORDBACKEND_H
+
+//BibleTime includes
+#include "backend/drivers/cswordmoduleinfo.h"
+
+//Qt includes
+#include <QObject>
+#include <QMap>
+#include <QString>
+#include <QStringList>
+
+//Sword includes
+#include <swmgr.h>
+#include <swbuf.h>
+#include <swmodule.h>
+#include <swversion.h>
+#include <localemgr.h>
+#include <utilstr.h>
+
+//forward declarations
+namespace Rendering {
+ class CEntryDisplay;
+ class CChapterDisplay;
+ class CBookDisplay;
+}
+
+/** The backend layer main class.
+ * This is the implementation of CBackend for Sword. It's additionally derived from SWMgr
+ * to provide functions of Sword.
+ *
+ * @short The backend implementation of Sword
+ * @author The BibleTime team
+ * @version $Id: cswordbackend.h,v 1.58 2007/03/14 21:32:47 joachim Exp $
+ */
+
+class CSwordBackend : public QObject, public sword::SWMgr
+{
+ Q_OBJECT
+public:
+
+ /** The reason for the sigSwordSetupChanged signal, i.e. why the module list has changed. */
+ enum SetupChangedReason {
+ AddedModules = 1,
+ RemovedModules = 2,
+ HidedModules = 4,
+ PathChanged = 8,
+ OtherChange = 16
+ };
+
+ /** Filter options. Filter options to
+ * control the text display of modules. Uses int and not bool because not all
+ * options have just two toggle values.
+ */
+ struct FilterOptions {
+ int footnotes; /**< 0 for disabled, 1 for enabled */
+ int strongNumbers; /**< 0 for disabled, 1 for enabled */
+ int headings; /**< 0 for disabled, 1 for enabled */
+ int morphTags; /**< 0 for disabled, 1 for enabled */
+ int lemmas; /**< 0 for disabled, 1 for enabled */
+ int hebrewPoints; /**< 0 for disabled, 1 for enabled */
+ int hebrewCantillation; /**< 0 for disabled, 1 for enabled */
+ int greekAccents; /**< 0 for disabled, 1 for enabled */
+ int textualVariants; /**< Number n to enabled the n-th variant */
+ int redLetterWords; /**< 0 for disabled, 1 for enabled */
+ int scriptureReferences; /**< 0 for disabled, 1 for enabled */
+ int morphSegmentation; /**< 0 for disabled, 1 for enabled */
+ };
+
+ /** Control the display of a text.
+ */
+ struct DisplayOptions {
+ int lineBreaks;
+ int verseNumbers;
+ };
+
+ /** The error codes which may be returned by the @ref Load() call.
+ */
+ enum LoadError { // the values exist to cast from the char return of SWMgr::Load
+ NoSwordConfig = -1,
+ NoError = 0,
+ NoModules = 1
+ };
+ /**
+ * The constructor of the Sword backend.
+ * It creates the SWModule objects using SWMgr's methods, it adds the necessary
+ * filters for the module format.
+ */
+ CSwordBackend();
+ /**
+ * The constructor of the Sword backend. This is actually used nowhere.
+ * Notice that using augmentHome=false can mess up the system because it is true elsewhere.
+ * @param path The path which is used to load modules
+ * @param augmentHome True if the $HOME/.sword/ modules should be augmented with the other modules
+ */
+ CSwordBackend( const QString& path, const bool augmentHome = true );
+
+ /**
+ * The destrctor of this backend. This function shuts the modules down using @ref shutdownModules.
+ */
+ virtual ~CSwordBackend();
+
+ /**
+ * This function returns the list of available modules managed by this backend.
+ * You have to call initModules() first;
+ *
+ * @return The list of modules managed by this backend
+ */
+ inline virtual QList<CSwordModuleInfo*>& moduleList();
+ /**
+ * Initializes the Sword modules.
+ *
+ * @return True if the initializiation was succesful, otherwise return false.
+ */
+ virtual CSwordBackend::LoadError initModules(SetupChangedReason reason);
+ /**
+ * This function deinitializes the modules and deletes them.
+ *
+ * @return True if it was succesful, otherwise return false
+ */
+ virtual bool shutdownModules();
+ /**
+ * Sets the given options enabled or disabled depending on the second parameter.
+ *
+ * @param type This is the type this function should set enabled or disabled
+ * @param enable If this is true the option will be enabled, otherwise it will be disabled.
+ */
+ void setOption( const CSwordModuleInfo::FilterTypes type, const int state );
+ /** */
+ void setFilterOptions( const CSwordBackend::FilterOptions options );
+ /**
+ * Sets the language for the international booknames of Sword.
+ * @param langName The abbreviation string which should be used for the Sword backend
+ */
+ const QString booknameLanguage( const QString& langName = QString::null );
+ /**
+ * This function searches for a module with the specified description
+ * @param description The description of the desired module
+ * @return pointer to the desired module; null if no module has the specified description
+ */
+ virtual CSwordModuleInfo* findModuleByDescription(const QString& description);
+ /**
+ * This function searches for a module with the specified description
+ * @param description The description of the desired module
+ * @return pointer to the desired module; null if no module has the specified description
+ */
+ const QString findModuleNameByDescription(const QString& description);
+ /**
+ * This function searches for a module with the specified name
+ * @param name The name of the desired module
+ * @return Pointer to the desired module; null if no module has the specified name
+ */
+ CSwordModuleInfo* findModuleByName(const QString& name);
+ /**
+ * This function searches for a module with the specified sword module as module() object!
+ * @param swmodule to a Sword module
+ * @return pointer to the desired module; null if no module has the specified name
+ */
+ CSwordModuleInfo* findSwordModuleByPointer(const sword::SWModule* const swmodule);
+ /**
+ * This function searches for a module which is the same as the passed module.
+ * @param module The module which should be used for searching the new one. May be child of a different backend.
+ * @return Pointer to the desired module; null if no module has the specified name
+ */
+ CSwordModuleInfo* findModuleByPointer(const CSwordModuleInfo* const module);
+ /**
+ * @return Our global config object which contains the configs of all modules merged together.
+ */
+ inline sword::SWConfig* getConfig() const;
+ /**
+ * Tries to find the config object for the module. The second paramter will be the found config.
+ * @return True if the config was found, false if not. If false is returned the moduleConfig object is in undefined/unknwon state.
+ */
+ bool moduleConfig(const QString& module, sword::SWConfig& moduleConfig );
+ /**
+ * Returns the text used for the option given as parameter.
+ * @param The paramter enum
+ * @return The name of the option given by the parameter
+ */
+ static const QString optionName( const CSwordModuleInfo::FilterTypes option );
+ /**
+ * Returns the text used for the option given as parameter.
+ */
+ static const QString configOptionName( const CSwordModuleInfo::FilterTypes option );
+ /**
+ * Returns the translated name of the option given as parameter.
+ * @param The translated option name
+ */
+ static const QString translatedOptionName(const CSwordModuleInfo::FilterTypes option );
+ /**
+ * Returns the version of the Sword library.
+ * @return The version used by this backend
+ */
+ inline virtual const sword::SWVersion Version();
+ /**
+ * Reload all Sword modules.
+ */
+ void reloadModules(SetupChangedReason reason);
+
+ /**
+ * Takes off the given modules from the list and returns them.
+ * User must take care of the deletion of the returned CSwordModuleInfo pointers.
+ */
+ QList<CSwordModuleInfo*> takeModulesFromList(QStringList names);
+
+ /** Sword prefix list.
+ * @return A list of all known Sword prefix dirs
+ */
+ const QStringList swordDirList();
+
+ /** Emits the sigSwordSetupChanged signal.
+ * This can be called directly from outside if there is no need to reload the backend.
+ */
+ void notifyChange(SetupChangedReason reason);
+
+signals:
+ void sigSwordSetupChanged(CSwordBackend::SetupChangedReason reason);
+
+protected:
+ /**
+ * Adds a render filter to the module.
+ * This is used to apply our own render filters to our modules instead of the sword filters
+ */
+ virtual void AddRenderFilters(sword::SWModule *module, sword::ConfigEntMap &section);
+ /**
+ * Overrides Sword filters which appear to be buggy.
+ */
+ virtual void filterInit();
+
+private:
+ // Filters
+ struct Filters {
+ sword::SWFilter* gbf;
+ sword::SWFilter* plain;
+ sword::SWFilter* thml;
+ sword::SWFilter* osis;
+ } m_filters;
+
+ struct Displays {
+ Rendering::CChapterDisplay* chapter;
+ Rendering::CEntryDisplay* entry;
+ Rendering::CBookDisplay* book;
+ } m_displays;
+
+ QList<CSwordModuleInfo*> m_moduleList;
+ QMap<QString, QString> m_moduleDescriptionMap;
+};
+
+/**Returns The list of modules managed by this backend*/
+inline QList<CSwordModuleInfo*>& CSwordBackend::moduleList() {
+ return m_moduleList;
+}
+
+/** Returns our local config object to store the cipher keys etc. locally for each user. The values of the config are merged with the global config. */
+inline sword::SWConfig* CSwordBackend::getConfig() const {
+ return config;
+}
+
+/** Returns the version of the Sword library. */
+inline const sword::SWVersion CSwordBackend::Version() {
+ return sword::SWVersion::currentVersion;
+}
+
+#endif
diff --git a/src/backend/rendering/cbookdisplay.cpp b/src/backend/rendering/cbookdisplay.cpp
new file mode 100644
index 0000000..fd57034
--- /dev/null
+++ b/src/backend/rendering/cbookdisplay.cpp
@@ -0,0 +1,136 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//Backend
+#include "cbookdisplay.h"
+#include "cdisplayrendering.h"
+#include "backend/drivers/cswordbookmoduleinfo.h"
+#include "backend/keys/cswordtreekey.h"
+
+//Util
+#include <boost/scoped_ptr.hpp>
+
+/** Returns the rendered text using the modules in the list and using the key parameter. The displayoptions and filter options are used, too. */
+const QString Rendering::CBookDisplay::text( const QList<CSwordModuleInfo*>& modules, const QString& keyName, const CSwordBackend::DisplayOptions displayOptions, const CSwordBackend::FilterOptions filterOptions ) {
+ CSwordBookModuleInfo* book = dynamic_cast<CSwordBookModuleInfo*>(modules.first());
+ Q_ASSERT(book);
+
+ CSwordBackend::DisplayOptions dOpts = displayOptions;
+ dOpts.lineBreaks = true; //books should render with blocks, not with inlined sections
+
+ CDisplayRendering render(dOpts, filterOptions);
+ CDisplayRendering::KeyTree tree;
+ CDisplayRendering::KeyTreeItem::Settings itemSettings;
+
+ // the number of levels which should be display together, 1 means display no entries together
+ int displayLevel = book->config( CSwordModuleInfo::DisplayLevel ).toInt();
+
+ boost::scoped_ptr<CSwordTreeKey> key (
+ dynamic_cast<CSwordTreeKey*>( CSwordKey::createInstance(book) )
+ );
+ key->key(keyName); //set the key to position we'd like to get
+
+ const unsigned long offset = key->getOffset();
+
+ // standard of DisplayLevel, display nothing together
+ // if the current key is the root entry don't display anything together!
+
+ if ((displayLevel <= 1) || (key->key().isEmpty() || (key->key() == "/") )) {
+ tree.append( new CDisplayRendering::KeyTreeItem( key->key(), modules, itemSettings ) );
+
+ const QString renderedText = render.renderKeyTree(tree);
+ key->setOffset( offset );
+ return renderedText;
+ };
+
+ /**
+ * Check whether displaying displayLevel levels together is possible.
+ * For this count the childs and parents
+ * of the required position
+ */
+
+ int possibleLevels = 1; //we start with the default value of displayLevel, which means no entries together
+
+ while( key->parent() && (key->key() != "/") && !key->key().isEmpty() ) {//add parents
+ ++possibleLevels;
+ };
+
+ // key->key(keyName); //set the key to the start position
+
+ key->setOffset( offset );
+
+ while( key->firstChild( )) { //add childs
+ ++possibleLevels;
+ };
+
+ if (possibleLevels < displayLevel) { //too few levels available!
+ //display current level, we could also decide to display the available levels together
+ tree.append( new CDisplayRendering::KeyTreeItem( key->key(), modules, itemSettings ) );
+
+ const QString renderedText = render.renderKeyTree(tree);
+ key->setOffset( offset );
+ return renderedText;
+ };
+
+ if ((displayLevel > 2) && (displayLevel == possibleLevels)) { //fix not to diplay the whole module
+ --displayLevel;
+ }
+
+ // at this point we're sure that we can display the required levels toogether
+ // at the moment we're at the lowest level, so we only have to go up!
+ for (int currentLevel = 1; currentLevel < displayLevel; ++currentLevel) { //we start again with 1 == standard of displayLevel
+
+ if ( !key->parent() ) { //something went wrong although we checked before! Be safe and return entry's text
+ tree.append( new CDisplayRendering::KeyTreeItem( key->key(), modules, itemSettings ) );
+
+ const QString renderedText = render.renderKeyTree(tree);
+ key->setOffset( offset );
+ return renderedText;
+ };
+ };
+
+ // no we can display all sub levels together! We checked before that this is possible!
+ itemSettings.highlight = (key->key() == keyName);
+
+ tree.append( new CDisplayRendering::KeyTreeItem( key->key(), modules, itemSettings ) );
+
+ //const bool hasToplevelText = !key->strippedText().isEmpty();
+ key->firstChild(); //go to the first sibling on the same level
+
+ setupRenderTree(key.get(), &tree, keyName);
+
+ const QString renderedText = render.renderKeyTree(tree);
+
+ key->setOffset( offset ); //restore key
+
+ return renderedText;
+}
+
+void Rendering::CBookDisplay::setupRenderTree(CSwordTreeKey * swordTree, CTextRendering::KeyTree * renderTree, const QString& highlightKey) {
+
+ const QString key = swordTree->key();
+ const unsigned long offset = swordTree->getOffset();
+
+ CTextRendering::KeyTreeItem::Settings settings;
+ settings.highlight = (key == highlightKey);
+
+ CTextRendering::KeyTreeItem* item = new CTextRendering::KeyTreeItem(key, swordTree->module(0), settings );
+ renderTree->append( item );
+
+ if (swordTree->hasChildren()) { //print tree for the child items
+ swordTree->firstChild();
+ setupRenderTree(swordTree, item->childList(), highlightKey);
+ swordTree->setOffset( offset ); //go back where we came from
+ }
+
+ if (swordTree->nextSibling()) { //print tree for next entry on the same depth
+ setupRenderTree(swordTree, renderTree, highlightKey);
+ swordTree->setOffset( offset ); //return to the value we had at the beginning of this block!
+ }
+}
diff --git a/src/backend/rendering/cbookdisplay.h b/src/backend/rendering/cbookdisplay.h
new file mode 100644
index 0000000..6f0b031
--- /dev/null
+++ b/src/backend/rendering/cbookdisplay.h
@@ -0,0 +1,45 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef RENDERINGCBOOKDISPLAY_H
+#define RENDERINGCBOOKDISPLAY_H
+
+#include "centrydisplay.h"
+#include "ctextrendering.h"
+//TODO: It would be sufficient to forward declare CTextRendering and CTextRendering::KeyTree
+//but I don't know how :(
+
+class CSwordTreeKey;
+
+namespace Rendering {
+
+ /**
+ * A CEntryDisplay implementation which works on tree-based GenBook modules
+ * of Sword.
+ * @short CEntryDisplay implementation for GenBook modules,
+ * @author The BibleTime team
+ */
+
+class CBookDisplay : public CEntryDisplay {
+public: // Public methods
+ virtual ~CBookDisplay() {}
+
+ /**
+ * Returns the rendered text using the modules in the list and using the key parameter.
+ * The displayoptions and filter options are used, too.
+ */
+ virtual const QString text( const QList<CSwordModuleInfo*>& modules, const QString& key, const CSwordBackend::DisplayOptions displayOptions, const CSwordBackend::FilterOptions filterOptions);
+
+protected:
+ void setupRenderTree(CSwordTreeKey* swordTree, CTextRendering::KeyTree* renderTree, const QString& highlightKey);
+};
+
+}
+
+#endif
diff --git a/src/backend/rendering/cchapterdisplay.cpp b/src/backend/rendering/cchapterdisplay.cpp
new file mode 100644
index 0000000..921ed78
--- /dev/null
+++ b/src/backend/rendering/cchapterdisplay.cpp
@@ -0,0 +1,59 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//Backend
+#include "cchapterdisplay.h"
+#include "cdisplayrendering.h"
+#include "backend/keys/cswordversekey.h"
+#include "backend/drivers/cswordbiblemoduleinfo.h"
+
+const QString Rendering::CChapterDisplay::text( const QList<CSwordModuleInfo*>& modules, const QString& keyName, const CSwordBackend::DisplayOptions displayOptions, const CSwordBackend::FilterOptions filterOptions ) {
+ Q_ASSERT( modules.count() >= 1 );
+ Q_ASSERT( !keyName.isEmpty() );
+
+ CSwordModuleInfo* module = modules.first();
+
+ if (modules.count() == 1) module->module()->setSkipConsecutiveLinks( true ); //skip empty, linked verses
+
+ CTextRendering::KeyTreeItem::Settings settings;
+ settings.keyRenderingFace =
+ displayOptions.verseNumbers
+ ? CTextRendering::KeyTreeItem::Settings::SimpleKey
+ : CTextRendering::KeyTreeItem::Settings::NoKey;
+
+ QString startKey = keyName;
+ QString endKey = startKey;
+
+ //check whether there's an intro we have to include
+ Q_ASSERT((module->type() == CSwordModuleInfo::Bible));
+
+ if (module->type() == CSwordModuleInfo::Bible) {
+ ((sword::VerseKey*)(module->module()->getKey()))->Headings(1); //HACK: enable headings for VerseKeys
+
+ CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module);
+ Q_ASSERT(bible);
+
+ CSwordVerseKey k1(module);
+ k1.Headings(1);
+ k1.key(keyName);
+
+ if (k1.Chapter() == 1) k1.Chapter(0); //Chapter 1, start with 0:0, otherwise X:0
+
+ k1.Verse(0);
+
+ startKey = k1.key();
+
+ if (k1.Chapter() == 0) k1.Chapter(1);
+ k1.Verse(bible->verseCount(k1.book(), k1.Chapter()));
+ endKey = k1.key();
+ }
+
+ CDisplayRendering render(displayOptions, filterOptions);
+ return render.renderKeyRange( startKey, endKey, modules, keyName, settings );
+}
diff --git a/src/backend/rendering/cchapterdisplay.h b/src/backend/rendering/cchapterdisplay.h
new file mode 100644
index 0000000..cf00adf
--- /dev/null
+++ b/src/backend/rendering/cchapterdisplay.h
@@ -0,0 +1,37 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef RENDERINGCCHAPTERDISPLAY_H
+#define RENDERINGCCHAPTERDISPLAY_H
+
+#include "centrydisplay.h"
+
+namespace Rendering {
+
+/** Chapter rendering.
+* A CEntryDisplay implementation mde for Bibles to display whole chapters
+* at once.
+* @author The BibleTime team
+*/
+
+class CChapterDisplay : public CEntryDisplay {
+
+public: // Public methods
+ virtual ~CChapterDisplay() {}
+
+ /**
+ * Returns the rendered text using the modules in the list and using the key parameter.
+ * The displayoptions and filter options are used, too.
+ */
+ virtual const QString text( const QList<CSwordModuleInfo*>& modules, const QString& key, const CSwordBackend::DisplayOptions displayOptions, const CSwordBackend::FilterOptions filterOptions);
+};
+
+}
+
+#endif
diff --git a/src/backend/rendering/cdisplayrendering.cpp b/src/backend/rendering/cdisplayrendering.cpp
new file mode 100644
index 0000000..8c6c525
--- /dev/null
+++ b/src/backend/rendering/cdisplayrendering.cpp
@@ -0,0 +1,158 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cdisplayrendering.h"
+
+#include "backend/managers/cdisplaytemplatemgr.h"
+#include "backend/managers/creferencemanager.h"
+#include "backend/keys/cswordkey.h"
+#include "backend/keys/cswordversekey.h"
+
+#include "util/cpointers.h"
+
+//Qt
+#include <QString>
+#include <QRegExp>
+
+namespace Rendering {
+
+ CDisplayRendering::CDisplayRendering(CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions)
+: CHTMLExportRendering(CHTMLExportRendering::Settings(true), displayOptions, filterOptions) {}
+
+ const QString CDisplayRendering::entryLink( const KeyTreeItem& item, CSwordModuleInfo* module ) {
+ QString linkText;
+
+ const bool isBible = module && (module->type() == CSwordModuleInfo::Bible);
+ CSwordVerseKey vk(module); //only valid for bible modules, i.e. isBible == true
+ vk.Headings(true);
+
+ if (isBible) {
+ vk.key(item.key());
+ }
+
+ if (isBible && (vk.Verse() == 0)) {
+ return QString::null; //Warning: return already here
+ }
+
+ switch (item.settings().keyRenderingFace) {
+
+ case KeyTreeItem::Settings::NoKey: {
+ linkText = QString::null;
+ break; //no key is valid for all modules
+ }
+
+ case KeyTreeItem::Settings::CompleteShort: {
+ if (isBible) {
+ linkText = QString::fromUtf8(vk.getShortText());
+ break;
+ }
+
+ //fall through for non-Bible modules
+ }
+
+ case KeyTreeItem::Settings::CompleteLong: {
+ if (isBible) {
+ linkText = vk.key();
+ break;
+ }
+
+ //fall through for non-Bible modules
+ }
+
+ case KeyTreeItem::Settings::SimpleKey: {
+ if (isBible) {
+ linkText = QString::number(vk.Verse());
+ break;
+ }
+
+ //fall through for non-Bible modules
+ }
+
+ default: { //default behaviour to return the passed key
+ linkText = item.key();
+ break;
+ }
+ }
+
+ if (linkText.isEmpty()) {
+ return QString("<a name=\"").append(keyToHTMLAnchor(item.key())).append("\" />");
+ }
+ else {
+ return QString("<a name=\"").append(keyToHTMLAnchor(item.key())).append("\" ")
+ .append("href=\"")
+ .append(CReferenceManager::encodeHyperlink(
+ module->name(), item.key(), CReferenceManager::typeFromModule(module->type()))
+ )
+ .append("\">").append(linkText).append("</a>\n");
+ }
+
+ return QString::null;
+ }
+
+ const QString CDisplayRendering::keyToHTMLAnchor(const QString& key) {
+ QString ret = key;
+ ret = ret.trimmed().remove(QRegExp("[^A-Za-z0-9]+"));
+ ret = ret.remove(QRegExp("^\\d+|"));
+
+ return ret;
+ }
+
+ const QString CDisplayRendering::finishText( const QString& oldText, KeyTree& tree ) {
+ QList<CSwordModuleInfo*> modules = collectModules(&tree);
+ qDebug("CDisplayRendering::finishText");
+
+ //marking words is very slow, we have to find a better solution
+
+ /*
+ //mark all words by spans
+
+ QString text = oldText;
+
+ QRegExp re("(\\b)(?=\\w)"); //word begin marker
+ int pos = text.find(re, 0);
+
+ while (pos != -1) { //word begin found
+ //qWarning("found word at %i in %i", pos, text.length());
+ int endPos = pos + 1;
+ if (!CToolClass::inHTMLTag(pos+1, text)) { //the re has a positive look ahead which matches one char before the word start
+ //qWarning("matched %s", text.mid(pos+1, 4).latin1());
+
+ //find end of word and put a marker around it
+ endPos = text.find(QRegExp("\\b|[,.:]"), pos+1);
+ if ((endPos != -1) && !CToolClass::inHTMLTag(endPos, text) && (endPos - pos >= 3)) { //reuire wordslonger than 3 chars
+ text.insert(endPos, "</span>");
+ text.insert(pos, "<span class=\"word\">");
+
+ endPos += 26;
+ }
+ }
+ pos = text.find(re, endPos);
+ }
+ */
+ const CLanguageMgr::Language* const lang =
+ (modules.count() >= 1)
+ ? modules.first()->language()
+ : CPointers::languageMgr()->defaultLanguage();
+
+ CDisplayTemplateMgr* tMgr = CPointers::displayTemplateManager();
+
+ //Q_ASSERT(modules.count() >= 1);
+
+ CDisplayTemplateMgr::Settings settings;
+ settings.modules = modules;
+ settings.langAbbrev = ((modules.count() == 1) && lang->isValid()) ? lang->abbrev() : QString::null;
+
+ if (modules.count() == 1)
+ settings.pageDirection = (modules.first()->textDirection() == CSwordModuleInfo::LeftToRight) ? "ltr" : "rtl";
+ else
+ settings.pageDirection = QString::null;
+
+ return tMgr->fillTemplate(CBTConfig::get(CBTConfig::displayStyle), oldText, settings);
+ }
+}
diff --git a/src/backend/rendering/cdisplayrendering.h b/src/backend/rendering/cdisplayrendering.h
new file mode 100644
index 0000000..9c4451b
--- /dev/null
+++ b/src/backend/rendering/cdisplayrendering.h
@@ -0,0 +1,38 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef RENDERINGCDISPLAYRENDERING_H
+#define RENDERINGCDISPLAYRENDERING_H
+
+#include "chtmlexportrendering.h"
+
+namespace Rendering {
+
+/** HTML rendering for the text display widgets.
+ * @short Rendering for the html display widget.
+ * @author The BibleTime team
+ */
+
+class CDisplayRendering : public CHTMLExportRendering {
+public:
+ static const QString keyToHTMLAnchor(const QString& key);
+
+ CDisplayRendering(
+ CSwordBackend::DisplayOptions displayOptions = CBTConfig::getDisplayOptionDefaults(),
+ CSwordBackend::FilterOptions filterOptions = CBTConfig::getFilterOptionDefaults()
+ );
+
+protected:
+ virtual const QString entryLink( const KeyTreeItem& item, CSwordModuleInfo* const module );
+ virtual const QString finishText( const QString&, KeyTree& tree );
+};
+
+}
+
+#endif
diff --git a/src/backend/rendering/centrydisplay.cpp b/src/backend/rendering/centrydisplay.cpp
new file mode 100644
index 0000000..7a4626c
--- /dev/null
+++ b/src/backend/rendering/centrydisplay.cpp
@@ -0,0 +1,63 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//BibleTime includes
+#include "centrydisplay.h"
+
+#include "backend/keys/cswordkey.h"
+#include "backend/keys/cswordversekey.h"
+#include "backend/drivers/cswordbookmoduleinfo.h"
+#include "backend/managers/creferencemanager.h"
+#include "backend/managers/cdisplaytemplatemgr.h"
+#include "cdisplayrendering.h"
+
+#include "backend/config/cbtconfig.h"
+#include <boost/scoped_ptr.hpp>
+
+//Qt includes
+#include <QApplication>
+#include <QRegExp>
+
+using namespace Rendering;
+
+/** Returns the rendered text using the modules in the list and using the key parameter.
+ * The displayoptions and filter options are used, too.
+ */
+const QString CEntryDisplay::text( const QList<CSwordModuleInfo*>& modules, const QString& keyName, const CSwordBackend::DisplayOptions displayOptions, const CSwordBackend::FilterOptions filterOptions ) {
+ CDisplayRendering render(displayOptions, filterOptions);
+
+ //no highlighted key and no extra key link in the text
+ CTextRendering::KeyTreeItem::Settings normal_settings(false, CTextRendering::KeyTreeItem::Settings::CompleteShort);
+ CSwordModuleInfo* module = modules.first();
+ QString result;
+
+ //in Bibles and Commentaries we need to check if 0:0 and X:0 contain something
+ if (module->type() == CSwordModuleInfo::Bible || module->type() == CSwordModuleInfo::Commentary) {
+ ((sword::VerseKey*)(module->module()->getKey()))->Headings(1); //HACK: enable headings for VerseKeys
+
+ CSwordVerseKey k1(module);
+ k1.Headings(1);
+ k1.key(keyName);
+
+ // don't print the key
+ CTextRendering::KeyTreeItem::Settings preverse_settings(false, CTextRendering::KeyTreeItem::Settings::NoKey);
+
+ if (k1.Verse() == 1){ //X:1, prepend X:0
+ if (k1.Chapter() == 1){ //1:1, also prepend 0:0 before that
+ k1.Chapter(0);
+ k1.Verse(0);
+ if ( k1.rawText().length() > 0 ) result.append( render.renderSingleKey(k1.key(), modules, preverse_settings ) );
+ k1.Chapter(1);
+ }
+ k1.Verse(0);
+ if ( k1.rawText().length() > 0 ) result.append( render.renderSingleKey(k1.key(), modules, preverse_settings ) );
+ }
+ }
+ return result.append( render.renderSingleKey(keyName, modules, normal_settings) );
+}
diff --git a/src/backend/rendering/centrydisplay.h b/src/backend/rendering/centrydisplay.h
new file mode 100644
index 0000000..96f0dba
--- /dev/null
+++ b/src/backend/rendering/centrydisplay.h
@@ -0,0 +1,51 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CENTRYDISPLAY_H
+#define CENTRYDISPLAY_H
+
+//BibleTime
+//#include "ctextrendering.h"
+class CSwordModuleInfo;
+#include "backend/managers/cswordbackend.h"
+
+#include "util/cpointers.h"
+
+//Sword
+#include <swdisp.h>
+
+//Qt
+#include <QString>
+
+class CSwordModuleInfo;
+
+namespace Rendering {
+
+/**
+* The reimplementation of SWDisplay to fit our needs.
+* @short Display implementation
+* @author The BibleTime team
+*/
+
+class CEntryDisplay : public sword::SWDisplay, public CPointers {
+
+public:
+ virtual ~CEntryDisplay() {}
+
+ /**
+ * Returns the rendered text using the modules in the list and using the key parameter.
+ * The displayoptions and filter options are used, too.
+ */
+ virtual const QString text( const QList<CSwordModuleInfo*>& modules, const QString& key, const CSwordBackend::DisplayOptions displayOptions, const CSwordBackend::FilterOptions filterOptions);
+};
+
+
+}
+
+#endif
diff --git a/src/backend/rendering/chtmlexportrendering.cpp b/src/backend/rendering/chtmlexportrendering.cpp
new file mode 100644
index 0000000..38a83d3
--- /dev/null
+++ b/src/backend/rendering/chtmlexportrendering.cpp
@@ -0,0 +1,234 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "chtmlexportrendering.h"
+
+#include "backend/managers/cdisplaytemplatemgr.h"
+#include "backend/managers/clanguagemgr.h"
+#include "backend/keys/cswordkey.h"
+#include "backend/keys/cswordversekey.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+
+#include "util/cpointers.h"
+#include <boost/scoped_ptr.hpp>
+
+#include <iostream>
+
+namespace {
+
+/*
+ * Helper function to dump a verse with all its enty attributes
+ */
+
+void dumpEntryAttributes(sword::SWModule *module) {
+ std::cout << "Attributes for key: " << module->getKeyText() << std::endl;
+ sword::AttributeTypeList::iterator i1;
+ sword::AttributeList::iterator i2;
+ sword::AttributeValue::iterator i3;
+ for (i1 = module->getEntryAttributes().begin(); i1 != module->getEntryAttributes().end(); i1++) {
+ std::cout << "[ " << i1->first << " ]\n";
+ for (i2 = i1->second.begin(); i2 != i1->second.end(); i2++) {
+ std::cout << "\t[ " << i2->first << " ]\n";
+ for (i3 = i2->second.begin(); i3 != i2->second.end(); i3++) {
+ std::cout << "\t\t" << i3->first << " = " << i3->second << "\n";
+ }
+ }
+ }
+ std::cout << std::endl;
+}
+
+}
+
+namespace Rendering {
+
+ CHTMLExportRendering::CHTMLExportRendering(const CHTMLExportRendering::Settings& settings, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions)
+: m_displayOptions(displayOptions),
+ m_filterOptions(filterOptions),
+ m_settings(settings) {}
+
+ CHTMLExportRendering::~CHTMLExportRendering() {}
+
+ const QString CHTMLExportRendering::renderEntry( const KeyTreeItem& i, CSwordKey* k) {
+
+ if (i.hasAlternativeContent()) {
+ QString ret = QString(i.settings().highlight ? "<div class=\"currententry\">" : "<div class=\"entry\">");
+ ret.append(i.getAlternativeContent());
+
+ // Q_ASSERT(i.hasChildItems());
+
+ if (!i.childList()->isEmpty()) {
+ KeyTree * const tree = i.childList();
+
+ const QList<CSwordModuleInfo*> modules = collectModules(tree);
+
+ if (modules.count() == 1) { //insert the direction into the sorrounding div
+ ret.insert( 5, QString("dir=\"%1\" ").arg((modules.first()->textDirection() == CSwordModuleInfo::LeftToRight) ? "ltr" : "rtl" ));
+ }
+
+ foreach ( KeyTreeItem* c, (*tree) ) {
+ ret.append( renderEntry( *c ) );
+ }
+ }
+
+ ret.append("</div>");
+ return ret; //WARNING: Return already here!
+ }
+
+
+ const QList<CSwordModuleInfo*>& modules( i.modules() );
+ if (modules.count() == 0) {
+ return QString(""); //no module present for rendering
+ }
+
+ boost::scoped_ptr<CSwordKey> scoped_key( !k ? CSwordKey::createInstance(modules.first()) : 0 );
+ CSwordKey* key = k ? k : scoped_key.get();
+ Q_ASSERT(key);
+
+ CSwordVerseKey* myVK = dynamic_cast<CSwordVerseKey*>(key);
+
+ if ( myVK ) myVK->Headings(1);
+
+ QString renderedText( (modules.count() > 1) ? "\n\t\t<tr>\n" : "\n" );
+ // Only insert the table stuff if we are displaying parallel.
+
+ //declarations out of the loop for optimization
+ QString entry;
+ QString keyText;
+ bool isRTL;
+ QString preverseHeading;
+ QString langAttr;
+ QString key_renderedText;
+
+ QList<CSwordModuleInfo*>::const_iterator end_modItr = modules.end();
+
+ for (QList<CSwordModuleInfo*>::const_iterator mod_Itr(modules.begin()); mod_Itr != end_modItr; ++mod_Itr) {
+ key->module(*mod_Itr);
+ key->key( i.key() );
+
+ keyText = key->key();
+ isRTL = ((*mod_Itr)->textDirection() == CSwordModuleInfo::RightToLeft);
+ entry = QString::null;
+
+ if ((*mod_Itr)->language()->isValid()) {
+ langAttr = QString("xml:lang=\"")
+ .append((*mod_Itr)->language()->abbrev())
+ .append("\" lang=\"")
+ .append((*mod_Itr)->language()->abbrev())
+ .append("\"");
+ }
+ else {
+ langAttr = QString("xml:lang=\"")
+ .append((*mod_Itr)->module()->Lang())
+ .append("\" lang=\"")
+ .append((*mod_Itr)->module()->Lang())
+ .append("\"");
+ }
+
+ key_renderedText = key->renderedText();
+
+ if (m_filterOptions.headings) {
+ (*mod_Itr)->module()->RenderText();
+ sword::AttributeValue::const_iterator it =
+ (*mod_Itr)->module()->getEntryAttributes()["Heading"]["Preverse"].begin();
+ const sword::AttributeValue::const_iterator end =
+ (*mod_Itr)->module()->getEntryAttributes()["Heading"]["Preverse"].end();
+
+ for (; it != end; ++it) {
+ preverseHeading = QString::fromUtf8(it->second.c_str());
+ //TODO: Take care of the heading type!
+ if (!preverseHeading.isEmpty()) {
+ entry.append("<div ")
+ .append(langAttr)
+ .append(" class=\"sectiontitle\">")
+ .append(preverseHeading)
+ .append("</div>");
+ }
+ }
+ }
+
+ entry.append(m_displayOptions.lineBreaks ? "<div " : "<div style=\"display: inline;\" ");
+
+ if (modules.count() == 1) { //insert only the class if we're not in a td
+ entry.append( i.settings().highlight ? "class=\"currententry\" " : "class=\"entry\" " );
+ }
+
+ entry.append(langAttr).append(isRTL ? " dir=\"rtl\"" : " dir=\"ltr\"").append(">");
+
+ //keys should normally be left-to-right, but this doesn't apply in all cases
+ entry.append("<span class=\"entryname\" dir=\"ltr\">").append(entryLink(i, *mod_Itr)).append("</span>");
+
+ if (m_settings.addText) {
+ //entry.append( QString::fromLatin1("<span %1>%2</span>").arg(langAttr).arg(key_renderedText) );
+ entry.append( key_renderedText );
+ }
+
+ if (!i.childList()->isEmpty()) {
+ KeyTree* tree(i.childList());
+
+ foreach (KeyTreeItem* c, (*tree)) {
+ entry.append( renderEntry(*c) );
+ }
+ }
+
+ entry.append("</div>");
+
+ if (modules.count() == 1) {
+ renderedText.append( "\t\t" ).append( entry ).append("\n");
+ }
+ else {
+ renderedText.append("\t\t<td class=\"")
+ .append(i.settings().highlight ? "currententry" : "entry")
+ .append("\" ")
+ .append(langAttr)
+ .append(" dir=\"")
+ .append(isRTL ? "rtl" : "ltr")
+ .append("\">\n")
+ .append( "\t\t\t" ).append( entry ).append("\n")
+ .append("\t\t</td>\n");
+ }
+ }
+
+ if (modules.count() > 1) {
+ renderedText.append("\t\t</tr>\n");
+ }
+
+ // qDebug("CHTMLExportRendering: %s", renderedText.latin1());
+ return renderedText;
+}
+
+void CHTMLExportRendering::initRendering() {
+ //CPointers::backend()->setDisplayOptions( m_displayOptions );
+ CPointers::backend()->setFilterOptions( m_filterOptions );
+}
+
+const QString CHTMLExportRendering::finishText( const QString& text, KeyTree& tree ) {
+ const QList<CSwordModuleInfo*> modules = collectModules(&tree);
+
+ const CLanguageMgr::Language* const lang = modules.first()->language();
+
+ CDisplayTemplateMgr* tMgr = CPointers::displayTemplateManager();
+ CDisplayTemplateMgr::Settings settings;
+ settings.modules = modules;
+ settings.langAbbrev = ((modules.count() == 1) && lang->isValid()) ? lang->abbrev() : "unknown";
+ if (modules.count() == 1)
+ settings.pageDirection = ((modules.first()->textDirection() == CSwordModuleInfo::LeftToRight) ? "ltr" : "rtl");
+ else
+ settings.pageDirection = QString::null;
+
+ return tMgr->fillTemplate(QObject::tr("Export"), text, settings);
+}
+
+/*!
+ \fn CHTMLExportRendering::entryLink( KeyTreeItem& item )
+ */
+const QString CHTMLExportRendering::entryLink( const KeyTreeItem& item, CSwordModuleInfo* ) {
+ return item.key();
+}
+
+}//end of namespace "Rendering"
diff --git a/src/backend/rendering/chtmlexportrendering.h b/src/backend/rendering/chtmlexportrendering.h
new file mode 100644
index 0000000..6a8153e
--- /dev/null
+++ b/src/backend/rendering/chtmlexportrendering.h
@@ -0,0 +1,58 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef RENDERINGCHTMLEXPORTRENDERING_H
+#define RENDERINGCHTMLEXPORTRENDERING_H
+
+#include "backend/managers/cswordbackend.h"
+#include "ctextrendering.h"
+
+#include "backend/config/cbtconfig.h"
+
+namespace Rendering {
+
+ /**
+ * This CTextRenerding implementation
+ * creates HTML specially made for export as HTML files.
+ * @short HTML rendering for export.
+ * @author The BibleTime team
+ */
+
+class CHTMLExportRendering : public CTextRendering {
+
+public:
+ struct Settings {
+ Settings(const bool text = true) {
+ addText = text;
+ };
+
+ bool addText;
+ };
+
+ CHTMLExportRendering(
+ const Settings& settings,
+ CSwordBackend::DisplayOptions displayOptions = CBTConfig::getDisplayOptionDefaults(),
+ CSwordBackend::FilterOptions filterOptions = CBTConfig::getFilterOptionDefaults()
+ );
+ virtual ~CHTMLExportRendering();
+
+protected:
+ virtual const QString renderEntry( const KeyTreeItem&, CSwordKey* = 0 );
+ virtual const QString finishText( const QString&, KeyTree& tree );
+ virtual const QString entryLink( const KeyTreeItem& item, CSwordModuleInfo* module );
+ virtual void initRendering();
+
+ CSwordBackend::DisplayOptions m_displayOptions;
+ CSwordBackend::FilterOptions m_filterOptions;
+ Settings m_settings;
+};
+
+}
+
+#endif
diff --git a/src/backend/rendering/cplaintextexportrendering.cpp b/src/backend/rendering/cplaintextexportrendering.cpp
new file mode 100644
index 0000000..d99cff3
--- /dev/null
+++ b/src/backend/rendering/cplaintextexportrendering.cpp
@@ -0,0 +1,53 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//Backend includes
+#include "cplaintextexportrendering.h"
+#include "backend/keys/cswordkey.h"
+
+//Util
+#include <boost/scoped_ptr.hpp>
+
+namespace Rendering {
+
+CPlainTextExportRendering::CPlainTextExportRendering(const CPlainTextExportRendering::Settings& settings, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions)
+ : CHTMLExportRendering(settings, displayOptions, filterOptions) {}
+
+CPlainTextExportRendering::~CPlainTextExportRendering() {}
+
+const QString CPlainTextExportRendering::renderEntry( const KeyTreeItem& i, CSwordKey* ) {
+ if (!m_settings.addText) {
+ return QString(i.key()).append("\n");
+ }
+
+ QList<CSwordModuleInfo*> modules = i.modules();
+ boost::scoped_ptr<CSwordKey> key( CSwordKey::createInstance(modules.first()) );
+ QString renderedText = QString(i.key()).append(":\n");
+
+ QString entry;
+ // for (CSwordModuleInfo* m = modules.first(); m; m = modules.next()) {
+ QList<CSwordModuleInfo*>::iterator end_it = modules.end();
+
+ for (QList<CSwordModuleInfo*>::iterator it(modules.begin()); it != end_it; ++it) {
+ key->module(*it);
+ key->key( i.key() );
+
+ //ToDo: Check this code
+ entry.append(key->strippedText()).append("\n");
+ renderedText.append( entry );
+ }
+
+ return renderedText;
+}
+
+const QString CPlainTextExportRendering::finishText( const QString& oldText, KeyTree& ) {
+ return oldText;
+}
+
+}
diff --git a/src/backend/rendering/cplaintextexportrendering.h b/src/backend/rendering/cplaintextexportrendering.h
new file mode 100644
index 0000000..9ec388b
--- /dev/null
+++ b/src/backend/rendering/cplaintextexportrendering.h
@@ -0,0 +1,40 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef RENDERINGCPLAINTEXTEXPORTRENDERING_H
+#define RENDERINGCPLAINTEXTEXPORTRENDERING_H
+
+#include "chtmlexportrendering.h"
+
+namespace Rendering {
+
+ /**
+ * This implementation can be used to export content as plain text.
+ * @short Text rendering as plain text.
+ * @author The BibleTime team
+ */
+
+class CPlainTextExportRendering : public CHTMLExportRendering {
+
+public:
+ CPlainTextExportRendering(
+ const Settings& settings,
+ CSwordBackend::DisplayOptions displayOptions = CBTConfig::getDisplayOptionDefaults(),
+ CSwordBackend::FilterOptions filterOptions = CBTConfig::getFilterOptionDefaults()
+ );
+ virtual ~CPlainTextExportRendering();
+
+protected:
+ virtual const QString renderEntry( const KeyTreeItem&, CSwordKey* = 0 );
+ virtual const QString finishText( const QString&, KeyTree& tree );
+};
+
+}
+
+#endif
diff --git a/src/backend/rendering/ctextrendering.cpp b/src/backend/rendering/ctextrendering.cpp
new file mode 100644
index 0000000..c7ac0bd
--- /dev/null
+++ b/src/backend/rendering/ctextrendering.cpp
@@ -0,0 +1,263 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "ctextrendering.h"
+
+//BibleTime
+#include "backend/keys/cswordkey.h"
+#include "backend/keys/cswordversekey.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/managers/cdisplaytemplatemgr.h"
+#include "backend/managers/creferencemanager.h"
+
+#include <boost/scoped_ptr.hpp>
+#include "util/ctoolclass.h"
+
+//Sword
+#include <swkey.h>
+
+//Qt
+#include <QRegExp>
+
+
+using namespace Rendering;
+
+CTextRendering::KeyTreeItem::KeyTreeItem(const QString& key, CSwordModuleInfo const * mod, const Settings settings )
+ : m_settings( settings ),
+ m_moduleList(),
+ m_key( key ),
+ m_childList(),
+ m_stopKey( QString::null ),
+ m_alternativeContent( QString::null )
+{
+ m_moduleList.append( const_cast<CSwordModuleInfo*>(mod) ); //BAD CODE
+}
+
+CTextRendering::KeyTreeItem::KeyTreeItem(const QString& content, const Settings settings )
+ : m_settings( settings ),
+ m_moduleList(),
+ m_key( QString::null ),
+ m_childList(),
+ m_stopKey( QString::null ),
+ m_alternativeContent( content )
+{
+}
+
+CTextRendering::KeyTreeItem::KeyTreeItem(const QString& key, const QList<CSwordModuleInfo*>& mods, const Settings settings )
+ : m_settings( settings ),
+ m_moduleList( mods ),
+ m_key( key ),
+ m_childList(),
+ m_stopKey( QString::null ),
+ m_alternativeContent( QString::null )
+{
+}
+
+CTextRendering::KeyTreeItem::KeyTreeItem()
+ : m_settings(),
+ m_moduleList(),
+ m_key(QString::null),
+ m_childList(),
+ m_stopKey(QString::null),
+ m_alternativeContent(QString::null)
+{
+}
+
+CTextRendering::KeyTreeItem::KeyTreeItem(const KeyTreeItem& i)
+ : m_settings( i.m_settings ),
+ m_moduleList( i.m_moduleList ),
+ m_key( i.m_key ),
+ m_childList(),
+ m_stopKey( i.m_stopKey ),
+ m_alternativeContent( i.m_alternativeContent )
+{
+ foreach(KeyTreeItem* item, (*i.childList())){
+ m_childList.append(new KeyTreeItem((*item))); //deep copy
+ }
+
+}
+
+CTextRendering::KeyTreeItem::~KeyTreeItem() {
+ qDeleteAll(m_childList);
+}
+
+CTextRendering::KeyTreeItem::KeyTreeItem(const QString& startKey, const QString& stopKey, CSwordModuleInfo* module, const Settings settings)
+: m_settings( settings ),
+m_moduleList(),
+m_key( startKey ),
+m_childList(),
+m_stopKey( stopKey ),
+m_alternativeContent( QString::null ) {
+ Q_ASSERT(module);
+ m_moduleList.append(module);
+
+ //use the start and stop key to ceate our child items
+
+ if (module->type() == CSwordModuleInfo::Bible) {
+ CSwordVerseKey start(module);
+ start.key(startKey);
+
+ CSwordVerseKey stop(module);
+ stop.key(stopKey);
+
+ if (!m_key.isEmpty() && !m_stopKey.isEmpty()) { //we have a range of keys
+ bool ok = true;
+
+ while (ok && ((start < stop) || (start == stop)) ) { //range
+ m_childList.append(
+ new KeyTreeItem(start.key(), module, KeyTreeItem::Settings(false, settings.keyRenderingFace))
+ );
+
+
+ ok = start.next(CSwordVerseKey::UseVerse);
+ }
+ }
+ else if (m_key.isEmpty()) {
+ m_childList.append( new KeyTreeItem(startKey, module, KeyTreeItem::Settings(false, settings.keyRenderingFace)) );
+ }
+ }
+ else if ((module->type() == CSwordModuleInfo::Lexicon) || (module->type() == CSwordModuleInfo::Commentary) ) {
+ m_childList.append( new KeyTreeItem(startKey, module, KeyTreeItem::Settings(false, KeyTreeItem::Settings::NoKey)) );
+ }
+ else if (module->type() == CSwordModuleInfo::GenericBook) {
+ m_childList.append( new KeyTreeItem(startKey, module, KeyTreeItem::Settings(false, KeyTreeItem::Settings::NoKey)) );
+ }
+
+ //make it into "<simple|range> (modulename)"
+
+ if (startKey == stopKey) {
+ m_alternativeContent = startKey;
+ }
+ else {
+ sword::VerseKey vk(startKey.toUtf8().constData(), stopKey.toUtf8().constData());
+
+ if (vk.LowerBound().Book() != vk.UpperBound().Book()) {
+ m_alternativeContent = QString::fromUtf8(vk.getRangeText());
+ }
+ else if (vk.LowerBound().Chapter() != vk.UpperBound().Chapter()) {
+ m_alternativeContent = QString("%1 - %2:%3")
+ .arg(QString::fromUtf8(vk.LowerBound().getText()))
+ .arg(vk.UpperBound().Chapter())
+ .arg(vk.UpperBound().Verse());
+ }
+ else { //only verses differ (same book, same chapter)
+ m_alternativeContent = QString("%1 - %2")
+ .arg(QString::fromUtf8(vk.LowerBound().getText()))
+ .arg(vk.UpperBound().Verse());
+ }
+ }
+
+ m_alternativeContent.append(" (").append(module->name()).append(")");
+ m_alternativeContent.prepend("<div class=\"rangeheading\" dir=\"ltr\">").append("</div>"); //insert the right tags
+}
+
+const QString& CTextRendering::KeyTreeItem::getAlternativeContent() const {
+ return m_alternativeContent;
+}
+
+const QList<CSwordModuleInfo*> CTextRendering::collectModules(KeyTree* const tree) const {
+ //collect all modules which are available and used by child items
+ QList<CSwordModuleInfo*> modules;
+
+ foreach (KeyTreeItem* c, (*tree)) {
+ Q_ASSERT(c);
+ foreach (CSwordModuleInfo* mod, c->modules()) {
+ if (!modules.contains(mod)) {
+ modules.append(mod);
+ }
+ }
+ }
+ return modules;
+}
+
+const QString CTextRendering::renderKeyTree( KeyTree& tree ) {
+ initRendering();
+
+ QList<CSwordModuleInfo*> modules = collectModules(&tree);
+ QString t;
+
+ //optimization for entries with the same key
+ boost::scoped_ptr<CSwordKey> key(
+ (modules.count() == 1) ? CSwordKey::createInstance(modules.first()) : 0
+ );
+
+ foreach (KeyTreeItem* c, tree) {
+ if (modules.count() == 1) { //this optimizes the rendering, only one key created for all items
+ key->key( c->key() );
+ t.append( renderEntry( *c, key.get()) );
+ }
+ else {
+ t.append( renderEntry( *c ) );
+ }
+ }
+
+ return finishText(t, tree);
+}
+
+const QString CTextRendering::renderKeyRange( const QString& start, const QString& stop, const QList<CSwordModuleInfo*>& modules, const QString& highlightKey, const KeyTreeItem::Settings& keySettings ) {
+
+ CSwordModuleInfo* module = modules.first();
+ //qWarning( "renderKeyRange start %s stop %s \n", start.latin1(), stop.latin1() );
+
+ boost::scoped_ptr<CSwordKey> lowerBound( CSwordKey::createInstance(module) );
+ lowerBound->key(start);
+
+ boost::scoped_ptr<CSwordKey> upperBound( CSwordKey::createInstance(module) );
+ upperBound->key(stop);
+
+ sword::SWKey* sw_start = dynamic_cast<sword::SWKey*>(lowerBound.get());
+ sword::SWKey* sw_stop = dynamic_cast<sword::SWKey*>(upperBound.get());
+
+ Q_ASSERT((*sw_start == *sw_stop) || (*sw_start < *sw_stop));
+
+ if (*sw_start == *sw_stop) { //same key, render single key
+ return renderSingleKey(lowerBound->key(), modules);
+ }
+ else if (*sw_start < *sw_stop) { // Render range
+ KeyTree tree;
+ KeyTreeItem::Settings settings = keySettings;
+
+ CSwordVerseKey* vk_start = dynamic_cast<CSwordVerseKey*>(lowerBound.get());
+ Q_ASSERT(vk_start);
+
+ CSwordVerseKey* vk_stop = dynamic_cast<CSwordVerseKey*>(upperBound.get());
+ Q_ASSERT(vk_stop);
+
+ bool ok = true;
+ while (ok && ((*vk_start < *vk_stop) || (*vk_start == *vk_stop))) {
+ //make sure the key given by highlightKey gets marked as current key
+ settings.highlight = (!highlightKey.isEmpty() ? (vk_start->key() == highlightKey) : false);
+
+ /*TODO: We need to take care of linked verses if we render one or (esp) more modules
+ If the verses 2,3,4,5 are linked to 1, it should be displayed as one entry with the caption 1-5 */
+
+ if (vk_start->Chapter() == 0){ //range was 0:0-1:x, render 0:0 first and jump to 1:0
+ vk_start->Verse(0);
+ tree.append( new KeyTreeItem(vk_start->key(), modules, settings) );
+ vk_start->Chapter(1);
+ vk_start->Verse(0);
+ }
+ tree.append( new KeyTreeItem(vk_start->key(), modules, settings) );
+ ok = vk_start->next(CSwordVerseKey::UseVerse);
+ }
+
+ return renderKeyTree(tree);
+ }
+
+ return QString::null;
+}
+
+const QString CTextRendering::renderSingleKey( const QString& key, const QList<CSwordModuleInfo*>& moduleList, const KeyTreeItem::Settings& settings ) {
+ KeyTree tree;
+ tree.append( new KeyTreeItem(key, moduleList, settings) );
+
+ return renderKeyTree(tree);
+}
+
+
diff --git a/src/backend/rendering/ctextrendering.h b/src/backend/rendering/ctextrendering.h
new file mode 100644
index 0000000..403962b
--- /dev/null
+++ b/src/backend/rendering/ctextrendering.h
@@ -0,0 +1,128 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CTEXTRENDERING_H
+#define CTEXTRENDERING_H
+
+//BT includes
+class CSwordModuleInfo;
+//#include "util/autoptrvector.h"
+
+//QT includes
+#include <QString>
+#include <QList>
+
+class CSwordKey;
+
+/**
+ * CTextRendering is BibleTime's place where the actual rendering takes place.
+ * It provides several methods to convert an abstract tree of items
+ * into a string of html.
+ *
+ * See the implementations @ref CHTMLExportRendering and especially @ref CDisplayRendering.
+ * @short Text rendering based on trees
+ * @author The BibleTime team
+*/
+
+namespace Rendering {
+
+class CTextRendering {
+
+public:
+
+ class KeyTreeItem;
+ typedef QList<KeyTreeItem*> KeyTree;
+
+ class KeyTreeItem {
+ public:
+
+ struct Settings {
+ enum KeyRenderingFace {
+ NoKey, //< means no key shown at all
+ SimpleKey, //< means only versenumber or only lexicon entry name
+ CompleteShort, //< means key like "Gen 1:1"
+ CompleteLong //< means "Genesis 1:1"
+ };
+
+ Settings(const bool highlight = false, KeyRenderingFace keyRendering = SimpleKey) : highlight(highlight), keyRenderingFace(keyRendering) {}
+
+ bool highlight;
+ KeyRenderingFace keyRenderingFace;
+ };
+
+ KeyTreeItem(const QString& key, CSwordModuleInfo const * module, const Settings settings);
+ KeyTreeItem(const QString& key, const QList<CSwordModuleInfo*>& modules, const Settings settings);
+ KeyTreeItem(const QString& startKey, const QString& stopKey, CSwordModuleInfo* module, const Settings settings);
+ KeyTreeItem(const QString& content, const Settings settings);
+ KeyTreeItem(const KeyTreeItem& i);
+
+ virtual ~KeyTreeItem();
+
+ const QString& getAlternativeContent() const;
+ inline void setAlternativeContent(const QString& newContent) {
+ m_alternativeContent = newContent;
+ };
+
+ inline bool hasAlternativeContent() const {
+ return !m_alternativeContent.isNull();
+ };
+
+ inline const QList<CSwordModuleInfo*>& modules() const {
+ return m_moduleList;
+ };
+
+ inline const QString& key() const {
+ return m_key;
+ };
+
+ inline const Settings& settings() const {
+ return m_settings;
+ };
+
+ inline KeyTree* childList() const;
+// inline const bool hasChildItems() const;
+
+ protected:
+ KeyTreeItem();
+
+ Settings m_settings;
+ QList<CSwordModuleInfo*> m_moduleList;
+ QString m_key;
+ mutable KeyTree m_childList;
+
+ QString m_stopKey;
+ QString m_alternativeContent;
+ };
+
+ virtual ~CTextRendering() {}
+
+ const QString renderKeyTree( KeyTree& );
+
+ const QString renderKeyRange( const QString& start, const QString& stop, const QList<CSwordModuleInfo*>& modules, const QString& hightlightKey = QString::null, const KeyTreeItem::Settings& settings = KeyTreeItem::Settings() );
+
+ const QString renderSingleKey( const QString& key, const QList<CSwordModuleInfo*>&, const KeyTreeItem::Settings& settings = KeyTreeItem::Settings() );
+
+protected:
+ const QList<CSwordModuleInfo*> collectModules(KeyTree* const tree) const;
+ virtual const QString renderEntry( const KeyTreeItem&, CSwordKey* = 0 ) = 0;
+ virtual const QString finishText( const QString&, KeyTree& tree ) = 0;
+ virtual void initRendering() = 0;
+};
+
+inline CTextRendering::KeyTree* CTextRendering::KeyTreeItem::childList() const{
+ return &m_childList;
+}
+//
+//inline const bool CTextRendering::KeyTreeItem::hasChildItems() const {
+// return !m_childList.isEmpty();
+//}
+
+}
+
+#endif
diff --git a/src/bibletime.cpp b/src/bibletime.cpp
new file mode 100644
index 0000000..c4510f6
--- /dev/null
+++ b/src/bibletime.cpp
@@ -0,0 +1,314 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+#include "bibletime.h"
+
+#include "frontend/cmdiarea.h"
+#include "frontend/mainindex/cmainindex.h"
+#include "frontend/mainindex/bookshelf/cbookshelfindex.h"
+#include "frontend/displaywindow/cdisplaywindow.h"
+#include "frontend/displaywindow/cdisplaywindowfactory.h"
+#include "frontend/displaywindow/creadwindow.h"
+#include "frontend/displaywindow/cwritewindow.h"
+#include "frontend/keychooser/ckeychooser.h"
+#include "backend/config/cbtconfig.h"
+
+#include "util/ctoolclass.h"
+#include "util/cpointers.h"
+#include "util/directoryutil.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/drivers/cswordbiblemoduleinfo.h"
+#include "backend/drivers/cswordcommentarymoduleinfo.h"
+#include "backend/drivers/cswordlexiconmoduleinfo.h"
+#include "backend/drivers/cswordbookmoduleinfo.h"
+#include "backend/keys/cswordversekey.h"
+#include "backend/keys/cswordldkey.h"
+
+//Qt includes
+#include <QSplitter>
+#include <QDebug>
+#include <QAction>
+#include <QApplication>
+#include <QMdiSubWindow>
+#include <QCloseEvent>
+#include <QSplashScreen>
+
+#include <cstdlib>
+#include <ctime>
+
+using namespace Profile;
+
+BibleTime::BibleTime() :
+ QMainWindow(0),
+ m_dock0(0),
+ m_dock1(0),
+ m_dock2(0),
+ m_initialized(false),
+ m_moduleList(0),
+ m_currentProfile(0),
+ m_mdi(0),
+ m_profileMgr()
+{
+ QPixmap pm;
+ if ( !pm.load( util::filesystem::DirectoryUtil::getPicsDir().canonicalPath().append( "/startuplogo.png")) )
+ {
+ qWarning("Can't load startuplogo! Check your installation.");
+ }
+ QSplashScreen splash(pm);
+ QString splashHtml("<div style='background:transparent;color:white;font-weight:bold'>%1</div>");
+ if (CBTConfig::get(CBTConfig::logo))
+ {
+ splash.show();
+ }
+ splash.showMessage(splashHtml.arg(tr("Initializing the SWORD engine...")), Qt::AlignCenter);
+ initBackends();
+ splash.showMessage(splashHtml.arg(tr("Creating BibleTime's user interface...")), Qt::AlignCenter);
+ initView();
+ splash.showMessage(splashHtml.arg(tr("Initializing menu- and toolbars...")), Qt::AlignCenter);
+ initActions();
+ initConnections();
+ readSettings();
+ setPlainCaption(QString());
+}
+
+BibleTime::~BibleTime()
+{
+ // delete m_dcopInterface;
+ // The backend is deleted by the BibleTimeApp instance
+}
+
+/** Saves the properties of BibleTime to the application wide configfile */
+void BibleTime::saveSettings()
+{
+ //TODO: how to write settings?
+ //accel()->writeSettings(CBTConfig::getConfig());
+
+ CBTConfig::set(CBTConfig::toolbar, m_viewToolbar_action->isChecked());
+
+ // set the default to false
+ /* CBTConfig::set(CBTConfig::autoTileVertical, false);
+ CBTConfig::set(CBTConfig::autoTileHorizontal, false);
+ CBTConfig::set(CBTConfig::autoCascade, false);
+ */
+ CBTConfig::set(CBTConfig::autoTileVertical, m_windowAutoTileVertical_action->isChecked());
+ CBTConfig::set(CBTConfig::autoTileHorizontal, m_windowAutoTileHorizontal_action->isChecked());
+ CBTConfig::set(CBTConfig::autoCascade, m_windowAutoCascade_action->isChecked());
+
+ CProfile* p = m_profileMgr.startupProfile();
+ if (p)
+ {
+ saveProfile(p);
+ }
+}
+
+/** Reads the settings from the configfile and sets the right properties. */
+void BibleTime::readSettings()
+{
+ qDebug("******************BibleTime::readSettings******************************");
+ // accel()->readSettings(CBTConfig::getConfig());
+// CBTConfig::setupAccelSettings(CBTConfig::application, actionCollection());
+
+ m_viewToolbar_action->setChecked( CBTConfig::get(CBTConfig::toolbar) );
+ slotToggleToolbar();
+
+ if ( CBTConfig::get(CBTConfig::autoTileVertical) )
+ {
+ m_windowAutoTileVertical_action->setChecked( true );
+ m_windowManualMode_action->setChecked(false);
+ slotAutoTileVertical();
+ }
+ else if ( CBTConfig::get(CBTConfig::autoTileHorizontal) )
+ {
+ m_windowAutoTileHorizontal_action->setChecked( true );
+ m_windowManualMode_action->setChecked(false);
+ slotAutoTileHorizontal();
+ }
+ else if ( CBTConfig::get(CBTConfig::autoCascade) )
+ {
+ m_windowAutoCascade_action->setChecked(true);
+ m_windowManualMode_action->setChecked(false);
+ slotAutoCascade();
+ }
+ else
+ {
+ m_windowManualMode_action->setChecked(true);
+ slotManualArrangementMode();
+ }
+}
+
+/** Creates a new presenter in the MDI area according to the type of the module. */
+CDisplayWindow* BibleTime::createReadDisplayWindow(QList<CSwordModuleInfo*> modules, const QString& key)
+{
+ qApp->setOverrideCursor( QCursor(Qt::WaitCursor) );
+ qDebug("BibleTime::createReadDisplayWindow(QList<CSwordModuleInfo*> modules, const QString& key)");
+ CDisplayWindow* displayWindow = CDisplayWindowFactory::createReadInstance(modules, m_mdi);
+ if ( displayWindow )
+ {
+ displayWindow->init();
+ if (m_mdi->subWindowList().count() == 0)
+ displayWindow->showMaximized();
+ else
+ displayWindow->show();
+ // if (!key.isEmpty())
+ displayWindow->lookupKey(key);
+ }
+ // We have to process pending events here, otherwise displayWindow is not fully painted
+ qApp->processEvents();
+ // Now all events, including mouse clicks for the displayWindow have been handled
+ // and we can let the user click the same module again
+ m_bookshelfPage->unfreezeModules(modules);
+ qApp->restoreOverrideCursor();
+ return displayWindow;
+}
+
+
+/** Creates a new presenter in the MDI area according to the type of the module. */
+CDisplayWindow* BibleTime::createReadDisplayWindow(CSwordModuleInfo* module, const QString& key)
+{
+ QList<CSwordModuleInfo*> list;
+ list.append(module);
+
+ return createReadDisplayWindow(list, key);
+}
+
+CDisplayWindow* BibleTime::createWriteDisplayWindow(CSwordModuleInfo* module, const QString& key, const CDisplayWindow::WriteWindowType& type)
+{
+ qApp->setOverrideCursor( QCursor(Qt::WaitCursor) );
+
+ QList<CSwordModuleInfo*> modules;
+ modules.append(module);
+
+ CDisplayWindow* displayWindow = CDisplayWindowFactory::createWriteInstance(modules, m_mdi, type);
+ if ( displayWindow )
+ {
+ displayWindow->init();
+ if (m_mdi->subWindowList().count() == 0)
+ displayWindow->showMaximized();
+ else
+ displayWindow->show();
+ displayWindow->lookupKey(key);
+ }
+
+ qApp->restoreOverrideCursor();
+ return displayWindow;
+}
+
+/** Refreshes all presenters.*/
+void BibleTime::refreshDisplayWindows()
+{
+ foreach (QMdiSubWindow* subWindow, m_mdi->subWindowList())
+ {
+ if (CDisplayWindow* window = dynamic_cast<CDisplayWindow*>(subWindow->widget()))
+ {
+ window->reload(CSwordBackend::OtherChange);
+ }
+ }
+}
+
+/** Called before quit. */
+void BibleTime::slot_aboutToQuit()
+{
+ saveSettings();
+}
+
+/** Called before a window is closed */
+bool BibleTime::queryClose()
+{
+ qDebug("BibleTime::queryClose");
+ bool ret = true;
+
+ foreach(QMdiSubWindow* subWindow, m_mdi->subWindowList())
+ {
+ if (CDisplayWindow* window = dynamic_cast<CDisplayWindow*>(subWindow->widget()))
+ {
+ ret = ret && window->queryClose();
+ }
+ qDebug() << "return value:" << ret;
+ }
+ qDebug() << "final return value:" << ret;
+ return ret;
+}
+
+/** Restores the workspace if the flag for this is set in the config. */
+void BibleTime::restoreWorkspace()
+{
+ if (CProfile* p = m_profileMgr.startupProfile())
+ {
+ loadProfile(p);
+ }
+}
+
+/** Sets the plain caption of the main window */
+void BibleTime::setPlainCaption(const QString& title)
+{
+ QString suffix;
+ //Watch out, subtitles must be appended with the form " - [%s]", otherwise
+ //QMdiSubWindow will mess up when it is maximized
+ if (!title.isEmpty())
+ {
+ suffix = QString(" - [").append(title).append("]");
+ }
+ QMainWindow::setWindowTitle( QString("BibleTime ").append(BT_VERSION) + suffix );
+}
+
+/** Processes the commandline options given to BibleTime. */
+void BibleTime::processCommandline()
+{
+ QStringList args = qApp->QCoreApplication::arguments();
+
+ if ( !CBTConfig::get(CBTConfig::crashedTwoTimes) &&
+ !args.contains("--ignore-session") )
+ {
+ restoreWorkspace();
+ }
+
+ if ( args.contains("--open-default-bible") &&
+ !CBTConfig::get(CBTConfig::crashedLastTime) &&
+ !CBTConfig::get(CBTConfig::crashedTwoTimes))
+ {
+ int index = args.indexOf("--open-default-bible");
+ QString bibleKey;
+ if (index >= 0 && (index+1) < args.size())
+ {
+ bibleKey = args.at(index+1);
+ }
+ CSwordModuleInfo* bible = CBTConfig::get(CBTConfig::standardBible);
+ if (bibleKey == "random")
+ {
+ CSwordVerseKey vk(0);
+ const int maxIndex = 31100;
+ time_t seconds;
+ seconds = time (NULL);
+ srand(seconds);
+ int newIndex = rand() % maxIndex;
+ vk.setPosition(sword::TOP);
+ vk.Index(newIndex);
+ bibleKey = vk.key();
+ }
+ createReadDisplayWindow(bible, bibleKey);
+ m_mdi->myTileVertical();//we are sure only one window is open, which should be displayed fullscreen in the working area
+ }
+}
+
+bool BibleTime::event(QEvent* e)
+{
+// /* if (e->type() == QEvent::Polish) {
+// qWarning("BibleTime::event type Polish");
+// m_initialized = true;
+// }*/
+ if (e->type() == QEvent::Close)
+ {
+ }
+ return QMainWindow::event(e);
+}
+
+void BibleTime::closeEvent(QCloseEvent* e)
+{
+ QMainWindow::closeEvent(e);
+}
diff --git a/src/bibletime.h b/src/bibletime.h
new file mode 100644
index 0000000..bf27ccd
--- /dev/null
+++ b/src/bibletime.h
@@ -0,0 +1,380 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BIBLETIME_H
+#define BIBLETIME_H
+
+#include "frontend/profile/cprofilemgr.h"
+#include "frontend/profile/cprofile.h"
+#include "frontend/displaywindow/cdisplaywindow.h"
+
+class CSwordModuleInfo;
+
+#include <QList>
+#include <QMainWindow>
+
+class CMDIArea;
+class CDisplayWindow;
+class CMainIndex;
+class CBookmarkIndex;
+class CBookshelfIndex;
+
+namespace InfoDisplay {
+ class CInfoDisplay;
+}
+class QAction;
+class QMenu;
+class QToolBar;
+class QSplitter;
+
+/**
+ * @page backend The structure of the backend
+ * <p>
+ * The backend implementation for Sword is called CSwordBackend, the classes we use
+ * to work with keys are called CSwordVerseKey and CSwordLDKey, both are derived from
+ * the class CSwordKey.
+ * The CSwordKey derived classes used for Sword do also inherit the classes
+ * VerseKey (CSwordVerseKey)
+ * and SWKey (CSwordLDKey).
+ * </p>
+ * <p>
+ * The classes used to handle all module based stuff are derived from CModuleInfo.
+ * The module classes are: CSwordModuleInfo (for Sword modules),
+ * CSwordBibleModuleInfo (for bibles), CSwordCommentaryModuleInfo (for commentaries) and
+ * CSwordLexiconModuleInfo (for lexicons).
+ * Have a look at the class documentation of the mentioned classes to learn how the
+ * structure of them looks like and which class inherits which other class.
+ * </p>
+ * <p>
+ * The first objects which should be created in the application is the backend
+ * (for Sword the class is called CSwordBackend).
+ * Then create all the different module classes for the correct Sword modules.
+ * Have a look at
+ * BibleTime::initBackens() to see how it's done in BibleTime.@br
+ * Later you can work with them for example by using the CSwordKey and
+ * CSwordModuleInfo derived class.
+ * </p>
+ */
+
+/**
+ * @page frontend The structure of the frontend
+ *
+ * <p>
+ * The frontend contains the classes which interact with the user. For example the main index,
+ * the display windows, the searchdialog or the other parts.
+ * </p><p>
+ * The main index is implemented in the class CGroupManager, the items of the
+ * main index are implemented in the class CGroupManagerItem.
+ * Each CGroupManagerItem has a type() function which returns the type of
+ * the object (Module, Bookmark or Group).<BR>
+ * The display windows are all derived from the base class CPresenter.
+ * The display windows which handle Sword modules are all derived from the
+ * CSwordPresenter class.
+ * The display windows which provide functionality are CBiblePresenter for
+ * Bibles, CCommentaryPresenter for commentaries and CLexiconPresenter for
+ * lexicon and dictionaries.
+ * CSwordPresenter provides the essential base functions which are
+ * reimplemented in the derived classes (for example CSwordPresenter::lookup).<BR>
+ * </p><p>
+ * Another important part of the frontend are the keychoosers.
+ * They provide an interface to choose a key of a module.
+ * The interface for different module types is different.
+ * The base class is CKeyChooser which is the factory for the derived classes.
+ * Use the function CKeyChooser::createInstance to get the correct
+ * keychooser implementation for the desired module.<BR>
+ * </p>
+ */
+
+/** @mainpage BibleTime - sourcecode documentation
+ * BibleTime main page.
+ * <p>This is the sourcecode documentation of BibleTime, a Bible study tool for KDE/Linux.
+ * BibleTime is devided in two major parts, the backend and the frontend.
+ * The backend is mainly a wrapper around Sword's classes to use Qt functionality
+ * to allow easy access to it's functionality and to have it in a (more or less :)
+ * object oriented structure.</p><BR>
+ * <p>
+ * -Introduction to the backend: @ref backend<BR>
+ * -Introduction to the frontend: @ref frontend.<BR>
+ * The main class of BibleTime is called @ref BibleTime, which is the main window
+ * and initializes all important parts at startup. The text display windows
+ * belong to the @ref frontend.
+ * </p>
+ */
+
+/** BibleTime's main class.
+ * The main class of BibleTime. Here are the main widgets created.
+ *
+ * This is the main class of BibleTime! This class creates the GUI, the QAction objects
+ * and connects to some slots. Please insert the creation of actions in initActions,
+ * the creation of widgets into initView and the connect(...) calls into initConnections.
+ * Reading from a config file on creation time should go into readSettings(), saving into
+ * saveSettings().
+ * This is the general way of all BibleTime classes.
+ */
+class BibleTime : public QMainWindow
+{
+ friend class CMDIArea;
+ friend class BibleTimeDBusAdaptor;
+ Q_OBJECT
+public:
+ /**
+ * construtor of BibleTime
+ */
+ BibleTime();
+ /**
+ * destructor of BibleTime
+ */
+ virtual ~BibleTime();
+
+ /**
+ * Reads the settings from the configfile and sets the right properties.
+ */
+ void readSettings();
+ /**
+ * Saves the settings of this class
+ */
+ void saveSettings();
+ /**
+ * Restores the workspace if the flaf for this is set in the config.
+ */
+ void restoreWorkspace();
+ /**
+ * Apply the settings given by the profile p
+ */
+ void applyProfileSettings( Profile::CProfile* p );
+ /**
+ * Stores the settings of the mainwindow in the profile p
+ */
+ void storeProfileSettings( Profile::CProfile* p );
+
+public slots:
+ /**
+ * Opens the optionsdialog of BibleTime.
+ */
+ void slotSettingsOptions();
+ /**
+ * Opens the optionsdialog of BibleTime.
+ */
+ void slotSwordSetupDialog();
+ /**
+ * Opens the handbook.
+ */
+ void openOnlineHelp_Handbook();
+ /**
+ * Opens the bible study howto.
+ */
+ void openOnlineHelp_Howto();
+ /**
+ * Sets the plain caption of the main window
+ */
+ virtual void setPlainCaption( const QString& );
+ /**
+ * Processes the commandline options given to BibleTime.
+ */
+ void processCommandline();
+
+protected: // Protected methods
+ /**
+ * Initializes the view of this widget
+ */
+ void initView();
+ /**
+ * Initializes the menubar of BibleTime.
+ */
+ void initMenubar();
+ /**
+ * Initializes the SIGNAL / SLOT connections
+ */
+ void initConnections();
+ /**
+ * Initializes the backend
+ */
+ void initBackends();
+ /**
+ * Initializes the action objects of the GUI
+ */
+ void initActions();
+ /**
+ * Initializes one action object
+ */
+ QAction* initAction(QAction* action, QString text, QString icon, QKeySequence accel, QString tooltip, const char* slot );
+ /**
+ * Refreshes all presenter supporting at least in of the features given as parameter.
+ */
+ void refreshDisplayWindows();
+ /**
+ * Called before a window is closed
+ */
+ bool queryClose();
+
+ virtual bool event(QEvent*);
+
+ virtual void closeEvent(QCloseEvent* e);
+
+protected slots:
+ /**
+ * Creates a new presenter in the MDI area according to the type of the module.
+ */
+ CDisplayWindow* createReadDisplayWindow(QList<CSwordModuleInfo*> modules, const QString& key);
+ CDisplayWindow* createReadDisplayWindow(CSwordModuleInfo* module, const QString& key);
+ CDisplayWindow* createWriteDisplayWindow(CSwordModuleInfo* module, const QString& key, const CDisplayWindow::WriteWindowType& type);
+ /**
+ * Is called when the window menu is about to show ;-)
+ */
+ void slotWindowMenuAboutToShow();
+ /**
+ * This slot is connected with the windowAutoTile_action object
+ */
+ void slotAutoTileVertical();
+ /**
+ * This slot is connected with the windowAutoTile_action object
+ */
+ void slotAutoTileHorizontal();
+ /**
+ * This slot is connected with the windowAutoCascade_action object
+ */
+ void slotAutoCascade();
+ void slotUpdateWindowArrangementActions( QAction* );
+
+ void slotCascade();
+ void slotTileVertical();
+ void slotTileHorizontal();
+
+ void slotManualArrangementMode();
+
+ /**
+ * Is called when a client was selected in the window menu
+ */
+ void slotWindowMenuActivated();
+ /**
+ * Shows/hides the toolbar
+ */
+ void slotToggleToolbar();
+ /**
+ * Saves to the profile with the menu id ID
+ */
+ void saveProfile(QAction* action);
+ /**
+ * Saves the current settings into the currently activatred profile.
+ */
+ void saveProfile(Profile::CProfile* p);
+ /**
+ * Deletes the chosen session from the menu and from disk.
+ */
+ void deleteProfile(QAction* action);
+ /**
+ * Loads the profile with the menu id ID
+ */
+ void loadProfile(QAction* action);
+ /**
+ * Loads the profile with the menu ID id
+ */
+ void loadProfile(Profile::CProfile* p);
+ /**
+ * Toggles between normal and fullscreen mode.
+ */
+ void toggleFullscreen();
+ /**
+ * Is called when settings in the optionsdialog have been
+ * changed (ok or apply)
+ */
+ void slotSettingsChanged();
+ /**
+ * Is called when settings in the sword setup dialog have been
+ * changed (ok or apply)
+ */
+ void slotSwordSetupChanged();
+ /**
+ * Called when search button is pressed
+ **/
+ void slotSearchModules();
+ /**
+ * Called for search default bible
+ **/
+ void slotSearchDefaultBible();
+ /**
+ Saves current settings into a new profile.
+ */
+ void saveToNewProfile();
+ /**
+ * Slot to refresh the save profile and load profile menus.
+ */
+ void refreshProfileMenus();
+ /**
+ * Called before quit.
+ */
+ void slot_aboutToQuit();
+ /**
+ * Open the About Dialog
+ */
+ void slotOpenAboutDialog();
+
+private:
+ // docking widgets
+ QDockWidget* m_dock0;
+ QDockWidget* m_dock1;
+ QDockWidget* m_dock2;
+ QToolBar* m_mainToolBar;
+ // VIEW menu actions
+ QAction* m_viewToolbar_action;
+ QMenu* m_windowMenu;
+ /** WINDOW menu actions */
+ QAction* m_windowCascade_action;
+ QAction* m_windowTileHorizontal_action;
+ QAction* m_windowTileVertical_action;
+ QMenu* m_windowArrangementModeMenu;
+ QAction* m_windowManualMode_action;
+ QAction* m_windowAutoCascade_action;
+ QAction* m_windowAutoTileVertical_action;
+ QAction* m_windowAutoTileHorizontal_action;
+ QAction* m_windowCloseAll_action;
+
+ QMenu* m_windowSaveProfileMenu;
+ QAction* m_windowSaveToNewProfile_action;
+ QMenu* m_windowLoadProfileMenu;
+ QMenu* m_windowDeleteProfileMenu;
+ QAction* m_windowFullscreen_action;
+
+ QList<QAction*> m_windowOpenWindowsList;
+
+ bool m_initialized;
+ /**
+ * The list of installed SWORD modules
+ */
+ QList<CSwordModuleInfo*>* m_moduleList;
+
+ Profile::CProfile* m_currentProfile;
+ CMDIArea* m_mdi;
+
+ Profile::CProfileMgr m_profileMgr;
+
+ // docking windows
+ CBookmarkIndex* m_bookmarksPage;
+ CBookshelfIndex* m_bookshelfPage;
+ InfoDisplay::CInfoDisplay* m_infoDisplay;
+
+protected: //DBUS interface implementation
+ void closeAllModuleWindows();
+ void syncAllBibles(const QString& key);
+ void syncAllCommentaries(const QString& key);
+ void syncAllLexicons(const QString& key);
+ void syncAllVerseBasedModules(const QString& key);
+ void openWindow(const QString& moduleName, const QString& key);
+ void openDefaultBible(const QString& key);
+ QString getCurrentReference();
+ QStringList searchInModule(const QString& module, const QString& searchText);
+ QStringList searchInOpenModules(const QString& searchText);
+ QStringList searchInDefaultBible(const QString& searchText);
+ QStringList getModulesOfType(const QString& type);
+ void reloadModules();
+ //helper function
+ void syncAllModulesByType(const CSwordModuleInfo::ModuleType type, const QString& key);
+};
+
+#endif
diff --git a/src/bibletime_dbus.cpp b/src/bibletime_dbus.cpp
new file mode 100644
index 0000000..e2976b5
--- /dev/null
+++ b/src/bibletime_dbus.cpp
@@ -0,0 +1,208 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+//BibleTime includes
+#include "bibletime.h"
+
+#include "frontend/cmdiarea.h"
+#include "backend/config/cbtconfig.h"
+
+#include "backend/keys/cswordversekey.h"
+
+//Sword includes
+#include <versekey.h>
+#include <listkey.h>
+
+//QT
+#include <QList>
+#include <QDebug>
+#include <QMdiSubWindow>
+
+//helper function
+void BibleTime::syncAllModulesByType(const CSwordModuleInfo::ModuleType type, const QString& key) {
+ qDebug() << "Syncing modules by type to key" << key.toLatin1();
+ foreach (QMdiSubWindow* w, m_mdi->usableWindowList()) {
+ CDisplayWindow* d = dynamic_cast<CDisplayWindow*>(w->widget());
+ if (d && d->modules().count() && d->modules().first()->type() == type) {
+ d->lookupKey(key);
+ }
+ }
+}
+
+void BibleTime::closeAllModuleWindows() {
+ qDebug() << "DBUS: close all windows now...";
+ m_mdi->deleteAll();
+}
+
+void BibleTime::syncAllBibles(const QString& key) {
+ qDebug() << "DBUS: syncing all bibles ...";
+ syncAllModulesByType(CSwordModuleInfo::Bible, key);
+}
+
+void BibleTime::syncAllCommentaries(const QString& key) {
+ qDebug() << "DBUS: syncing all commentaries ...";
+ syncAllModulesByType(CSwordModuleInfo::Commentary, key);
+}
+
+void BibleTime::syncAllLexicons(const QString& key) {
+ qDebug() << "DBUS: syncing all lexicons ...";
+ syncAllModulesByType(CSwordModuleInfo::Lexicon, key);
+}
+
+void BibleTime::syncAllVerseBasedModules(const QString& key) {
+ qDebug() << "DBUS: syncing all verse based modules ...";
+ syncAllModulesByType(CSwordModuleInfo::Bible, key);
+ syncAllModulesByType(CSwordModuleInfo::Commentary, key);
+}
+
+void BibleTime::openWindow(const QString& moduleName, const QString& key) {
+ qDebug() << "DBUS: open window for module" << moduleName.toLatin1() << "and key" << key.toLatin1();
+ CSwordModuleInfo* module = CPointers::backend()->findModuleByName(moduleName);
+ if (module) {
+ createReadDisplayWindow(module, key);
+ }
+}
+
+void BibleTime::openDefaultBible(const QString& key) {
+ qDebug() << "DBUS: open default bible ...";
+ CSwordModuleInfo* mod = CBTConfig::get(CBTConfig::standardBible);
+ if (mod) {
+ openWindow(mod->name(), key);
+ }
+}
+
+QStringList BibleTime::searchInModule(const QString& moduleName, const QString& searchText) {
+ qDebug() << "DBUS: searchInModule" << moduleName.toLatin1();
+ QStringList ret;
+ CSwordModuleInfo* mod = CPointers::backend()->findModuleByName(moduleName);
+
+ if (mod) {
+ //mod->search(searchText, CSwordModuleSearch::multipleWords, sword::ListKey());
+ sword::ListKey scope;
+ mod->searchIndexed( searchText, scope );
+
+ sword::ListKey result = mod->searchResult();
+ const QString lead = QString("[%1] ").arg(moduleName);
+ ;
+ for ( int i = 0; i < result.Count(); ++i ) {
+ sword::SWKey* key = result.getElement(i);
+ Q_ASSERT(key);
+
+
+ if (mod->type() == CSwordModuleInfo::Bible || mod->type() == CSwordModuleInfo::Commentary) {
+ sword::VerseKey vk(key->getText());
+ ret << lead + QString::fromUtf8( vk.getOSISRef() );
+ }
+ else {
+ ret << lead + QString::fromUtf8( key->getText() );
+ }
+ }
+ }
+
+ return ret;
+
+}
+
+QStringList BibleTime::searchInOpenModules(const QString& searchText) {
+ qDebug() << "DBUS: search in open modules ...";
+ QStringList ret;
+ foreach (QMdiSubWindow* subWindow, m_mdi->subWindowList()) {
+ if (CDisplayWindow* w = dynamic_cast<CDisplayWindow*>(subWindow->widget())) {
+ QList<CSwordModuleInfo*> windowModules = w->modules();
+ QList<CSwordModuleInfo*>::iterator end_it = windowModules.end();
+ for (QList<CSwordModuleInfo*>::iterator it(windowModules.begin()); it != end_it; ++it) {
+ ret += searchInModule((*it)->name(), searchText);
+ }
+ }
+ }
+ return ret;
+}
+
+QStringList BibleTime::searchInDefaultBible(const QString& searchText) {
+ CSwordModuleInfo* bible = CBTConfig::get(CBTConfig::standardBible);
+ return searchInModule(bible->name(), searchText);
+}
+
+QString BibleTime::getCurrentReference() {
+ qDebug() << "BibleTime::getCurrentReference";
+ QString ret = QString::null;
+
+ QMdiSubWindow* activeSubWindow = m_mdi->activeSubWindow();
+ if (!activeSubWindow) return ret;
+
+ CDisplayWindow* w = dynamic_cast<CDisplayWindow*>(activeSubWindow->widget());
+
+ if (w) {
+ QString modType;
+ Q_ASSERT(w->modules().first());
+ switch (w->modules().first()->type()) {
+ case CSwordModuleInfo::Bible:
+ modType = "BIBLE";
+ break;
+ case CSwordModuleInfo::Commentary:
+ modType = "COMMENTARY";
+ break;
+ case CSwordModuleInfo::GenericBook:
+ modType = "BOOK";
+ break;
+ case CSwordModuleInfo::Lexicon:
+ modType = "LEXICON";
+ break;
+ default:
+ modType = "UNSUPPORTED";
+ break;
+ }
+
+ ret.append("[").append(w->modules().first()->name()).append("] ");
+ ret.append("[").append(modType).append("] ");
+
+ CSwordVerseKey* vk = dynamic_cast<CSwordVerseKey*>( w->key() );
+ if (vk) {
+ ret.append( vk->getOSISRef() );
+ }
+ else {
+ ret.append( w->key()->key() );
+ }
+ }
+
+ return ret;
+}
+
+QStringList BibleTime::getModulesOfType(const QString& type) {
+ QStringList ret;
+
+ CSwordModuleInfo::ModuleType modType = CSwordModuleInfo::Unknown;
+ if (type == "BIBLES") {
+ modType = CSwordModuleInfo::Bible;
+ }
+ else if (type == "COMMENTARIES") {
+ modType = CSwordModuleInfo::Commentary;
+ }
+ else if (type == "LEXICONS") {
+ modType = CSwordModuleInfo::Lexicon;
+
+ }
+ else if (type == "BOOKS") {
+ modType = CSwordModuleInfo::GenericBook;
+ }
+
+ QList<CSwordModuleInfo*> modList = CPointers::backend()->moduleList();
+ for (QList<CSwordModuleInfo*>::iterator it( modList.begin() ); it != modList.end(); ++it) {
+ if ((*it)->type() == modType) {
+ ret.append( (*it)->name() );
+ }
+ }
+
+ return ret;
+}
+
+void BibleTime::reloadModules() {
+ slotSwordSetupChanged();
+}
diff --git a/src/bibletime_dbus_adaptor.cpp b/src/bibletime_dbus_adaptor.cpp
new file mode 100644
index 0000000..ac32c47
--- /dev/null
+++ b/src/bibletime_dbus_adaptor.cpp
@@ -0,0 +1,71 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef NO_DBUS
+
+#include "bibletime_dbus_adaptor.h"
+
+BibleTimeDBusAdaptor::BibleTimeDBusAdaptor(BibleTime *bibletime_ptr) :
+ QDBusAbstractAdaptor(bibletime_ptr),
+ m_bibletime(bibletime_ptr)
+{
+}
+
+void BibleTimeDBusAdaptor::syncAllBibles(const QString& key){
+ m_bibletime->syncAllBibles(key);
+}
+
+void BibleTimeDBusAdaptor::syncAllCommentaries(const QString& key){
+ m_bibletime->syncAllCommentaries(key);
+}
+void BibleTimeDBusAdaptor::syncAllLexicons(const QString& key){
+ m_bibletime->syncAllLexicons(key);
+}
+
+void BibleTimeDBusAdaptor::syncAllVerseBasedModules(const QString& key){
+ m_bibletime->syncAllVerseBasedModules(key);
+}
+
+void BibleTimeDBusAdaptor::reloadModules(){
+ m_bibletime->reloadModules();
+}
+
+void BibleTimeDBusAdaptor::openWindow(const QString& moduleName, const QString& key){
+ m_bibletime->openWindow(moduleName, key);
+}
+
+void BibleTimeDBusAdaptor::openDefaultBible(const QString& key){
+ m_bibletime->openDefaultBible(key);
+}
+
+void BibleTimeDBusAdaptor::closeAllModuleWindows(){
+ m_bibletime->closeAllModuleWindows();
+}
+
+QString BibleTimeDBusAdaptor::getCurrentReference(){
+ return m_bibletime->getCurrentReference();
+}
+
+QStringList BibleTimeDBusAdaptor::searchInModule(const QString& moduleName, const QString& searchText){
+ return m_bibletime->searchInModule(moduleName, searchText);
+}
+
+QStringList BibleTimeDBusAdaptor::searchInOpenModules(const QString& searchText){
+ return m_bibletime->searchInOpenModules(searchText);
+}
+
+QStringList BibleTimeDBusAdaptor::searchInDefaultBible(const QString& searchText){
+ return m_bibletime->searchInDefaultBible(searchText);
+}
+
+QStringList BibleTimeDBusAdaptor::getModulesOfType(const QString& type){
+ return m_bibletime->getModulesOfType(type);
+}
+
+#endif //NO_DBUS
diff --git a/src/bibletime_dbus_adaptor.h b/src/bibletime_dbus_adaptor.h
new file mode 100644
index 0000000..dc238db
--- /dev/null
+++ b/src/bibletime_dbus_adaptor.h
@@ -0,0 +1,110 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef NO_DBUS
+
+#ifndef BIBLETIME_DBUS_ADAPTOR_H
+#define BIBLETIME_DBUS_ADAPTOR_H
+
+#include "bibletime.h"
+
+//Qt includes
+#include <QString>
+#include <QStringList>
+#ifndef NO_DBUS
+#include <QDBusAbstractAdaptor>
+#endif
+
+class BibleTimeDBusAdaptor : QDBusAbstractAdaptor
+{
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "info.bibletime.BibleTime")
+
+private:
+ BibleTime* m_bibletime;
+
+public:
+ BibleTimeDBusAdaptor(BibleTime *bibletime_ptr);
+
+public slots:
+ /** Sync all open Bible windows to the key.
+ * @param key The key which is set to all Bible windows.
+ */
+ void syncAllBibles(const QString& key);
+ /** Sync all open commentary windows to the key.
+ * @param key The key which is set to all Commentary windows.
+ */
+ void syncAllCommentaries(const QString& key);
+ /** Sync all open lexicon windows to the key.
+ * @param key The key which is set to all Lexicon windows.
+ */
+ void syncAllLexicons(const QString& key);
+ /** Sync all open verse based (i.e. Bibles and commentaries) windows to the key.
+ * @param key The key which is set to all Bible and Commentary windows.
+ */
+ void syncAllVerseBasedModules(const QString& key);
+ /** Reload all modules
+ */
+ void reloadModules();
+ /** Open a new read window for the module moduleName using the given key
+ * @param moduleName The name of the module which is opened in a new module window.
+ * @param key The key to set to the newly opened window.
+ */
+ void openWindow(const QString& moduleName, const QString& key);
+ /** Open a new read window for the default Bible module using the given key
+ * @param key The key to set to the newly opened window.
+ */
+ void openDefaultBible(const QString& key);
+ /** Close all open windows.
+ */
+ void closeAllModuleWindows();
+ /** Returns the reference used in the current window.
+ * The format of the returned reference is
+ * [Module] [Type] OSIS_Reference,
+ * wtih type one of BIBLE/COMMENTARY/BOOK/LEXICON/UNSUPPORTED
+ * If the type is BIBLE or COMMENTARY the reference is an OSIS ref
+ * in the other cases it's the key name, for books /Chapter/Subsection
+ * for Lexicons just the plain key, e.g. "ADAM".
+ * e.g.
+ * [KJV] [BIBLE] Gen.1.1
+ * [MHC] [COMMENTARY] Gen.1.1
+ * [ISBE] [LEXICON] REDEMPTION
+ * @return The reference displayed in the currently active module window. Empty if none is active.
+ */
+ QString getCurrentReference();
+ /** Seach the searchText in the specified module.
+ * @param moduleName The module to search in
+ * @param searchText Search for this in the modules
+ * @return The search result. It's in the format [modulename] osis_ref_of_the_found_key. For example "[KJV] Gen.1.1".
+ */
+ QStringList searchInModule(const QString& moduleName, const QString& searchText) ;
+ /** Search in all open modules and return the search result.
+ * The result is in the same format as searchInModule
+ * @param searchText Search for this in the modules
+ * @return The search result for a searchin all opened module windows
+ * @see searchInModule For the search result format.
+ */
+ QStringList searchInOpenModules(const QString& searchText);
+ /** Search in the default Bible module and return the search result.
+ * The result is in the same format as searchInModule
+ * @param searchText Search for this in the modules
+ * @return The search result for a search in the default Bible
+ * @see searchInModule
+ */
+ QStringList searchInDefaultBible(const QString& searchText);
+ /** Return a list of modules of the given type.
+ * @param type One of BIBLES, COMMENTARIES, LEXICONS, BOOKS
+ * @return The list of modules of the given type, may be empty
+ */
+ QStringList getModulesOfType(const QString& type);
+};
+
+#endif
+
+#endif //NO_DBUS
diff --git a/src/bibletime_init.cpp b/src/bibletime_init.cpp
new file mode 100644
index 0000000..5effe7e
--- /dev/null
+++ b/src/bibletime_init.cpp
@@ -0,0 +1,481 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//BibleTime includes
+#include "bibletime.h"
+#include "util/cpointers.h"
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+#include "backend/managers/btstringmgr.h"
+#include "backend/managers/cswordbackend.h"
+#include "backend/managers/clanguagemgr.h"
+#include "frontend/mainindex/cmainindex.h"
+#include "frontend/profile/cprofilemgr.h"
+#include "frontend/profile/cprofile.h"
+#include "frontend/cmdiarea.h"
+#include "frontend/cprinter.h"
+#include "backend/config/cbtconfig.h"
+#include "frontend/cinfodisplay.h"
+#include "frontend/mainindex/bookshelf/cbookshelfindex.h"
+#include "frontend/mainindex/bookmarks/cbookmarkindex.h"
+
+// Qt includes
+#include <QSplitter>
+#include <QPointer>
+#include <QLabel>
+#include <QVBoxLayout>
+#include <QMenu>
+#include <QMenuBar>
+#include <QToolBar>
+#include <QApplication>
+#include <QDebug>
+#include <QDockWidget>
+
+// Sword includes
+#include <swlog.h>
+
+using namespace InfoDisplay;
+using namespace Profile;
+
+/**Initializes the view of this widget*/
+void BibleTime::initView()
+{
+ m_mdi = new CMDIArea(this);
+ setCentralWidget(m_mdi);
+
+ m_dock0 = new QDockWidget(tr("Bookshelf"), this);
+ m_dock0->setObjectName("BookshelfDock");
+ m_bookshelfPage = new CBookshelfIndex(0);
+ m_dock0->setWidget(m_bookshelfPage);
+ addDockWidget(Qt::LeftDockWidgetArea, m_dock0);
+
+ m_dock1 = new QDockWidget(tr("Bookmarks"), this);
+ m_dock1->setObjectName("BookmarksDock");
+ m_bookmarksPage = new CBookmarkIndex(0);
+ m_dock1->setWidget(m_bookmarksPage);
+ addDockWidget(Qt::LeftDockWidgetArea, m_dock1);
+ tabifyDockWidget(m_dock1, m_dock0);
+
+ m_dock2 = new QDockWidget(tr("Mag"), this);
+ m_dock2->setObjectName("MagDock");
+ m_infoDisplay = new CInfoDisplay(this);
+ m_infoDisplay->resize(150,150);
+ m_dock2->setWidget(m_infoDisplay);
+ addDockWidget(Qt::LeftDockWidgetArea, m_dock2);
+
+ CPointers::setInfoDisplay(m_infoDisplay);
+ m_mdi->setMinimumSize(100, 100);
+ m_mdi->setFocusPolicy(Qt::ClickFocus);
+}
+
+QAction* BibleTime::initAction(QAction* action, QString text, QString icon, QKeySequence accel, QString tooltip, const char* slot )
+{
+ action->setText(text);
+ if ( ! icon.isEmpty() )
+ action->setIcon(util::filesystem::DirectoryUtil::getIcon(icon));
+ action->setShortcut(accel);
+ if (tooltip != QString::null) action->setToolTip(tooltip);
+// actionCollection()->addAction(actionName, action);
+ if (slot) QObject::connect( action, SIGNAL(triggered()), this, slot );
+ return action;
+}
+
+/** Initializes the action objects of the GUI */
+void BibleTime::initActions()
+{
+ //:Main menu item
+ QMenu* fileMenu = menuBar()->addMenu(tr("&File"));
+ //:Main menu item
+ QMenu* viewMenu = menuBar()->addMenu(tr("&View"));
+ //:Main menu item
+ QMenu* searchMenu = menuBar()->addMenu(tr("&Search"));
+ //:Main menu item
+ m_windowMenu = menuBar()->addMenu(tr("&Window"));
+ //:Main menu item
+ QMenu* settingsMenu = menuBar()->addMenu(tr("Se&ttings"));
+ //:Main menu item
+ QMenu* helpMenu = menuBar()->addMenu(tr("&Help"));
+
+ //:Name of the main toolbar
+ m_mainToolBar = addToolBar(tr("Main Toolbar"));
+ m_mainToolBar->setObjectName("MainToolBar");
+ m_mainToolBar->setFloatable(false);
+ m_mainToolBar->setMovable(false);
+
+ QAction* tmp = new QAction(this);
+ initAction(
+ tmp,
+ tr("&Quit"),
+ QString("exit.svg"),
+ QKeySequence(Qt::CTRL + Qt::Key_Q),
+ tr("Quit BibleTime"),
+ SLOT( close() )
+ );
+ fileMenu->addAction(tmp);
+ m_mainToolBar->addAction(tmp);
+ m_mainToolBar->addSeparator();
+
+ m_windowFullscreen_action = new QAction(this);
+ m_windowFullscreen_action->setCheckable(true);
+ viewMenu->addAction(initAction(
+ m_windowFullscreen_action,
+ tr("&Fullscreen mode"),
+ CResMgr::mainMenu::window::showFullscreen::icon,
+ CResMgr::mainMenu::window::showFullscreen::accel,
+ tr("Toggle fullscreen mode of the main window"),
+ SLOT(toggleFullscreen()))
+ );
+ m_mainToolBar->addAction(m_windowFullscreen_action);
+
+ m_viewToolbar_action = new QAction(this);
+ m_viewToolbar_action->setCheckable(true);
+ m_viewToolbar_action->setChecked(true);
+ viewMenu->addAction(initAction(
+ m_viewToolbar_action,
+ tr("&Show toolbar"),
+ "",
+ QKeySequence(Qt::Key_F6),
+ "",
+ SLOT(slotToggleToolbar())));
+
+ QAction* action = m_dock0->toggleViewAction();
+ action->setText(tr("Show Bookshelf"));
+ viewMenu->addAction(action);
+
+ action = m_dock1->toggleViewAction();
+ action->setText(tr("Show Bookmarks"));
+ viewMenu->addAction(action);
+
+ action = m_dock2->toggleViewAction();
+ action->setText(tr("Show Mag"));
+ viewMenu->addAction(action);
+
+ m_mainToolBar->addSeparator();
+
+ tmp = initAction(
+ new QAction(this),
+ tr("Search in &open works..."),
+ CResMgr::mainMenu::mainIndex::search::icon,
+ CResMgr::mainMenu::mainIndex::search::accel,
+ tr("Search in all works that are currently open"),
+ SLOT( slotSearchModules() )
+ );
+ searchMenu->addAction(tmp);
+ m_mainToolBar->addAction(tmp);
+ m_mainToolBar->addSeparator();
+
+ searchMenu->addAction(initAction(
+ new QAction(this),
+ tr("Search in standard &Bible..."),
+ CResMgr::mainMenu::mainIndex::searchdefaultbible::icon,
+ CResMgr::mainMenu::mainIndex::searchdefaultbible::accel,
+ tr("Search in the standard Bible"),
+ SLOT(slotSearchDefaultBible())));
+
+ m_windowSaveProfileMenu = new QMenu(tr("&Save session"));
+ m_windowMenu->addMenu(m_windowSaveProfileMenu);
+
+ m_windowSaveToNewProfile_action = new QAction(this);
+ m_windowMenu->addAction(initAction(
+ m_windowSaveToNewProfile_action,
+ tr("Save as &new session..."),
+ CResMgr::mainMenu::window::saveToNewProfile::icon,
+ CResMgr::mainMenu::window::saveToNewProfile::accel,
+ tr("Create and save a new session"),
+ SLOT( saveToNewProfile() ))
+ );
+
+ m_windowLoadProfileMenu = new QMenu(tr("&Load session"));
+ m_windowMenu->addMenu(m_windowLoadProfileMenu);
+
+ m_windowDeleteProfileMenu = new QMenu(tr("&Delete session"));
+ m_windowMenu->addMenu(m_windowDeleteProfileMenu);
+
+ QObject::connect(m_windowLoadProfileMenu, SIGNAL(triggered(QAction*)), SLOT(loadProfile(QAction*)));
+ QObject::connect(m_windowSaveProfileMenu, SIGNAL(triggered(QAction*)), SLOT(saveProfile(QAction*)));
+ QObject::connect(m_windowDeleteProfileMenu, SIGNAL(triggered(QAction*)), SLOT(deleteProfile(QAction*)));
+
+ refreshProfileMenus();
+
+ m_windowMenu->addSeparator();
+
+//--------------------------Window arrangement actions---------------------------------------
+
+ QMenu* arrangementMenu = new QMenu(tr("&Arrangement mode"));
+ m_windowMenu->addMenu(arrangementMenu);
+
+ m_windowManualMode_action = new QAction(this);
+ m_windowManualMode_action->setCheckable(true);
+ arrangementMenu->addAction(initAction(
+ m_windowManualMode_action,
+ tr("&Manual mode"),
+ CResMgr::mainMenu::window::arrangementMode::manual::icon,
+ CResMgr::mainMenu::window::arrangementMode::manual::accel,
+ "",
+ SLOT( slotManualArrangementMode() ))
+ );
+
+ m_windowAutoTileVertical_action = new QAction(this);
+ m_windowAutoTileVertical_action->setCheckable(true);
+ //: Vertical tiling means that windows are vertical, placed side by side
+ arrangementMenu->addAction(initAction(
+ m_windowAutoTileVertical_action,
+ tr("Auto-tile &vertically"),
+ CResMgr::mainMenu::window::arrangementMode::autoTileVertical::icon,
+ CResMgr::mainMenu::window::arrangementMode::autoTileVertical::accel,
+ tr("Automatically tile the open windows vertically (arrange side by side)"),
+ SLOT( slotAutoTileVertical() ))
+ );
+
+ m_windowAutoTileHorizontal_action = new QAction(this);
+ m_windowAutoTileHorizontal_action->setCheckable(true);
+ arrangementMenu->addAction(initAction(
+ m_windowAutoTileHorizontal_action,
+ //: Horizontal tiling means that windows are horizontal, placed on top of each other
+ tr("Auto-tile &horizontally"),
+ CResMgr::mainMenu::window::arrangementMode::autoTileHorizontal::icon,
+ CResMgr::mainMenu::window::arrangementMode::autoTileHorizontal::accel,
+ tr("Automatically tile the open windows horizontally (arrange on top of each other)"),
+ SLOT( slotAutoTileHorizontal() ))
+ );
+
+ m_windowAutoCascade_action = new QAction(this);
+ m_windowAutoCascade_action->setCheckable(true);
+ arrangementMenu->addAction(initAction(
+ m_windowAutoCascade_action,
+ //: Cascading means that only one window is visible, others are behind that
+ tr("Auto-&cascade"),
+ CResMgr::mainMenu::window::arrangementMode::autoCascade::icon,
+ CResMgr::mainMenu::window::arrangementMode::autoCascade::accel,
+ tr("Automatically cascade the open windows"),
+ SLOT( slotAutoCascade() ))
+ );
+
+ m_windowCascade_action = new QAction(this);
+ m_windowMenu->addAction(initAction(
+ m_windowCascade_action,
+ tr("&Cascade"),
+ CResMgr::mainMenu::window::cascade::icon,
+ CResMgr::mainMenu::window::cascade::accel,
+ tr("Cascade the open windows"),
+ SLOT( slotCascade() ))
+ );
+
+ m_windowTileVertical_action = new QAction(this);
+ m_windowMenu->addAction(initAction(
+ m_windowTileVertical_action,
+ tr("Tile &vertically"),
+ CResMgr::mainMenu::window::tileVertical::icon,
+ CResMgr::mainMenu::window::tileVertical::accel,
+ tr("Vertically tile (arrange side by side) the open windows"),
+ SLOT( slotTileVertical() ))
+ );
+
+ m_windowTileHorizontal_action = new QAction(this);
+ m_windowMenu->addAction(initAction(
+ m_windowTileHorizontal_action,
+ tr("Tile &horizontally"),
+ CResMgr::mainMenu::window::tileHorizontal::icon,
+ CResMgr::mainMenu::window::tileHorizontal::accel,
+ tr("Horizontally tile (arrange on top of each other) the open windows"),
+ SLOT( slotTileHorizontal() ))
+ );
+
+ m_windowCloseAll_action = new QAction(this);
+ m_windowMenu->addAction(initAction(
+ m_windowCloseAll_action,
+ tr("Cl&ose all windows"),
+ CResMgr::mainMenu::window::closeAll::icon,
+ CResMgr::mainMenu::window::closeAll::accel,
+ tr("Close all open windows inside BibleTime"),
+ 0)
+ );
+ QObject::connect(m_windowCloseAll_action, SIGNAL(triggered()), m_mdi, SLOT( deleteAll() ) );
+
+ settingsMenu->addAction(initAction(
+ new QAction(this),
+ tr("&Configure BibleTime..."),
+ "configure.svg",
+ QKeySequence(),
+ tr("Set BibleTime's preferences"),
+ SLOT( slotSettingsOptions() )));
+ settingsMenu->addSeparator();
+
+ settingsMenu->addAction(initAction(
+ new QAction(this),
+ tr("Bookshelf &Manager..."),
+ CResMgr::mainMenu::settings::swordSetupDialog::icon,
+ CResMgr::mainMenu::settings::swordSetupDialog::accel,
+ tr("Configure your bookshelf and install/update/remove/index works"),
+ SLOT( slotSwordSetupDialog() )));
+
+ tmp = initAction(
+ new QAction(this),
+ tr("&Handbook"),
+ CResMgr::mainMenu::help::handbook::icon,
+ CResMgr::mainMenu::help::handbook::accel,
+ tr("Open BibleTime's handbook"),
+ SLOT( openOnlineHelp_Handbook() )
+ );
+ helpMenu->addAction(tmp);
+ m_mainToolBar->addAction(tmp);
+
+ helpMenu->addAction(initAction(
+ new QAction(this),
+ //: "Howto" is a guide; if there's no natural translation for HowTo, translate it as Guide
+ tr("&Bible Study Howto"),
+ CResMgr::mainMenu::help::bibleStudyHowTo::icon,
+ CResMgr::mainMenu::help::bibleStudyHowTo::accel,
+ tr("Open the Bible study HowTo included with BibleTime.<BR>This HowTo is an introduction on how to study the Bible in an efficient way."),
+ SLOT( openOnlineHelp_Howto() ))
+ );
+
+ helpMenu->addSeparator();
+
+ helpMenu->addAction( initAction(
+ new QAction(this),
+ tr("&About BibleTime"),
+ "",
+ QKeySequence(),
+ "",
+ SLOT(slotOpenAboutDialog()))
+ );
+}
+
+/** Initializes the SIGNAL / SLOT connections */
+void BibleTime::initConnections() {
+ QObject::connect(m_mdi, SIGNAL(sigSetToplevelCaption(const QString&)),
+ this, SLOT(setPlainCaption(const QString&)));
+ QObject::connect(m_mdi, SIGNAL(createReadDisplayWindow(QList<CSwordModuleInfo*>, const QString&)),
+ this, SLOT(createReadDisplayWindow(QList<CSwordModuleInfo*>, const QString&)));
+
+ if (m_windowMenu) {
+ QObject::connect(m_windowMenu, SIGNAL(aboutToShow()), this, SLOT(slotWindowMenuAboutToShow()));
+ }
+ else {
+ qWarning() << "Main window: can't find window menu";
+ }
+
+ bool ok;
+ ok = connect(m_bookmarksPage, SIGNAL(createReadDisplayWindow(QList<CSwordModuleInfo*>, const QString&)),
+ this, SLOT(createReadDisplayWindow(QList<CSwordModuleInfo*>,const QString&)));
+ Q_ASSERT(ok);
+ ok = connect(m_bookshelfPage, SIGNAL(createReadDisplayWindow(QList<CSwordModuleInfo*>, const QString&)),
+ this, SLOT(createReadDisplayWindow(QList<CSwordModuleInfo*>,const QString&)));
+ Q_ASSERT(ok);
+ ok = connect(m_bookshelfPage, SIGNAL(createWriteDisplayWindow(CSwordModuleInfo*, const QString&, const CDisplayWindow::WriteWindowType&)),
+ this, SLOT(createWriteDisplayWindow(CSwordModuleInfo*,const QString&, const CDisplayWindow::WriteWindowType&)));
+ Q_ASSERT(ok);
+
+ connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(slot_aboutToQuit()));
+}
+
+/** Initializes the backend */
+void BibleTime::initBackends() {
+ qDebug("BibleTime::initBackends");
+
+ sword::StringMgr::setSystemStringMgr( new BTStringMgr() );
+ sword::SWLog::getSystemLog()->setLogLevel(1);
+
+ CSwordBackend* backend = new CSwordBackend();
+ backend->booknameLanguage(CBTConfig::get(CBTConfig::language) );
+
+ CPointers::setBackend(backend);
+ const CSwordBackend::LoadError errorCode = CPointers::backend()->initModules(CSwordBackend::OtherChange);
+
+ m_moduleList = 0;
+ if ( errorCode == CSwordBackend::NoError ) { //no error
+ m_moduleList = &(CPointers::backend()->moduleList());
+ }
+ else {
+ m_moduleList = 0;
+ //show error message that initBackend failed
+ //TODO:
+// switch (errorCode) {
+// case CSwordBackend::NoSwordConfig: //mods.d or mods.conf missing
+// {
+// KStartupLogo::hideSplash();
+// qDebug("case CSwordBackend::NoSwordConfig");
+// BookshelfManager::CSwordSetupDialog dlg;
+// dlg.showPart( BookshelfManager::CSwordSetupDialog::Sword );
+// dlg.exec();
+// break;
+// }
+//
+// case CSwordBackend::NoModules: //no modules installed, but config exists
+// {
+// KStartupLogo::hideSplash();
+// qDebug("case CSwordBackend::NoModules");
+// BookshelfManager::CSwordSetupDialog dlg;
+// dlg.showPart( BookshelfManager::CSwordSetupDialog::Install );
+// dlg.exec();
+// break;
+// }
+//
+// default: //unknown error
+// {
+// KStartupLogo::hideSplash();
+// qDebug("unknown error");
+// BookshelfManager::CSwordSetupDialog dlg;
+// dlg.showPart( BookshelfManager::CSwordSetupDialog::Sword );
+// dlg.exec();
+// break;
+// }
+// }
+ }
+
+ //This function will
+ // - delete all orphaned indexes (no module present) if autoDeleteOrphanedIndices is true
+ // - delete all indices of modules where hasIndex() returns false
+ //BookshelfManager::CManageIndicesWidget::deleteOrphanedIndices();
+ //TODO: //backend::deleteOrphanedIndices();
+
+}
+
+void BibleTime::applyProfileSettings( CProfile* p ) {
+ qDebug("BibleTime::applyProfileSettings");
+ Q_ASSERT(p);
+ if (!p) return;
+
+ //first Main Window state
+ m_windowFullscreen_action->setChecked( p->fullscreen() ); //set the fullscreen button state
+ toggleFullscreen(); //either showFullscreen or showNormal
+ if (p->maximized()) QMainWindow::showMaximized(); //if maximized, then also call showMaximized
+ //Then Main Window geometry
+ QMainWindow::resize( p->geometry().size() ); //Don't use QMainWindowInterface::resize
+ QMainWindow::move( p->geometry().topLeft() );//Don't use QMainWindowInterface::move
+ restoreState(p->getMainwindowState());
+
+ const CMDIArea::MDIArrangementMode newArrangementMode = p->getMDIArrangementMode();
+ //make sure actions are updated by calling the slot functions
+ //updatesEnabled in the MDI area is false atm, so changes won't actually be displayed yet
+ switch(newArrangementMode){
+ case CMDIArea::ArrangementModeTileVertical: slotAutoTileVertical(); break;
+ case CMDIArea::ArrangementModeTileHorizontal: slotAutoTileHorizontal(); break;
+ case CMDIArea::ArrangementModeCascade: slotAutoCascade(); break;
+ default: slotManualArrangementMode(); break;
+ }
+}
+
+void BibleTime::storeProfileSettings( CProfile* p ) {
+ Q_ASSERT(p && m_windowFullscreen_action);
+ if (!p || !m_windowFullscreen_action) return;
+
+ p->setMainwindowState(saveState());
+ p->setFullscreen( m_windowFullscreen_action->isChecked() );
+ p->setMaximized( this->QMainWindow::isMaximized() );
+
+ QRect geometry;
+ geometry.setTopLeft(pos());
+ geometry.setSize(size());
+ p->setGeometry(geometry);
+
+ p->setMDIArrangementMode(m_mdi->getMDIArrangementMode());
+}
+
diff --git a/src/bibletime_slots.cpp b/src/bibletime_slots.cpp
new file mode 100644
index 0000000..3e054af
--- /dev/null
+++ b/src/bibletime_slots.cpp
@@ -0,0 +1,510 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//own includes
+#include "bibletime.h"
+
+#include "backend/keys/cswordversekey.h"
+
+#include "util/ctoolclass.h"
+#include "util/directoryutil.h"
+
+#include "frontend/cmdiarea.h"
+#include "frontend/profile/cprofilemgr.h"
+#include "frontend/profile/cprofile.h"
+#include "frontend/profile/cprofilewindow.h"
+#include "frontend/settingsdialogs/cconfigurationdialog.h"
+#include "backend/config/cbtconfig.h"
+#include "frontend/cinputdialog.h"
+#include "frontend/cinfodisplay.h"
+#include "frontend/mainindex/cmainindex.h"
+#include "frontend/displaywindow/cdisplaywindow.h"
+#include "frontend/displaywindow/cbiblereadwindow.h"
+#include "frontend/searchdialog/csearchdialog.h"
+#include "frontend/bookshelfmanager/btmodulemanagerdialog.h"
+#include "frontend/htmldialogs/btaboutdialog.h"
+
+//QT includes
+#include <QClipboard>
+#include <QInputDialog>
+#include <QList>
+#include <QAction>
+#include <QMenu>
+#include <QToolBar>
+#include <QApplication>
+#include <QProcess>
+#include <QMdiSubWindow>
+#include <QtGlobal>
+#include <QDesktopServices>
+
+using namespace Profile;
+
+// /* An action which stores a user defined pointer to a widget.
+// * @author Joachim Ansorg
+// */
+// class KUserDataAction : public KToggleAction {
+// public:
+// KUserDataAction( QString caption, const KShortcut& shortcut, const QObject* receiver, const char* slot, KActionCollection* actionCollection)
+// : KToggleAction(caption, actionCollection), m_userData(0)
+// {
+// setShortcut(shortcut);
+// QObject::connect(this, SIGNAL(triggered()), receiver, slot);
+// };
+//
+// void setUserData(QWidget* const data) {
+// m_userData = data;
+// };
+// QWidget* const getUserData() const {
+// return m_userData;
+// };
+//
+// private:
+// QWidget* m_userData;
+// };
+
+/** Opens the optionsdialog of BibleTime. */
+void BibleTime::slotSettingsOptions() {
+ qDebug("BibleTime::slotSettingsOptions");
+ CConfigurationDialog *dlg = new CConfigurationDialog(this, 0 /*actionCollection()*/);
+ QObject::connect(dlg, SIGNAL(signalSettingsChanged()), this, SLOT(slotSettingsChanged()) );
+
+ dlg->show();
+}
+
+/** Is called when settings in the optionsdialog were changed (ok or apply) */
+void BibleTime::slotSettingsChanged() {
+ qDebug("BibleTime::slotSettingsChanged");
+ const QString language = CBTConfig::get
+ (CBTConfig::language);
+ //m_backend->booknameLanguage(language);
+ CPointers::backend()->booknameLanguage(language);
+// TODO: update the bookmarks after Bible bookname language has been changed
+// QTreeWidgetItemIterator it(m_mainIndex);
+// while (*it) {
+// CIndexItemBase* citem = dynamic_cast<CIndexItemBase*>(*it);
+// if (citem) {
+// citem->update();
+// }
+// ++it;
+// }
+
+ refreshDisplayWindows();
+ refreshProfileMenus();
+ qDebug("BibleTime::slotSettingsChanged");
+}
+
+/** Opens the sword setup dialog of BibleTime. */
+void BibleTime::slotSwordSetupDialog() {
+ //TODO: nonmodal dialog, memory management (one instance only!
+ //BtModuleManagerDialog *dlg = new BtModuleManagerDialog(this);
+ BtModuleManagerDialog* dlg = BtModuleManagerDialog::getInstance(this);
+ //disconnect first because it may be connected already
+ //QObject::disconnect(dlg, SIGNAL(swordSetupChanged()), this, SLOT(slotSwordSetupChanged()) );
+ //connect(dlg, SIGNAL(swordSetupChanged()), SLOT(slotSwordSetupChanged()) );
+
+ dlg->showNormal();
+ dlg->show();
+ dlg->raise();
+ dlg->activateWindow();
+}
+
+/** Is called when settings in the sword setup dialog were changed (ok or apply) */
+void BibleTime::slotSwordSetupChanged() {
+ /*
+ Refresh everything here what might have changed
+ these are the mainindex, the searchdialog, the displaywindows
+ But at first we have to reset the Sword backend to reload the modules
+
+ TODO: should bookshelf manager be updated?
+ Should there be different signals/slots for visual changes,
+ i.e. grouping/hiding?
+
+ */
+
+
+ //CPointers::deleteBackend();
+ //m_backend = new CSwordBackend();
+ //CPointers::setBackend(new CSwordBackend());
+ //CPointers::backend()->reloadModules();
+
+ //m_mainIndex->reloadSword();
+
+ // refresh display windows
+ //refreshDisplayWindows();
+}
+
+/** Is called just before the window menu is ahown. */
+void BibleTime::slotWindowMenuAboutToShow() {
+ Q_ASSERT(m_windowMenu);
+ if (!m_windowMenu) {
+ return;
+ }
+
+ if ( m_mdi->subWindowList().isEmpty() ) {
+ m_windowCascade_action->setEnabled(false);
+ m_windowTileVertical_action->setEnabled(false);
+ m_windowTileHorizontal_action->setEnabled(false);
+ m_windowCloseAll_action->setEnabled(false);
+ }
+ else if (m_mdi->subWindowList().count() == 1) {
+ m_windowTileVertical_action->setEnabled( false );
+ m_windowTileHorizontal_action->setEnabled( false );
+ m_windowCascade_action->setEnabled( false );
+ m_windowCloseAll_action->setEnabled( true );
+ // m_windowMenu->insertSeparator();
+ }
+ else {
+ slotUpdateWindowArrangementActions(0); //update the window tile/cascade states
+ m_windowCloseAll_action->setEnabled( true );
+ }
+
+ QList<QAction*>::iterator end = m_windowOpenWindowsList.end();
+ for (QList<QAction*>::iterator it = m_windowOpenWindowsList.begin(); it != end; ++it ) {
+ //(*it)->unplugAll(); //see kde porting doc
+ foreach (QWidget *w, (*it)->associatedWidgets() ) {
+ w->removeAction(*it);
+ }
+ }
+
+ //m_windowOpenWindowsList.setAutoDelete(true);
+ qDeleteAll(m_windowOpenWindowsList);
+ m_windowOpenWindowsList.clear();
+
+// if (!m_windowActionCollection) {
+// m_windowActionCollection = new KActionCollection(this, KComponentData());
+// }
+
+// QList<QWidget*> windows = m_mdi->windowList();
+// const int count = windows.count();
+// for ( int i = 0; i < count; ++i ) {
+// QWidget* w = windows.at(i);
+// Q_ASSERT(w);
+//
+// KUserDataAction* action = new KUserDataAction(w->windowTitle(), KShortcut(), this, SLOT(slotWindowMenuActivated()), m_windowActionCollection);
+// Q_ASSERT(action);
+// action->setUserData(w);
+//
+// m_windowOpenWindowsList.append(action);
+// action->setChecked( w == m_mdi->activeWindow() );
+// m_windowMenu->addAction(action);
+// }
+}
+
+/** This slot is connected with the windowAutoTile_action object */
+void BibleTime::slotUpdateWindowArrangementActions( QAction* clickedAction ) {
+ /* If a toggle action was clicked we see if it checked ot unchecked and
+ * enable/disable the simple cascade and tile options accordingly
+ */
+ m_windowTileVertical_action->setEnabled( m_windowManualMode_action->isChecked() );
+ m_windowTileHorizontal_action->setEnabled( m_windowManualMode_action->isChecked() );
+ m_windowCascade_action->setEnabled( m_windowManualMode_action->isChecked() );
+
+ if (clickedAction) {
+ m_windowManualMode_action->setEnabled(
+ m_windowManualMode_action != clickedAction
+ && m_windowTileHorizontal_action != clickedAction
+ && m_windowTileVertical_action != clickedAction
+ && m_windowCascade_action != clickedAction
+ );
+ m_windowAutoTileVertical_action->setEnabled( m_windowAutoTileVertical_action != clickedAction );
+ m_windowAutoTileHorizontal_action->setEnabled( m_windowAutoTileHorizontal_action != clickedAction );
+ m_windowAutoCascade_action->setEnabled( m_windowAutoCascade_action != clickedAction );
+ }
+
+ if (clickedAction == m_windowManualMode_action) {
+ m_windowAutoTileVertical_action->setChecked(false);
+ m_windowAutoTileHorizontal_action->setChecked(false);
+ m_windowAutoCascade_action->setChecked(false);
+
+ m_mdi->setMDIArrangementMode( CMDIArea::ArrangementModeManual );
+ }
+ else if (clickedAction == m_windowAutoTileVertical_action) {
+ m_windowManualMode_action->setChecked(false);
+ m_windowAutoTileHorizontal_action->setChecked(false);
+ m_windowAutoCascade_action->setChecked(false);
+
+ m_mdi->setMDIArrangementMode( CMDIArea::ArrangementModeTileVertical );
+ }
+ else if (clickedAction == m_windowAutoTileHorizontal_action) {
+ m_windowManualMode_action->setChecked(false);
+ m_windowAutoTileVertical_action->setChecked(false);
+ m_windowAutoCascade_action->setChecked(false);
+
+ m_mdi->setMDIArrangementMode( CMDIArea::ArrangementModeTileHorizontal );
+ }
+ else if (clickedAction == m_windowAutoCascade_action) {
+ m_windowManualMode_action->setChecked(false);
+ m_windowAutoTileHorizontal_action->setChecked(false);
+ m_windowAutoTileVertical_action->setChecked(false);
+
+ m_mdi->setMDIArrangementMode( CMDIArea::ArrangementModeCascade );
+ }
+ else if (clickedAction == m_windowCascade_action) {
+ m_mdi->setMDIArrangementMode( CMDIArea::ArrangementModeManual );
+ m_mdi->myCascade();
+ }
+ else if (clickedAction == m_windowTileVertical_action) {
+ m_mdi->setMDIArrangementMode( CMDIArea::ArrangementModeManual );
+ m_mdi->myTileVertical();
+ }
+ else if (clickedAction == m_windowTileHorizontal_action) {
+ m_mdi->setMDIArrangementMode( CMDIArea::ArrangementModeManual );
+ m_mdi->myTileHorizontal();
+ }
+}
+
+void BibleTime::slotManualArrangementMode() {
+ slotUpdateWindowArrangementActions( m_windowManualMode_action );
+}
+
+/** This slot is connected with the windowAutoTile_action object */
+void BibleTime::slotAutoTileHorizontal() {
+ slotUpdateWindowArrangementActions( m_windowAutoTileHorizontal_action );
+}
+
+/** This slot is connected with the windowAutoTile_action object */
+void BibleTime::slotAutoTileVertical() {
+ slotUpdateWindowArrangementActions( m_windowAutoTileVertical_action );
+}
+
+void BibleTime::slotCascade() {
+ slotUpdateWindowArrangementActions( m_windowCascade_action );
+}
+
+void BibleTime::slotTileVertical() {
+ slotUpdateWindowArrangementActions( m_windowTileVertical_action );
+}
+
+void BibleTime::slotTileHorizontal() {
+ slotUpdateWindowArrangementActions( m_windowTileHorizontal_action );
+}
+
+/** This slot is connected with the windowAutoCascade_action object */
+void BibleTime::slotAutoCascade() {
+ slotUpdateWindowArrangementActions( m_windowAutoCascade_action );
+}
+
+void BibleTime::slotWindowMenuActivated() {
+ if (!m_windowMenu) {
+ return;
+ }
+
+/* const KUserDataAction* action = dynamic_cast<const KUserDataAction*>(sender());
+ Q_ASSERT(action);
+ if (action) {
+ QWidget* const window = action->getUserData();
+ Q_ASSERT(window);
+ if ( window ) {
+ window->setFocus();
+ }
+ }*/
+}
+
+/** Shows/hides the toolbar */
+void BibleTime::slotToggleToolbar() {
+ Q_ASSERT(m_mainToolBar);
+ if (m_viewToolbar_action->isChecked()) {
+ m_mainToolBar->show();
+ }
+ else {
+ m_mainToolBar->hide();
+ }
+}
+
+void BibleTime::slotSearchModules() {
+ //get the modules of the open windows
+ QList<CSwordModuleInfo*> modules;
+
+ foreach(QMdiSubWindow* subWindow, m_mdi->subWindowList()){
+ if (CDisplayWindow* w = dynamic_cast<CDisplayWindow*>(subWindow->widget())) {
+ modules << w->modules();
+ }
+ }
+ Search::CSearchDialog::openDialog(modules, QString::null);
+}
+
+/* Search default Bible slot
+ * Call CSearchDialog::openDialog with only the default bible module
+ */
+void BibleTime::slotSearchDefaultBible() {
+ QList<CSwordModuleInfo*> module;
+ CSwordModuleInfo* bible = CBTConfig::get(CBTConfig::standardBible);
+ if (bible) {
+ module.append(bible);
+ }
+ Search::CSearchDialog::openDialog(module, QString::null);
+}
+
+void BibleTime::openOnlineHelp_Handbook()
+{
+ QString urlPath = "file://" + util::filesystem::DirectoryUtil::getHandbookDir().canonicalPath() +"/index.html";
+ QDesktopServices::openUrl(QUrl(urlPath));
+}
+
+void BibleTime::openOnlineHelp_Howto()
+{
+ QString urlPath = "file://" + util::filesystem::DirectoryUtil::getHowtoDir().canonicalPath() +"/index.html";
+ QDesktopServices::openUrl(QUrl(urlPath));
+}
+
+void BibleTime::slotOpenAboutDialog()
+{
+ BtAboutDialog* dlg = new BtAboutDialog(this);
+ dlg->show();
+}
+
+/** Saves the current settings into the currently activated profile. */
+void BibleTime::saveProfile(QAction* action) {
+ m_mdi->setUpdatesEnabled(false);
+
+ const QString profileName = action->text().remove("&");
+ CProfile* p = m_profileMgr.profile( profileName );
+ Q_ASSERT(p);
+ if ( p ) {
+ saveProfile(p);
+ }
+
+ m_mdi->setUpdatesEnabled(true);
+}
+
+void BibleTime::saveProfile(CProfile* profile) {
+ if (!profile) {
+ return;
+ }
+ //save mainwindow settings
+ storeProfileSettings(profile);
+
+ QList<CProfileWindow*> profileWindows;
+ foreach (QMdiSubWindow* w, m_mdi->subWindowList()) {
+ CDisplayWindow* displayWindow = dynamic_cast<CDisplayWindow*>(w->widget());
+ if (!displayWindow) {
+ continue;
+ }
+
+ CProfileWindow* profileWindow = new CProfileWindow();
+ displayWindow->storeProfileSettings(profileWindow);
+ profileWindows.append(profileWindow);
+ }
+ profile->save(profileWindows);
+
+ //clean up memory - delete all created profile windows
+ //profileWindows.setAutoDelete(true);
+ qDeleteAll(profileWindows);
+ profileWindows.clear();
+}
+
+void BibleTime::loadProfile(QAction* action) {
+ const QString profileName = action->text().remove("&");
+ CProfile* p = m_profileMgr.profile( profileName );
+ Q_ASSERT(p);
+ if ( p ) {
+ m_mdi->deleteAll();
+ loadProfile(p);
+ }
+}
+
+void BibleTime::loadProfile(CProfile* p) {
+ if (!p) return;
+
+ QList<CProfileWindow*> windows = p->load();
+
+ m_mdi->setUpdatesEnabled(false);//don't auto tile or auto cascade, this would mess up everything!!
+
+ //load mainwindow setttings
+ applyProfileSettings(p);
+
+ QWidget* focusWindow = 0;
+
+ // for (CProfileWindow* w = windows.last(); w; w = windows.prev()) { //from the last one to make sure the order is right in the mdi area
+ foreach (CProfileWindow* w, windows) {
+ const QString key = w->key();
+ QStringList usedModules = w->modules();
+
+ QList<CSwordModuleInfo*> modules;
+ for ( QStringList::Iterator it = usedModules.begin(); it != usedModules.end(); ++it ) {
+ if (CSwordModuleInfo* m = CPointers::backend()->findModuleByName(*it)) {
+ modules.append(m);
+ }
+ }
+ if (!modules.count()) { //are the modules still installed? If not continue wih next session window
+ continue;
+ }
+
+ //is w->isWriteWindow is false we create a write window, otherwise a read window
+ CDisplayWindow* displayWindow = 0;
+ if (w->writeWindowType() > 0) { //create a write window
+ displayWindow = createWriteDisplayWindow(modules.first(), key, CDisplayWindow::WriteWindowType(w->writeWindowType()) );
+ }
+ else { //create a read window
+ displayWindow = createReadDisplayWindow(modules, key);
+ }
+
+ if (displayWindow) { //if a window was created initialize it.
+ if (w->hasFocus()) {
+ focusWindow = displayWindow;
+ }
+
+ displayWindow->applyProfileSettings(w);
+ }
+ }
+
+ m_mdi->setUpdatesEnabled(true);
+ m_mdi->triggerWindowUpdate();
+
+ if (focusWindow) {
+ focusWindow->setFocus();
+ }
+}
+
+void BibleTime::deleteProfile(QAction* action) {
+ //HACK: work around the inserted & char by KPopupMenu
+ const QString profileName = action->text().remove("&");
+ CProfile* p = m_profileMgr.profile( profileName );
+ Q_ASSERT(p);
+ if ( p ) m_profileMgr.remove(p);
+ refreshProfileMenus();
+}
+
+void BibleTime::toggleFullscreen() {
+ m_windowFullscreen_action->isChecked() ? showFullScreen() : showNormal();
+ m_mdi->triggerWindowUpdate();
+}
+
+/** Saves current settings into a new profile. */
+void BibleTime::saveToNewProfile() {
+ bool ok = false;
+ const QString name = QInputDialog::getText(this, tr("New Session"), tr("Please enter a name for the new session."), QLineEdit::Normal, QString::null, &ok);
+ if (ok && !name.isEmpty()) {
+ CProfile* profile = m_profileMgr.create(name);
+ saveProfile(profile);
+ }
+ refreshProfileMenus();
+}
+
+/** Slot to refresh the save profile and load profile menus. */
+void BibleTime::refreshProfileMenus() {
+ m_windowSaveProfileMenu->clear();
+ m_windowLoadProfileMenu->clear();
+ m_windowDeleteProfileMenu->clear();
+
+ //refresh the load, save and delete profile menus
+ m_profileMgr.refresh();
+ QList<CProfile*> profiles = m_profileMgr.profiles();
+
+ const bool enableActions = bool(profiles.count() != 0);
+ m_windowSaveProfileMenu->setEnabled(enableActions);
+ m_windowLoadProfileMenu->setEnabled(enableActions);
+ m_windowDeleteProfileMenu->setEnabled(enableActions);
+
+ foreach (CProfile* p, profiles) {
+ m_windowSaveProfileMenu->addAction(p->name());
+ m_windowLoadProfileMenu->addAction(p->name());
+ m_windowDeleteProfileMenu->addAction(p->name());
+ }
+}
diff --git a/src/bibletimeapp.cpp b/src/bibletimeapp.cpp
new file mode 100644
index 0000000..13451fc
--- /dev/null
+++ b/src/bibletimeapp.cpp
@@ -0,0 +1,43 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "bibletimeapp.h"
+#include "backend/config/cbtconfig.h"
+#include "util/cresmgr.h"
+
+//KDE includes
+//#include <dcopclient.h> #TODO: USE DBUS INSTEAD OF DCOP
+
+BibleTimeApp::BibleTimeApp( int & argc, char ** argv ) : QApplication(argc, argv)
+{
+// initDCOP();
+ CResMgr::init_tr();
+}
+
+BibleTimeApp::~BibleTimeApp() {
+
+ //we can set this safely now because we close now (hopyfully without crash)
+ CBTConfig::set(CBTConfig::crashedLastTime, false);
+ CBTConfig::set(CBTConfig::crashedTwoTimes, false);
+
+ deleteDisplayTemplateMgr();
+ deleteLanguageMgr();
+ deleteBackend();
+}
+
+/*
+void BibleTimeApp::initDCOP() {
+ const bool dcopOk = dcopClient()->attach();
+ Q_ASSERT(dcopOk);
+ if (dcopOk) {
+ const Q3CString appId = dcopClient()->registerAs(kapp->name(), false);
+ // dcopClient()->setDefaultObject("BibleTimeInterface");
+ }
+}
+*/
diff --git a/src/bibletimeapp.h b/src/bibletimeapp.h
new file mode 100644
index 0000000..b4036a3
--- /dev/null
+++ b/src/bibletimeapp.h
@@ -0,0 +1,30 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BIBLETIMEAPP_H
+#define BIBLETIMEAPP_H
+
+//BibleTime
+#include "util/cpointers.h"
+
+#include <QApplication>
+
+/** The BibleTimeApp class is used to clean up all instances of the backend and to delete all created module objects.
+ * @author The BibleTime team
+ */
+class BibleTimeApp : public QApplication, public CPointers {
+public:
+ BibleTimeApp( int & argc, char ** argv );
+ virtual ~BibleTimeApp();
+
+protected:
+// void initDCOP();
+};
+
+#endif
diff --git a/src/display-templates/Blue.tmpl b/src/display-templates/Blue.tmpl
new file mode 100644
index 0000000..db5844f
--- /dev/null
+++ b/src/display-templates/Blue.tmpl
@@ -0,0 +1,338 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>#TITLE#</title>
+ <meta name="GENERATOR" content="BibleTime - www.bibletime.info" />
+ <meta name="AUTHOR" content="BibleTime - www.bibletime.info" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+
+ <style type="text/css">
+ /* <![CDATA[ */
+#LANG_CSS#
+
+#content {
+ margin:10px;
+}
+#content > table {
+ margin: 0;
+ padding: 0;
+ border-spacing:10px;
+}
+#content > table th {
+ padding: 0 0 2px 0;
+ text-align: center;
+ font-weight: bold;
+ font-size: 110%;
+ border-bottom: 1px dotted #7B7B7B;
+}
+
+a {
+ text-decoration:none;
+ font-weight:normal;
+ color: #7B7B7B;
+ padding:0 2px;
+}
+a:hover {
+ text-decoration:none;
+ color: #0000FF;
+ padding:0 2px;
+}
+
+
+/* Settings which apply to all entries in all modules */
+.entry {
+ padding: 2px;
+ /*vertical-align: middle;*/
+ text-align: justify;
+}
+td.entry, td.currententry {
+ vertical-align: top;
+ text-align: justify !important;
+}
+#printer .entry {
+ font-size: 90%;
+ text-align: left;
+}
+.entry[dir=rtl] {
+ text-align: right !important;
+}
+#printer .entry[dir=rtl] {
+ text-align:right !important;
+}
+
+/* Keep the values the same as in .entry (take the border into account!) */
+.currententry {
+ padding: 2px;
+ /*vertical-align: middle;*/
+ text-align: justify;
+ background-color: #E6E4FF;
+}
+.currententry[dir=rtl] {
+ text-align:right !important;
+}
+div.currententry {
+}
+span.currententry {
+ background-color: #EDEFFF !important;
+}
+
+/* Space between the columns of modules displayed side by side */
+td.entry + td.entry {
+ margin-left: 5px;
+}
+
+/* Several additional settings for display of modules*/
+#bible div.currententry, #bible td.currententry {
+ border: 1px solid #B7B7B7;
+ padding: 2px;
+}
+
+
+/*Same for books!*/
+#book div.currententry, #book td.currententry {
+ border: 1px solid #B7B7B7;
+ padding: 2px;
+}
+#book .entryname + .entry {
+ margin-top:2px;
+ padding-top:1px;
+}
+/* To remove the gap between the entrynam and the entry's content*/
+#book .entry > *, #book .currententry > * {
+ margin-top:0px;
+ padding-top:0px;
+}
+
+.entryname {
+ font-size:80%;
+ padding:0 2px 0 0;
+ vertical-align:super;
+}
+.entry[dir=rtl] .entryname, .currententry[dir=rtl] .entryname {
+ padding: 0 0 0 2px;
+ font-size: 80%;
+ vertical-align: super;
+}
+.entryname a, #printer .entryname {
+}
+
+#printer .entry .entry, #printer .entry .sectiontitle , #printer .entry .booktitle {
+ padding-top: 0.05em;
+ margin-left: 10px;
+}
+
+.footnote {
+ vertical-align:super;
+ font-weight: normal;
+ color: blue;
+ font-size: 80%;
+ cursor: help;
+}
+
+.footnote:before { content:"("; }
+.footnote:after { content:")"; }
+
+.footnotepre {
+ font-style: italic;
+}
+
+
+.crossreference {
+ font-size: 80%;
+ color: blue;
+}
+#bible .crossreference:before { content:" ["; }
+#bible .crossreference:after { content:"]"; }
+
+.crossreference a {
+ color: blue;
+}
+.crossreference a:hover {
+ color: blue;
+}
+
+.alternative {}
+.alternative:before { content:"'"attr(alternative); }
+.alternative:after{ content:"'";}
+
+.abbreviation {
+
+}
+
+.sectiontitle {
+ font-weight: bold;
+ font-size: 110%;
+}
+#printer .sectiontitle {
+ font-weight: bold;
+ font-size: 100%;
+}
+* + .sectiontitle {
+ margin-top:15px;
+}
+
+.booktitle {
+ font-weight: bold;
+ font-size: 120%;
+ font-variant: small-caps;
+}
+#printer .booktitle {
+ font-weight: bold;
+ font-size: 120%;
+ font-variant: small-caps;
+}
+.foreign {
+}
+.jesuswords {
+ color:#9C2323;
+}
+
+.introduction {
+ font-size:80%;
+ text-align:justify;
+}
+
+.quotation {
+}
+.poetry {
+}
+.sup {
+ vertical-align: super;
+}
+.sub {
+ vertical-align: sub;
+}
+.right {
+ text-align: right;
+}
+.center {
+ text-align: center;
+}
+
+.bold {
+ font-weight:bold;
+}
+.illuminated {
+}
+.italic {
+ font-style:italic;
+}
+.line-through {
+}
+.normal {
+}
+.small-caps{
+}
+.underline {
+ font-style:underline;
+}
+
+.inscription {
+}
+.mentioned {
+}
+.name > .geographic {
+}
+.name > .holiday {
+}
+.name > .nonhuman {
+}
+.name > .person {
+}
+.name > .ritual {
+}
+.name > .divine {
+ font-variant: small-caps;
+}
+
+.transchange {
+ font-style:italic;
+}
+.transchange > .added {
+ background-color:inherit;
+}
+.transchange > .amplified {
+}
+.transchange > .changed {
+}
+.transchange > .deleted {
+}
+.transchange > .moved {
+}
+.transchange > .tenseChange {
+}
+
+.morphSegmentation {
+ border-right: 2px solid gray;
+}
+
+#infodisplay {
+ margin:0;
+ padding:0;
+}
+
+#infodisplay .footnoteinfo h3, #infodisplay .strongsinfo h3, #infodisplay .morphinfo h3, #infodisplay .translationinfo h3, #infodisplay .crossrefinfo h3 {
+ padding:4px 4px 2px 0;
+ color:darkGray;
+ font-weight:bold;
+ border-bottom:1px solid gray;
+ font-size:90%;
+ text-align: right;
+}
+
+#infodisplay > p, #infodisplay * > p,
+#infodisplay > .para, #infodisplay * > .para
+{ /* We only format the first p child in a special way */
+ font-size:95%;
+ text-align:justify !important;
+ color:black;
+ margin:0px;
+ padding:0px;
+}
+
+/*Required for cross references*/
+#infodisplay .entry {
+ padding:2px;
+ text-align:justify !important;
+ font-size:95%;
+ margin-bottom:10px;
+ margin-left:15px;
+}
+#infodisplay .entry[dir=rtl] {
+ text-align: right !important;
+}
+#infodisplay .entry .entry { /*No smaller font size for nested entries*/
+ font-size:100%;
+ margin:0px;
+}
+#infodisplay .entry .entry[dir=rtl] { /*No smaller font size for nested entries*/
+ text-align: right !important;
+}
+#infodisplay .entryname {
+ padding:2px;
+ margin:0px;
+ text-align:left !important;
+ font-weight:bold;
+ font-size:100%;
+}
+
+#infodisplay .rangeheading {
+ color:black;
+ font-weight:bold;
+ margin-left:-10px;
+}
+
+#printer .rangeheading {
+ border-bottom:1px solid black;
+ color:black;
+}
+
+ /* ]]> */
+ </style>
+</head>
+
+<body id="#DISPLAYTYPE#">
+ <div id="content" lang="#LANG_ABBREV#" xml:lang="#LANG_ABBREV#" dir="#PAGE_DIRECTION#">#CONTENT#</div>
+</body>
+</html> \ No newline at end of file
diff --git a/src/display-templates/Crazy.tmpl b/src/display-templates/Crazy.tmpl
new file mode 100644
index 0000000..c0e9b63
--- /dev/null
+++ b/src/display-templates/Crazy.tmpl
@@ -0,0 +1,311 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <!--TODO: This needs a better title than "Crazy"-->
+ <title>#TITLE#</title>
+ <meta name="GENERATOR" content="BibleTime - www.bibletime.info" />
+ <meta name="AUTHOR" content="BibleTime - www.bibletime.info" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+
+ <style type="text/css">
+/* <![CDATA[ */
+body {
+ margin:0px;
+ padding:0;
+ padding:1em;
+}
+
+/* content wraps all of the displayed elements */
+#content {
+ margin:0px;
+ padding:0px;
+ font-size:12pt;
+ text-align:justify;
+}
+
+/* The table contains the Bible verses, each verse on an own row, each Bible module in an own column */
+#content > table {
+ margin:0;
+ padding:3px;
+ border-spacing:0;
+ vertical-align:top;
+ text-align:justify;
+}
+/* The heading contains the name of the module and may contain additional information like the display keys */
+#content > table th {
+ text-shadow:black 1px 1px 3px;
+ font-size:1.3em;
+ background-color:#F0F0F0;
+ padding:8px;
+ border-bottom:1px solid black;
+}
+
+#content tr:nth-child(odd) { background-color: white; }
+#content tr:nth-child(even) { background-color: #EDEDED; }
+
+/* The a links are the normal HTML hyperlinks. Links without a class attribute are hyperlinks into the web */
+a { color:#FF0004; padding:0; }
+a:hover { }
+
+/* An entry is the generic element used for all content items.
+ In Bibles an entry contains a verse, in commentaries the comment to a verse range,
+ in lexicons an simple item and in book the text of an item with other .entry elements as childs.
+
+ If just one module is chosen, all entries are put together in one sourrounding table column. In this case the elements div and span may have the class "entry". If it's a div each entry should be on it's own line. span.entry should not add a linebreak.
+
+ If more than one module (Bibles) was chosen, the entry class applies to "td" elements, one column for a verse
+ */
+.entry {
+ padding:0.3em;
+}
+table .entry:nth-child(odd) {
+ border-left:10px solid #DEE6F6;
+}
+
+table .entry:nth-child(even) {
+ border-left:10px solid #E6EEFF;
+}
+
+#printer .entry { text-indent:15px; }
+/* Often needed to format BiDi text in the right way */
+/* .entry[dir=rtl] { text-align:right !important; } */b
+/* #printer .entry[dir=rtl] { } */
+
+/* Special formatting for the block element entries */
+div.entry, td.entry { }
+td.entry, td.currententry {
+ vertical-align:top;
+}
+
+/* Currententry is chosen when the entry should be highlighted as the current entry chosen by the user
+ currententry may apply to span, div, td (just like .entry)
+ */
+.currententry {
+ padding:0.3em;
+ line-height:1.6em;
+ background-color:#D3E5FF;
+ /*border: thin solid black;*/
+
+}
+
+table .currententry:nth-child(1) {
+ margin-left:0;
+ border-left:10px solid #99B4FF;
+ /*border-left:10px solid #F5FF6A;*/
+}
+/* .currententry[dir=rtl] { */
+/* } */
+div.currententry { }
+span.currententry { }
+
+/* You may use this to format the space between two columns */
+td.entry + td.entry {
+ margin:0;
+}
+
+/* Several additional settings for displaying Bible modules*/
+#bible div.entry {
+ border-left:10px solid white;
+}
+#bible div.entry[dir=rtl] {
+ border-left:none;
+ border-right:10px solid white;
+ text-align:right;
+}
+#bible div.currententry {
+ border-left:10px solid #99B4FF;
+}
+#bible div.currententry[dir=rtl] {
+ border-left:none;
+ border-right:10px solid #99B4FF;
+}
+#bible div.currententry, #bible td.currententry { }
+#bible td.currententry { }
+
+/* Same for books! */
+#book div.currententry, #book td.currententry { }
+#book .entryname + .entry { }
+/* To remove the gap between the entryname and the entry's content*/
+#book .entry > *, #book .currententry > * { }
+
+/* An entryname is embedded in an .entry tag and contains the name of the key, which belongs to the text of the .entry */
+.entryname { size:60%; vertical-align:super;}
+.entryname a { text-decoration:none !important; color:#8F2627 !important; font-style:italic; padding:0; }
+
+.entry[dir=rtl] .entryname, .currententry[dir=rtl] .entryname { }
+.entryname a, #printer .entryname { }
+/* As you can see #printer is used to format pages which are send to the printer. Printer pages should be clean and easy to read */
+#printer .entry .entry, #printer .entry .sectiontitle , #printer .entry .booktitle { }
+
+/* Footnote formatting options */
+/* A footnote is displayed as an asterisk or another small character. You can set the colors, font-size, etc. for the footnote. */
+.footnote { color:#8F2627; vertical-align:super; font-size:70%;}
+/* You may use this to add sourrounding brackets in Bible modules. To do this the content command of CSS */
+#bible .footnote:before { content:" ["; color:#8F2627; }
+#bible .footnote:after { content:"]"; color:#8F2627; }
+
+/* Crossreferences. The same as footnotes */
+.crossreference { color:#8f2627;}
+#bible .crossreference:before { content:" {" }
+#bible .crossreference:after { content:"}" }
+
+/*Keep in mind that for cross references it is not enough to
+*set only the cross reference colour, you must also set the
+*cross reference anchor marker with .crossreference a
+*This way both the non linked and linked text will show
+*as desired. Additionally, you can have seperate formatting
+*for linked and non linked text in the cross reference*/
+.crossreference a {
+ color:#8f2627;
+ /*Get rid of underlines on the notes when not hovered*/
+ text-decoration: none;
+}
+.crossreference a:hover {}
+
+/* Alternative reading as defined in the OSIS specs. The information about the alternative text is displayed in the info display. It's
+often a good idea to format this the same as footnotes
+The text which is the alternative of the displayed text is available in the attribute "alternative"
+so something like .alternative:before { content:"'"attr(alternative); } is possible
+*/
+.alternative {}
+.alternative:before { }
+.alternative:after { }
+
+/* An abbreviation. */
+.abbreviation { }
+
+/* A title within the text. This is the formatting which applies to a title of a section, as you can find them in Bibles */
+.sectiontitle {
+ padding:0.3em;
+ /*text-shadow:gray 0px 0px 3px;*/
+ font-size:1.3em;
+ font-weight:bold;
+ text-transform:uppercase;
+ padding-bottom:2px;
+}
+#printer .sectiontitle { }
+/* You may want to format elements before section titles in a special way. */
+* + .sectiontitle { }
+
+/* The title of a book, e.g. "The gospel of Matthew" */
+.booktitle { }
+#printer .booktitle { }
+
+/* A foreign word */
+.foreign { }
+
+/* Words spoken by Jesus Christ */
+/*.jesuswords { color: red; }*/
+.jesuswords { color: #B60000; }
+
+/* An introduction to a module, book or chapter */
+.introduction { }
+/* A quotation without a special speaker */
+.quotation { }
+/* Poetry formatting */
+.poetry { }
+/* Text displayed above. It's like the sup tag in HTML */
+.sup { }
+/* Sub text, the opposite of .sup */
+.sub { }
+/* Display the text inside as right aligned text */
+.right { }
+/* Display as centered text */
+.center { }
+
+/* Visual attributes to the text */
+.bold {
+ font-weight: bold;
+}
+.illuminated { }
+.italic {
+ font-style: italic;
+}
+.line-through { }
+.normal { }
+.small-caps{ }
+.underline { }
+
+/* An inscription */
+.inscription { }
+
+.mentioned { }
+
+/* Special formatting rules for names, see the OSIS specs for detailed information */
+.name {}
+.name > .geographic { }
+.name > .holiday { }
+.name > .nonhuman { }
+.name > .person { }
+.name > .ritual { }
+.name > .divine { font-variant: small-caps; }
+
+/* Information added by the translator */
+.transchange {}
+.transchange > .added { }
+.transchange > .amplified {}
+.transchange > .changed { }
+.transchange > .deleted { }
+.transchange > .moved { }
+.transchange > .tenseChange { }
+
+/* Special text markup */
+/* Morph segmentation is a special feature for hebrew to markup the word divisions in the text */
+/* .morphSegmentation { border-left:1px solid red; } */
+.morphSegmentation + .morphSegmentation {
+ border-right: 1px red solid;
+}
+
+/* The formatting of all things displayed in the information window */
+#infodisplay {background:white; font-size:10pt; padding:5px; margin:0px;}
+
+/* The headings of a section, several sections may be displayed together at the same time */
+#infodisplay .footnoteinfo h3,
+#infodisplay .strongsinfo h3,
+#infodisplay .morphinfo h3,
+#infodisplay .translationinfo h3,
+#infodisplay .crossrefinfo h3 {
+ font-size:12pt;
+ font-weight:bold;
+ text-transform:uppercase;
+ text-align:right;
+ color:gray;
+ border-bottom:1px solid black;
+ padding:4px;
+}
+
+#infodisplay > p, #infodisplay * > p { /* We only format the first p child in a special way */
+ font-size:80%;
+}
+
+/*Required for cross references*/
+#infodisplay .entry {
+ font-size:80%;
+}
+#infodisplay .entry .entry { /* No smaller font size for nested entries */
+ font-size:100% !important;
+}
+#infodisplay .entryname {
+ font-weight:bold;
+}
+#infodisplay .rangeheading {
+ font-weight:bold;
+}
+
+#printer .rangeheading {}
+
+*[dir=rtl] { text-align:right !important; }
+
+/* Here's the marker for the language specific fotn information. BibleTime replaces this by the CSS for the fonts */
+#LANG_CSS#
+
+/* ]]> */
+ </style>
+</head>
+
+<!-- The display type may be bible, book, printer -->
+<body id="#DISPLAYTYPE#">
+ <div id="content" lang="#LANG_ABBREV#" xml:lang="#LANG_ABBREV#" dir="#PAGE_DIRECTION#">#CONTENT#</div>
+</body>
+</html> \ No newline at end of file
diff --git a/src/display-templates/Green.tmpl b/src/display-templates/Green.tmpl
new file mode 100644
index 0000000..4616030
--- /dev/null
+++ b/src/display-templates/Green.tmpl
@@ -0,0 +1,320 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>#TITLE#</title>
+ <meta name="GENERATOR" content="BibleTime - www.bibletime.info" />
+ <meta name="AUTHOR" content="BibleTime - www.bibletime.info" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+
+ <style type="text/css">
+ /* <![CDATA[ */
+
+#content {
+ margin:10px;
+}
+
+#content > table {
+ margin: 0;
+ padding: 0;
+ border-spacing:10px;
+ vertical-align:top;
+}
+
+#content > table th {
+ padding: 0 0 2px 0;
+ text-align: center;
+ font-weight: bold;
+ font-size: 110%;
+ border-bottom: 1px solid #6B6B6B;
+}
+
+a {
+ text-decoration:none;
+ font-weight:normal;
+ color: #3B11AE;
+ padding:0 2px;
+}
+a:hover {
+ color: #AE1518;
+ padding:0 2px;
+}
+
+
+/* Settings which apply to all entries in all modules */
+.entry {
+ padding: 3px;
+ vertical-align: middle;
+ text-align: justify;
+}
+#printer .entry {
+ font-size:90%;
+ text-align:left;
+}
+.entry[dir=rtl] {
+ text-align:right !important;
+}
+#printer .entry[dir=rtl] {
+ text-align:right !important;
+}
+td.entry, td.currententry {
+ vertical-align:top;
+}
+
+/* Keep the values the same as in .entry (take the border into account!) */
+.currententry {
+ padding:3px;
+ text-align:justify;
+}
+.currententry[dir=rtl] {
+ text-align:right !important;
+}
+div.currententry {
+}
+span.currententry {
+ background-color:#D4FFCB;
+}
+
+
+/*Space between the columns of modules displayed side by side*/
+td.entry + td.entry {
+ margin-left: 5px;
+}
+
+/* Several additional settings for display of modules*/
+#bible div.currententry, #bible td.currententry {
+ border:1px solid black;
+ padding:2px;
+ background-color:#F6FFF7;
+}
+#bible span.currententry {
+ background-color:#C8FFB6;
+}
+
+/*Same for books!*/
+#book div.currententry, #book td.currententry {
+ border:1px solid black;
+ background-color:#F6FFF7;
+}
+#book span.currententry {
+ background-color:#C8FFB6;
+}
+
+
+.entryname {
+ font-size:80%;
+ padding:0 2px 0 0;
+ vertical-align:super;
+}
+.entry[dir=rtl] .entryname, .currententry[dir=rtl] .entryname {
+ padding: 0 0 0 2px;
+ font-size: 80%;
+ vertical-align:super;
+}
+.entryname a, #printer .entryname {
+ vertical-align: middle
+}
+
+#printer .entry .entry, #printer .entry .sectiontitle , #printer .entry .booktitle {
+ padding-top: 0.05em;
+ margin-left: 10px;
+}
+
+.footnote {
+ vertical-align:super;
+ color: blue;
+ font-size: 70%;
+}
+.footnote:before { content:"("; }
+.footnote:after { content:")"; }
+
+.crossreference {
+ font-size: 80%;
+ /*vertical-align:middle;*/
+ color: blue;
+}
+
+.crossreference a {
+ font-size: 80%;
+ /*vertical-align:middle;*/
+ color: blue;
+}
+
+.crossreference a:hover {
+ font-size: 80%;
+ /*vertical-align:middle;*/
+ color: blue;
+}
+
+
+
+.sectiontitle {
+ font-weight: bold;
+ font-size: 110%;
+}
+#printer .sectiontitle {
+ font-weight: bold;
+ font-size: 100%;
+}
+* + .sectiontitle {
+ margin-top:15px;
+}
+
+.booktitle {
+ font-weight: bold;
+ font-size: 120%;
+ font-variant: small-caps;
+}
+#printer .booktitle {
+ font-weight: bold;
+ font-size: 120%;
+ font-variant: small-caps;
+}
+.foreign {
+}
+.jesuswords {
+ color:#9C2323;
+}
+
+.quotation {
+}
+.poetry {
+}
+.sup {
+ vertical-align: super;
+}
+.sub {
+ vertical-align: sub;
+}
+.right {
+ text-align: right;
+}
+.center {
+ text-align: center;
+}
+
+.bold {
+ font-weight:bold;
+}
+.illuminated {
+}
+.italic {
+ font-style:italic;
+}
+.line-through {
+}
+.normal {
+}
+.small-caps{
+}
+.underline {
+ font-style:underline;
+}
+
+.inscription {
+}
+.mentioned {
+}
+.name > .geographic {
+}
+.name > .holiday {
+}
+.name > .nonhuman {
+}
+.name > .person {
+}
+.name > .ritual {
+}
+.name > .divine {
+ font-variant: small-caps;
+}
+
+.transchange {
+ font-style:italic;
+}
+.transchange > .added {
+ background-color:inherit;
+}
+.transchange > .amplified {
+}
+.transchange > .changed {
+}
+.transchange > .deleted {
+}
+.transchange > .moved {
+}
+.transchange > .tenseChange {
+}
+
+.morphSegmentation {
+ border: 1px solid gray;
+ margin-top: 1px; /* Don`t let the boxes touch here, between the lines */
+ margin-left: -1px; /* But here, for better reading of the text,
+ this will only occur within a word consisting of several segments.*/
+ margin-right: 0px;
+}
+
+#infodisplay {
+ margin:0;
+ padding:0;
+ font-size:100%;
+}
+
+#infodisplay .footnoteinfo h3, #infodisplay .strongsinfo h3, #infodisplay .morphinfo h3, #infodisplay .translationinfo h3, #infodisplay .crossrefinfo h3 {
+ padding:4px 4px 2px 0;
+ color:darkGray;
+ font-weight:bold;
+ border-bottom:1px solid gray;
+ font-size:100%;
+ text-align:left !important;
+}
+
+#infodisplay > p, #infodisplay * > p { /* We only format the first p child in a special way */
+ font-size:100%;
+ text-align:justify;
+ color:black;
+ margin:0px;
+ padding:0px;
+}
+
+/*Required for cross references*/
+#infodisplay .entry {
+ padding:2px;
+ text-align:justify;
+ font-size:100%;
+ margin-bottom:10px;
+ margin-left:15px;
+}
+#infodisplay .entry .entry { /*No smaller font size for nested entries*/
+ font-size:100%;
+ margin:0px;
+}
+#infodisplay .entryname {
+ padding:2px;
+ margin:0px;
+ text-align:left;
+ font-weight:bold;
+ font-size:100%;
+}
+
+#infodisplay .rangeheading {
+ color:black;
+ font-weight:bold;
+ margin-left:-10px;
+}
+
+#printer .rangeheading {
+ border-bottom:1px solid black;
+ color:black;
+}
+
+#LANG_CSS#
+
+ /* ]]> */
+ </style>
+</head>
+
+<body id="#DISPLAYTYPE#">
+ <div id="content" lang="#LANG_ABBREV#" xml:lang="#LANG_ABBREV#" dir="#PAGE_DIRECTION#">#CONTENT#</div>
+</body>
+</html> \ No newline at end of file
diff --git a/src/display-templates/HighContrast.tmpl b/src/display-templates/HighContrast.tmpl
new file mode 100644
index 0000000..4baf59d
--- /dev/null
+++ b/src/display-templates/HighContrast.tmpl
@@ -0,0 +1,332 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>#TITLE#</title>
+ <meta name="GENERATOR" content="BibleTime - www.bibletime.info" />
+ <meta name="AUTHOR" content="BibleTime - www.bibletime.info" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+
+ <style type="text/css">
+ /* <![CDATA[ */
+
+* {
+ /* To work around a KDE 3.2 bug / problem */
+ /* background-color:white; #this seems to break*/
+}
+
+#content {
+ background-color:white;
+ margin:10px;
+}
+#content > table {
+ margin: 0;
+ padding: 0;
+ border-spacing:10px;
+ vertical-align:top;
+}
+#content > table th {
+ padding: 0 0 2px 0;
+ text-align: center;
+ /*font-weight: bold;*/
+ font-size: 110%;
+ border-bottom: 1px solid #6B6B6B;
+}
+
+a {
+ text-decoration:none;
+ font-weight:normal;
+ /*color: #F98100;*/
+ padding:1px;
+}
+a:hover {
+ color: #FF0000;
+ padding:1px;
+ text-decoration:underline;
+}
+
+/* Settings which apply to all entries in all modules */
+.entry {
+ padding: 2px;
+ /*vertical-align: top;*/
+ text-align: justify;
+}
+#printer .entry {
+ font-size: 90%;
+ text-align: left;
+}
+.entry[dir=rtl],#printer .entry[dir=rtl] {
+ text-align: right;
+}
+div.entry, td.entry, td.currententry {
+ vertical-align:top;
+}
+
+/* Keep the values the same as in .entry (take the border into account!) */
+.currententry {
+ padding: 2px;
+ text-align: justify;
+ /*color:white;*/
+ /*The background colour of selected text as of kde 3.5.2*/
+ background-color: #A5A5FF;
+}
+.currententry[dir=rtl] {
+ text-align: right;
+}
+div.currententry {
+}
+span.currententry {
+
+}
+
+
+/*Space between the columns of modules displayed side by side*/
+td.entry + td.entry {
+ margin-left: 5px;
+}
+
+/* Several additional settings for display of modules*/
+#bible div.currententry, #bible td.currententry {
+ /*border: 1px solid black;*/
+ padding: 4px;
+}
+#bible span.currententry {
+}
+
+/*Same for books!*/
+#book div.currententry, #book td.currententry {
+ border: 1px solid black;
+}
+#book span.currententry {
+}
+
+.entryname {
+ font-size:70%;
+ padding:0 1px 0 0;
+ vertical-align:top;
+ /*color: #F98100;*/
+ color: black;
+ /*font-style: italic;*/
+}
+.entry[dir=rtl] .entryname, .currententry[dir=rtl] .entryname {
+ padding:0 0 0 1px;
+ font-size:60%;
+ /*vertical-align:top; */
+}
+.entryname a, #printer .entryname {
+ vertical-align: top;
+ font-size: 100%;
+ font-weight: bold;
+ color: black;
+}
+
+#printer .entry .entry, #printer .entry .sectiontitle , #printer .entry .booktitle {
+ padding-top:0.05em;
+ margin-left:10px;
+}
+
+.footnote {
+ vertical-align:super;
+ font-weight:bold;
+ /*color: #00B7FF;*/ /*This one is kind of blinding on white*/
+ /*color: #F98100;*/
+ font-size:80%;
+ color: black;
+}
+
+
+.footnote:before {
+ content: "(";
+}
+
+.footnote:after {
+ content: ")";
+}
+
+.crossreference {
+ font-size: 80%;
+ /*vertical-align:middle;*/
+ /*color: blue;*/
+ /*color: #F98100;*/
+}
+
+.crossreference:before {
+ content: "[";
+}
+
+.crosreference:after {
+ content: "]";
+}
+
+.sectiontitle {
+ font-weight: bold;
+ font-size: 110%;
+}
+#printer .sectiontitle {
+ font-weight: bold;
+ font-size: 100%;
+}
+* + .sectiontitle {
+ margin-top:15px;
+}
+
+.booktitle {
+ font-weight: bold;
+ font-size: 120%;
+ font-variant: small-caps;
+}
+#printer .booktitle {
+ font-weight: bold;
+ font-size: 120%;
+ font-variant: small-caps;
+}
+.foreign {
+}
+.jesuswords {
+ /*color:red;*/
+ /*color: #7500AC;*/
+ /*color: #F98100;*/
+ font-style:italic;
+ /*font-weight: bold;*/
+ font-size:0.9em;
+}
+
+.quotation {
+}
+.poetry {
+}
+.sup {
+ vertical-align: super;
+}
+.sub {
+ vertical-align: sub;
+}
+.right {
+ text-align: right;
+}
+.center {
+ text-align: center;
+}
+
+.bold {
+ font-weight:bold;
+}
+.illuminated {
+}
+.italic {
+ font-style:italic;
+}
+.line-through {
+}
+.normal {
+}
+.small-caps{
+}
+.underline {
+ font-style:underline;
+}
+
+.inscription {
+}
+.mentioned {
+}
+.name > .geographic {
+}
+.name > .holiday {
+}
+.name > .nonhuman {
+}
+.name > .person {
+}
+.name > .ritual {
+}
+.name > .divine {
+ font-variant: small-caps;
+}
+
+.transchange {
+ font-style:italic;
+}
+.transchange > .added {
+ background-color:inherit;
+}
+.transchange > .amplified {
+}
+.transchange > .changed {
+}
+.transchange > .deleted {
+}
+.transchange > .moved {
+}
+.transchange > .tenseChange {
+}
+
+.morphSegmentation {
+ border: 1px solid grey;
+ margin-top: 1px; /* Don`t let the boxes touch here, between the lines */
+ margin-left: -1px; /* But here, for better reading of the text,
+ this will only occur within a word consisting of several segments.*/
+ margin-right: 0px;
+}
+
+#infodisplay {
+ margin:0;
+ padding:0;
+}
+
+#infodisplay .footnoteinfo h3, #infodisplay .strongsinfo h3, #infodisplay .morphinfo h3, #infodisplay .translationinfo h3, #infodisplay .crossrefinfo h3 {
+ padding: 2px 0 0 0;
+ color: black;
+ font-weight: bold;
+ border-bottom: 1px solid black;
+ font-size: 90%;
+ margin: 0 0 3px 0;
+}
+
+#infodisplay > p { /* We only format the first p child in a special way */
+ font-size: 90%;
+ color: black;
+ margin: 0px;
+ padding: 0px;
+}
+
+/*Required for cross references*/
+#infodisplay .entry {
+ padding: 2px;
+ text-align: justify;
+ font-size: 80%;
+ margin: 0 0 10px 10px;
+}
+#infodisplay .entry .entry { /*No smaller font size for nested entries*/
+ font-size: 100%;
+ margin: 0px;
+}
+#infodisplay .entryname {
+ padding: 2px;
+ margin: 0px;
+ text-align: left;
+ font-weight: bold;
+ font-size: 90%;
+}
+
+#infodisplay .rangeheading {
+ color: black;
+ font-weight: bold;
+ margin-left: -5px;
+}
+
+#printer .rangeheading {
+ border-bottom: 1px solid black;
+ color: black;
+}
+
+#LANG_CSS#
+
+ /* ]]> */
+ </style>
+</head>
+
+<body id="#DISPLAYTYPE#">
+ <div id="content" lang="#LANG_ABBREV#" xml:lang="#LANG_ABBREV#">#CONTENT#</div>
+</body>
+</html>
diff --git a/src/display-templates/Simple.tmpl b/src/display-templates/Simple.tmpl
new file mode 100644
index 0000000..9d9e6c8
--- /dev/null
+++ b/src/display-templates/Simple.tmpl
@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>#TITLE#</title>
+ <meta name="GENERATOR" content="BibleTime " VERSION "" />
+ <meta name="AUTHOR" content="BibleTime " VERSION "" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+
+ <style type="text/css">
+/* <![CDATA[ */
+body {
+ margin:5px;
+}
+#content {
+ background-color:white;
+}
+#content table {
+ margin:0;
+ padding:0;
+ border-spacing:10px;
+ border-collapse: collapse;
+ vertical-align: top;
+}
+#content table th {
+ padding: 0 0 2px 0;
+ text-align: center;
+ font-weight: bold;
+ font-size: 115%;
+}
+
+a {
+ text-decoration:none;
+ font-weight:normal;
+ color: blue;
+ padding:2px;
+}
+
+td.entry, div.entry {
+ padding: 5px;
+ vertical-align: top;
+}
+div.entry {
+ padding: 5px;
+}
+
+td.currententry, div.currententry {
+ padding: 5px;
+ vertical-align: top;
+ font-weight:bold;
+}
+td.entry + td.entry {
+ margin-left: 5px;
+}
+div.currententry {
+ font-weight:bold;
+ /*vertical-align: middle;*/
+ padding: 5px;
+}
+
+.footnote {
+ color: gray;
+}
+
+.strongnumber {
+ vertical-align: top;
+ font-size: 60%;
+ color: blue;
+}
+.morphcode {
+ vertical-align: top;
+ font-size: 60%;
+ color: blue;
+}
+.lemma {
+}
+
+.sectiontitle {
+ font-weight: bold;
+ font-size: 120%;
+}
+.entry + .sectiontitle {
+ margin-top:35px;
+ padding-top:35px;
+}
+
+.booktitle {
+ font-weight: bold;
+ font-size: 140%;
+}
+.foreign {
+}
+.jesuswords {
+ color: red;
+ font-size: 0.9em;
+}
+
+.name > .divine {
+ font-variant: small-caps;
+}
+
+.quotation {
+}
+.poetry {
+}
+.sup {
+ vertical-align: super;
+}
+.sub {
+ vertical-align: sub;
+}
+.right {
+ text-align: right;
+}
+.center {
+ text-align: center;
+}
+/*TODO: Think of something better here since this will get confusing*/
+/* on verses but, is needed for things inthe Mag/Info window*/
+.bold {
+ font-weight: bold;
+}
+.italic {
+ font-style: italic;
+}
+#LANG_CSS#
+/* ]]> */
+ </style>
+</head>
+
+<body>
+ <div id="content" lang="#LANG_ABBREV#" xml:lang="#LANG_ABBREV#" dir="#PAGE_DIRECTION#">#CONTENT#</div>
+</body>
+</html> \ No newline at end of file
diff --git a/src/display-templates/basic_template.txt b/src/display-templates/basic_template.txt
new file mode 100644
index 0000000..16ed394
--- /dev/null
+++ b/src/display-templates/basic_template.txt
@@ -0,0 +1,205 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>#TITLE#</title>
+ <meta name="GENERATOR" content="BibleTime - www.bibletime.info" />
+ <meta name="AUTHOR" content="BibleTime - www.bibletime.info" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+
+ <style type="text/css">
+/* <![CDATA[ */
+* {
+ background-color:inherit; /* To work around a KDE 3.2 bug / problem */
+}
+
+/* content wraps all of the displayed elements */
+#content { }
+/* The table contains the Bible verses, each verse on an own row, each Bible module in an own column */
+#content > table { }
+/* The heading contains the name of the module and may contain additional information like the display keys */
+#content > table th { }
+
+/* The a links are the normal HTML hyperlinks. Links without a class attribute are hyperlinks into the web */
+a { }
+a:hover { }
+
+/* An entry is the generic element used for all content items.
+ In Bibles an entry contains a verse, in commentaries the comment to a verse range,
+ in lexicons an simple item and in book the text of an item with other .entry elements as childs.
+
+ If just one module is chosen, all entries are put together in one sourrounding table column. In this case the elements div and span may have the class "entry". If it's a div each entry should be on it's own line. span.entry should not add a linebreak.
+
+ If more than one module (Bibles) was chosen, the entry class applies to "td" elements, one column for a verse
+ */
+.entry { }
+#printer .entry { }
+/* Often needed to format BiDi text in the right way */
+.entry[dir=rtl] { }
+#printer .entry[dir=rtl] { }
+/* Special formatting for the block element entries */
+div.entry, td.entry { }
+
+td.currententry { }
+
+/* Currententry is chosen when the entry should be highlighted as the current entry chosen by the user
+ currententry may apply to span, div, td (just like .entry)
+ */
+.currententry {
+}
+.currententry[dir=rtl] {
+}
+div.currententry { }
+span.currententry { }
+
+/* You may use this to format the space between two columns */
+td.entry + td.entry { }
+
+/* Several additional settings for displaying Bible modules*/
+#bible div.currententry, #bible td.currententry { }
+#bible td.currententry { }
+
+/*Same for books!*/
+#book div.currententry, #book td.currententry { }
+#book .entryname + .entry { }
+/* To remove the gap between the entryname and the entry's content*/
+#book .entry > *, #book .currententry > * { }
+
+/* An entryname is embedded in an .entry tag and contains the name of the key, which belongs to the text of the .entry */
+.entryname { }
+.entry[dir=rtl] .entryname, .currententry[dir=rtl] .entryname { }
+.entryname a, #printer .entryname { }
+/* As you can see #printer is used to format pages which are send to the printer. Printer pages should be clean and easy to read */
+#printer .entry .entry, #printer .entry .sectiontitle , #printer .entry .booktitle { }
+
+/* Footnote formatting options */
+/* A footnote is displayed as an asterisk or another small character. You can set the colors, font-size, etc. for the footnote. */
+.footnote { }
+/* You may use this to add sourrounding brackets in Bible modules. To do this the content command of CSS */
+#bible .footnote:before { }
+#bible .footnote:after { }
+
+/* Crossreferences. The same as footnotes */
+.crossreference { }
+#bible .crossreference:before { }
+#bible .crossreference:after { }
+
+/*Keep in mind that for cross references it is not enough to
+*set only the cross reference colour, you must also set the
+*cross reference anchor marker with .crossreference a
+*This way both the non linked and linked text will show
+*as desired. Additionally, you can have seperate formatting
+*for linked and non linked text in the cross reference*/
+.crossreference a { }
+.crossreference a:hover { }
+
+/* Alternative reading as defined in the OSIS specs. The information about the alternative text is displayed in the info display. It's
+often a good idea to format this the same as footnotes
+The text which is the alternative of the displayed text is available in the attribute "alternative"
+so something like .alternative:before { content:"'"attr(alternative); } is possible
+*/
+.alternative {}
+.alternative:before { }
+.alternative:after { }
+
+/* An abbreviation. */
+.abbreviation { }
+
+/* A title within the text. This is the formatting which applies to a title of a section, as you can find them in Bibles */
+.sectiontitle { }
+#printer .sectiontitle { }
+/* You may want to format elements before section titles in a special way. */
+* + .sectiontitle { }
+
+/* The title of a book, e.g. "The gospel of Matthew" */
+.booktitle { }
+#printer .booktitle { }
+
+/* A foreign word */
+.foreign { }
+
+/* Words spoken by Jesus Christ */
+.jesuswords { }
+
+/* An introduction to a module, book or chapter */
+.introduction { }
+/* A quotation without a special speaker */
+.quotation { }
+/* Poetry formatting */
+.poetry { }
+/* Text displayed above. It's like the sup tag in HTML */
+.sup { }
+/* Sub text, the opposite of .sup */
+.sub { }
+/* Display the text inside as right aligned text */
+.right { }
+/* Display as centered text */
+.center { }
+
+/* Visual attributes to the text */
+.bold { }
+.illuminated { }
+.italic { }
+.line-through { }
+.normal { }
+.small-caps{ }
+.underline { }
+
+/* An inscription */
+.inscription { }
+
+.mentioned { }
+
+/* Special formatting rules for names, see the OSIS specs for detailed information */
+.name {}
+.name > .geographic { }
+.name > .holiday { }
+.name > .nonhuman { }
+.name > .person { }
+.name > .ritual { }
+.name > .divine { }
+
+/* Information added by the translator */
+.transchange {}
+.transchange > .added { }
+.transchange > .amplified {}
+.transchange > .changed { }
+.transchange > .deleted { }
+.transchange > .moved { }
+.transchange > .tenseChange { }
+
+/* Special text markup */
+/* Morph segmentation is a special feature for hebrew to markup the word divisions in the text */
+.morphSegmentation {}
+
+/* The formatting of all things displayed in the information window */
+#infodisplay { }
+
+/* The headings of a section, several sections may be displayed together at the same time */
+#infodisplay .footnoteinfo h3,
+#infodisplay .strongsinfo h3,
+#infodisplay .morphinfo h3,
+#infodisplay .translationinfo h3,
+#infodisplay .crossrefinfo h3 { }
+
+#infodisplay > p, #infodisplay * > p { /* We only format the first p child in a special way */ }
+
+/*Required for cross references*/
+#infodisplay .entry { }
+#infodisplay .entry .entry { /* No smaller font size for nested entries */ }
+#infodisplay .entryname { }
+#infodisplay .rangeheading {}
+
+#printer .rangeheading {}
+
+/* Here's the marker for the language specific fotn information. BibleTime replaces this by the CSS for the fonts */
+#LANG_CSS#
+
+/* ]]> */
+ </style>
+</head>
+
+<!-- The display type may be bible, book, printer -->
+<body id="#DISPLAYTYPE#">
+ <div id="content" lang="#LANG_ABBREV#" xml:lang="#LANG_ABBREV#">#CONTENT#</div></body>
+</html> \ No newline at end of file
diff --git a/src/frontend/bookshelfmanager/btconfigdialog.cpp b/src/frontend/bookshelfmanager/btconfigdialog.cpp
new file mode 100644
index 0000000..87cb12e
--- /dev/null
+++ b/src/frontend/bookshelfmanager/btconfigdialog.cpp
@@ -0,0 +1,122 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+#include "btconfigdialog.h"
+
+#include "util/directoryutil.h"
+#include "util/ctoolclass.h"
+
+#include <QDialog>
+#include <QStackedWidget>
+#include <QListWidget>
+#include <QListView>
+#include <QListWidgetItem>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QDialogButtonBox>
+#include <QFrame>
+#include <QEvent>
+
+BtConfigDialog::BtConfigDialog(QWidget* parent)
+ : QDialog(parent),
+ m_maxItemWidth(0),
+ m_previousPageIndex(-2)
+{
+ setWindowFlags(Qt::Window);
+ m_contentsList = new QListWidget(this);
+ m_contentsList->setViewMode(QListView::IconMode);
+ m_contentsList->setMovement(QListView::Static);
+
+ m_pageWidget = new QStackedWidget(this);
+ m_pageWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
+
+ QHBoxLayout *mainLayout = new QHBoxLayout;
+ setLayout(mainLayout);
+ mainLayout->addWidget(m_contentsList);
+ m_pageLayout = new QVBoxLayout;
+ mainLayout->addLayout(m_pageLayout);
+
+ m_pageLayout->addWidget(m_pageWidget);
+
+ // Horizontal line
+ QFrame* line = new QFrame();
+ line->setGeometry(QRect(1, 1, 1, 3));
+ line->setFrameShape(QFrame::HLine);
+ line->setFrameShadow(QFrame::Sunken);
+ line->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+ m_pageLayout->addWidget(line);
+
+ connect(m_contentsList,
+ SIGNAL(currentRowChanged(int)),
+ this, SLOT(slotChangePage(int))
+ );
+
+}
+
+BtConfigDialog::~BtConfigDialog() {}
+
+void BtConfigDialog::addPage(BtConfigPage* pageWidget)
+{
+ // this is a friend
+ pageWidget->m_parentDialog = this;
+
+ QVBoxLayout* containerLayout = new QVBoxLayout;
+ QLabel* headerLabel = CToolClass::explanationLabel(pageWidget, pageWidget->header(), pageWidget->label());
+ containerLayout->addWidget(headerLabel);
+ containerLayout->addWidget(pageWidget);
+ QWidget* containerWidget = new QWidget(m_pageWidget);
+ containerWidget->setLayout(containerLayout);
+ m_pageWidget->addWidget(containerWidget);
+
+
+ QListWidgetItem* item = new QListWidgetItem(m_contentsList);
+ item->setIcon(util::filesystem::DirectoryUtil::getIcon(pageWidget->iconName()));
+ item->setText(pageWidget->header());
+ item->setTextAlignment(Qt::AlignHCenter);
+ item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+
+ //set the list width - it may bee too wide (if there were no pages) or too narrow
+ if (m_maxItemWidth < m_contentsList->visualItemRect(item).width()) {
+ m_maxItemWidth = m_contentsList->visualItemRect(item).width();
+ m_contentsList->setFixedWidth( m_maxItemWidth + (m_contentsList->frameWidth()*2) );
+ }
+ // all items should has the same width
+ for(int i = 0; i < m_contentsList->count(); ++i) {
+ m_contentsList->item(i)->setSizeHint(QSize(m_maxItemWidth, m_contentsList->visualItemRect(m_contentsList->item(i)).height()) );
+ }
+
+ slotChangePage(m_contentsList->row(item));
+}
+
+void BtConfigDialog::addButtonBox(QDialogButtonBox* box)
+{
+ m_pageLayout->addWidget(box);
+}
+
+BtConfigPage* BtConfigDialog::currentPage()
+{
+ return dynamic_cast<BtConfigPage*>(m_pageWidget->currentWidget());
+}
+
+void BtConfigDialog::slotChangePage(int newIndex)
+{
+ if (m_previousPageIndex != newIndex) {
+ m_previousPageIndex = newIndex;
+ m_contentsList->setCurrentRow(newIndex);
+ m_pageWidget->setCurrentIndex(newIndex);
+ }
+}
+
+
+
+BtConfigPage::BtConfigPage() {}
+
+BtConfigPage::~BtConfigPage() {}
diff --git a/src/frontend/bookshelfmanager/btconfigdialog.h b/src/frontend/bookshelfmanager/btconfigdialog.h
new file mode 100644
index 0000000..7fb3482
--- /dev/null
+++ b/src/frontend/bookshelfmanager/btconfigdialog.h
@@ -0,0 +1,90 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTCONFIGDIALOG_H
+#define BTCONFIGDIALOG_H
+
+
+#include <QDialog>
+#include <QWidget>
+
+#include <QDebug>
+
+class BtConfigPage;
+
+class QListWidgetItem;
+class QListWidget;
+class QStackedWidget;
+class QDialogButtonBox;
+class QVBoxLayout;
+
+/**
+* Base class for configuration dialogs. A dialog which has a page chooser (icons
+* + text) at the left, widget pages and a buttonbox.
+*
+* Usage: add BtConfigPage pages with addPage(), add a button box with addButtonBox().
+* Connect the button box signals. Use setAttribute(Qt::WA_DeleteOnClose) if you want
+* an auto-destroying window.
+*/
+class BtConfigDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ BtConfigDialog(QWidget* parent);
+ virtual ~BtConfigDialog();
+
+ /** Adds a BtConfigPage to the paged widget stack. The new page will be the current page.*/
+ void addPage(BtConfigPage* pageWidget);
+ /** Adds a button box to the lower edge of the dialog. */
+ void addButtonBox(QDialogButtonBox* buttonBox);
+
+ /** Returns the currently selected page. */
+ BtConfigPage* currentPage();
+
+public slots:
+ /** Changes the current page using the given index number. */
+ void slotChangePage(int newIndex);
+
+private:
+ QListWidget* m_contentsList;
+ QStackedWidget* m_pageWidget;
+ QVBoxLayout* m_pageLayout;
+ int m_maxItemWidth;
+ int m_previousPageIndex;
+};
+
+
+
+/**
+* Base class for configuration dialog pages.
+*/
+class BtConfigPage : public QWidget
+{
+ Q_OBJECT
+public:
+ BtConfigPage();
+ virtual ~BtConfigPage();
+
+ /** Implement these to return the correct values.
+ * For example: header(){return tr("General");}
+ */
+ virtual QString iconName() = 0;
+ virtual QString label() = 0;
+ virtual QString header() = 0;
+ BtConfigDialog* parentDialog() {return m_parentDialog;}
+
+private:
+ friend class BtConfigDialog;
+ BtConfigDialog* m_parentDialog;
+
+};
+
+
+#endif
+
diff --git a/src/frontend/bookshelfmanager/btinstallmgr.cpp b/src/frontend/bookshelfmanager/btinstallmgr.cpp
new file mode 100644
index 0000000..d0bc760
--- /dev/null
+++ b/src/frontend/bookshelfmanager/btinstallmgr.cpp
@@ -0,0 +1,94 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//BibleTime includes
+#include "btinstallmgr.h"
+
+#include "frontend/bookshelfmanager/instbackend.h"
+#include "backend/managers/cswordbackend.h"
+
+//Qt includes
+#include <QObject>
+#include <QList>
+#include <QString>
+#include <QStringList>
+
+#include <QDebug>
+
+//sword includes
+#include <installmgr.h>
+#include <ftptrans.h>
+
+using namespace sword;
+
+
+BtInstallMgr::BtInstallMgr()
+ : InstallMgr(instbackend::configPath().toLatin1(), this),
+ m_firstCallOfPreStatus(true)
+{ //use this class also as status reporter
+ qDebug("BtInstallMgr::BtInstallMgr");
+ this->setFTPPassive(true);
+#ifdef SWORD_INTERNET_WARNING
+ // this was in 1.6RC1, removed in RC2. To be removed from here soon - uncomment this and comment out the isUserDisclaimerConfirmed if you need to use RC1.
+ //setUserDisclaimerConfirmed(true);
+#endif
+}
+
+BtInstallMgr::~BtInstallMgr() {
+ //doesn't really help because it only sets a flag
+ terminate(); //make sure to close the connection
+}
+
+#ifdef SWORD_INTERNET_WARNING
+bool BtInstallMgr::isUserDisclaimerConfirmed() const
+{
+ // TODO: Check from config if it's been confirmed with "don't show this anymore" checked.
+ // Create a dialog with the message, checkbox and Continue/Cancel, Cancel as default.
+ return true;
+}
+#endif
+
+void BtInstallMgr::statusUpdate(double dltotal, double dlnow)
+{
+ //qDebug("BtInstallMgr::statusUpdate");
+ if (dlnow > dltotal)
+ dlnow = dltotal;
+
+ int totalPercent = (int)((float)(dlnow + m_completedBytes) / (float)(m_totalBytes) * 100.0);
+
+ if (totalPercent > 100) {
+ totalPercent = 100;
+ }
+ else if (totalPercent < 0) {
+ totalPercent = 0;
+ }
+
+ int filePercent = (int)((float)(dlnow) / (float)(dltotal+1) * 100.0);
+ if (filePercent > 100) {
+ filePercent = 100;
+ }
+ else if (filePercent < 0) {
+ filePercent = 0;
+ }
+ //qApp->processEvents();
+ //qDebug() << "status: total"<<totalPercent<<"file"<<filePercent;
+ emit percentCompleted(totalPercent, filePercent);
+}
+
+
+void BtInstallMgr::preStatus(long totalBytes, long completedBytes, const char* message)
+{
+ if (m_firstCallOfPreStatus) {
+ m_firstCallOfPreStatus = false;
+ emit downloadStarted();
+ }
+ qDebug() << "BtInstallMgr::preStatus:" << (int)totalBytes << "/" << (int)completedBytes << QString(message);
+ m_completedBytes = completedBytes;
+ m_totalBytes = (totalBytes > 0) ? totalBytes : 1; //avoid division by zero
+}
diff --git a/src/frontend/bookshelfmanager/btinstallmgr.h b/src/frontend/bookshelfmanager/btinstallmgr.h
new file mode 100644
index 0000000..5607981
--- /dev/null
+++ b/src/frontend/bookshelfmanager/btinstallmgr.h
@@ -0,0 +1,75 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef NEWBTINSTALLMGR_H
+#define NEWBTINSTALLMGR_H
+
+//sword includes
+#include <installmgr.h>
+#include <ftptrans.h>
+
+//Qt includes
+#include <QObject>
+#include <QList>
+#include <QString>
+#include <QStringList>
+
+class CSwordBackend;
+
+
+typedef QList<sword::InstallSource*> InstallSourceList;
+
+/**
+* Our own reimplementation to provide installation and status bar updates.
+*/
+class BtInstallMgr : public QObject, public sword::InstallMgr, public sword::StatusReporter {
+ Q_OBJECT
+public:
+
+ BtInstallMgr();
+ virtual ~BtInstallMgr();
+
+ /**
+ * Refreshing the source should be cancellable (othewise it might freeze the app if there is
+ * for example something wrong with the network).
+ */
+ void slotRefreshCanceled();
+
+#ifdef SWORD_INTERNET_WARNING
+ /** Re-implemented from sword::InstallMgr. */
+ virtual bool isUserDisclaimerConfirmed() const;
+#endif
+
+protected:
+ /* Reimplementations of methods in StatusReporter */
+ /**
+ * Gets the total and current file status, emits the signal with those values as percents.
+ */
+ virtual void statusUpdate(double dltotal, double dlnow);
+ /**
+ * Called before starting to download each file of the module package.
+ * The sword message is not i18n'ed, it's in the form "Downloading (1 of 6): nt.bzs".
+ * This function is not utilized in the UI ATM.
+ */
+ virtual void preStatus(long totalBytes, long completedBytes, const char *message);
+
+ long m_totalBytes;
+ long m_completedBytes;
+
+private:
+ bool m_firstCallOfPreStatus;
+
+signals:
+ /** Download status. Percent of total and file.*/
+ void percentCompleted( const int, const int);
+ void downloadStarted();
+};
+
+
+#endif
diff --git a/src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp b/src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp
new file mode 100644
index 0000000..5e3dc41
--- /dev/null
+++ b/src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp
@@ -0,0 +1,73 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btmodulemanagerdialog.h"
+
+#include "installpage/btinstallpage.h"
+#include "removepage/btremovepage.h"
+#include "indexpage/btindexpage.h"
+
+#include "util/cpointers.h"
+#include "util/dialogutil.h"
+#include "backend/managers/cswordbackend.h"
+
+#include <QDialogButtonBox>
+
+
+static BtModuleManagerDialog* m_staticModuleManagerDialog = 0;
+
+BtModuleManagerDialog* BtModuleManagerDialog::getInstance(QWidget* parent)
+{
+ if (!m_staticModuleManagerDialog) {
+ m_staticModuleManagerDialog = new BtModuleManagerDialog(parent);
+ };
+ Q_ASSERT(m_staticModuleManagerDialog);
+ return m_staticModuleManagerDialog;
+}
+
+BtModuleManagerDialog::BtModuleManagerDialog(QWidget* parent)
+ : BtConfigDialog(parent)
+{
+ setAttribute(Qt::WA_DeleteOnClose);
+ setWindowTitle(tr("Bookshelf Manager"));
+
+ // Install page
+ BtInstallPage* installPage = new BtInstallPage();
+ addPage(installPage);
+
+ //Uninstall page
+ BtRemovePage* removePage = new BtRemovePage();
+ addPage(removePage);
+
+ //Index page
+ BtIndexPage* indexPage = new BtIndexPage();
+ addPage(indexPage);
+
+ slotChangePage(0);
+
+ // Dialog button (Close)
+ QDialogButtonBox* bbox = new QDialogButtonBox(this);
+ bbox->addButton(QDialogButtonBox::Close);
+ util::prepareDialogBox(bbox);
+ addButtonBox(bbox);
+ connect(bbox, SIGNAL(rejected()), SLOT(close()));
+}
+
+BtModuleManagerDialog::~BtModuleManagerDialog()
+{
+ m_staticModuleManagerDialog = 0;
+}
+
+// The QWidget close() sends close event, so does closing by the window X button.
+void BtModuleManagerDialog::closeEvent(QCloseEvent*)
+{
+ qDebug("BtModuleManagerDialog::closeEvent");
+}
+
+
diff --git a/src/frontend/bookshelfmanager/btmodulemanagerdialog.h b/src/frontend/bookshelfmanager/btmodulemanagerdialog.h
new file mode 100644
index 0000000..52c3e71
--- /dev/null
+++ b/src/frontend/bookshelfmanager/btmodulemanagerdialog.h
@@ -0,0 +1,43 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+#ifndef BTMODULEMANAGERDIALOG_H
+#define BTMODULEMANAGERDIALOG_H
+
+#include "btconfigdialog.h"
+
+class QWidget;
+
+/**
+* The Bookshelf Manager dialog. Includes pages for Install, Remove, Indexes.
+*/
+class BtModuleManagerDialog : public BtConfigDialog
+{
+ Q_OBJECT
+
+public:
+ static BtModuleManagerDialog* getInstance(QWidget* parent);
+
+ ~BtModuleManagerDialog();
+
+
+ //void slotClose();
+protected:
+ /** Reimplementation from QWidget. */
+ virtual void closeEvent(QCloseEvent* event);
+ /** Adds the pages and the button box. */
+ BtModuleManagerDialog(QWidget* parent);
+
+//signals:
+// void swordSetupChanged();
+};
+
+
+#endif
diff --git a/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp b/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp
new file mode 100644
index 0000000..bca32fa
--- /dev/null
+++ b/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp
@@ -0,0 +1,184 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//BT includes
+#include "cswordsetupinstallsourcesdialog.h"
+
+#include "frontend/bookshelfmanager/instbackend.h"
+
+#include <boost/scoped_ptr.hpp>
+
+//Qt includes
+#include <QLayout>
+#include <QLabel>
+#include <QComboBox>
+#include <QLineEdit>
+#include <QPushButton>
+#include <QMessageBox>
+#include <QFileInfo>
+#include <QGridLayout>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QFileDialog>
+#include <QDir>
+
+
+
+const QString PROTO_FILE( QObject::tr("Local") ); //Local path
+const QString PROTO_FTP( QObject::tr("Remote") ); //Remote path
+
+
+CSwordSetupInstallSourcesDialog::CSwordSetupInstallSourcesDialog(/*QWidget *parent*/)
+ : QDialog()
+{
+ setWindowTitle(tr("New Installation Source"));
+
+ QVBoxLayout* mainLayout = new QVBoxLayout( this );
+ mainLayout->setMargin( 10 );
+ mainLayout->setSpacing( 5 );
+
+ QHBoxLayout *captionLayout = new QHBoxLayout( this );
+ mainLayout->addLayout(captionLayout);
+ QLabel *label = new QLabel( tr("Caption"), this );
+ captionLayout->addWidget( label );
+
+ m_captionEdit = new QLineEdit( this );
+ m_captionEdit->setText("Crosswire Bible Society");
+ captionLayout->addWidget( m_captionEdit );
+
+ mainLayout->addSpacing( 10 );
+
+ QGridLayout* layout = new QGridLayout( this );
+ layout->setSpacing(3);
+ layout->setMargin(3);
+ mainLayout->addLayout(layout);
+ layout->setSpacing( 5 );
+
+ label = new QLabel(tr("Type"), this);
+ layout->addWidget( label, 0, 0);
+
+ m_serverLabel = new QLabel(tr("Server"), this);
+ layout->addWidget( m_serverLabel, 0, 1);
+
+ label = new QLabel(tr("Path"), this);
+ layout->addWidget( label, 0, 2 );
+
+ m_protocolCombo = new QComboBox( this );
+ layout->addWidget(m_protocolCombo, 1, 0);
+ m_protocolCombo->addItem( PROTO_FTP );
+ m_protocolCombo->addItem( PROTO_FILE );
+
+ m_serverEdit = new QLineEdit( this );
+ layout->addWidget( m_serverEdit, 1, 1 );
+ m_serverEdit->setText("ftp.crosswire.org");
+
+ m_pathEdit = new QLineEdit( this );
+ layout->addWidget( m_pathEdit, 1, 2 );
+ m_pathEdit->setText("/pub/sword/raw");
+
+ mainLayout->addSpacing( 10 );
+
+ QHBoxLayout* buttonLayout = new QHBoxLayout( this );
+ mainLayout->addLayout(buttonLayout);
+ buttonLayout->addStretch();
+ QPushButton* okButton = new QPushButton( tr("Ok"), this);
+ QPushButton* discardButton = new QPushButton( tr("Discard"), this);
+ buttonLayout->addWidget( discardButton);
+ buttonLayout->addWidget( okButton);
+ buttonLayout->addStretch();
+
+ connect( okButton, SIGNAL( clicked() ), this, SLOT( slotOk() ) );
+ connect( discardButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
+ connect( m_protocolCombo, SIGNAL( activated(int) ), this, SLOT( slotProtocolChanged() ) );
+
+}
+void CSwordSetupInstallSourcesDialog::slotOk() {
+ //run a few tests to validate the input first
+ if ( m_captionEdit->text().trimmed().isEmpty() ) { //no caption
+ QMessageBox::information( this, tr( "Error" ), tr("Please provide a caption."), QMessageBox::Retry);
+ return;
+ }
+
+ //BTInstallMgr iMgr;
+ //sword::InstallSource is = BTInstallMgr::Tool::RemoteConfig::source( &iMgr, m_captionEdit->text() );
+ sword::InstallSource is = instbackend::source(m_captionEdit->text());
+ if ( (QString)is.caption.c_str() == m_captionEdit->text() ) { //source already exists
+ QMessageBox::information( this, tr( "Error" ),
+ tr("A source with this caption already exists.<br>Please provide a different caption."), QMessageBox::Retry);
+ return;
+ }
+
+ if ( m_protocolCombo->currentText() == PROTO_FTP &&
+ m_serverEdit->text().trimmed().isEmpty() ) { //no server name
+ QMessageBox::information( this, tr( "Error" ), tr("Please provide a server name."), QMessageBox::Retry);
+ return;
+ }
+
+ if ( m_protocolCombo->currentText() == PROTO_FILE) {
+ const QFileInfo fi( m_pathEdit->text() );
+ if (!fi.exists() || !fi.isReadable()) { //no valid and readable path
+ QMessageBox::information( this, tr( "Error" ), tr("Please provide a valid, readable path."), QMessageBox::Retry);
+ return;
+ }
+ else if ( m_pathEdit->text().isEmpty() ) {
+ QMessageBox::information( this, tr( "Error" ), tr("Please provide a path."), QMessageBox::Retry);
+
+ }
+ }
+
+ accept(); //only if nothing else failed
+}
+
+void CSwordSetupInstallSourcesDialog::slotProtocolChanged() {
+ if (m_protocolCombo->currentText() == PROTO_FTP) { //REMOTE
+ m_serverLabel->setEnabled(true);
+ m_serverEdit->setEnabled(true);
+ }
+ else { //LOCAL, no server needed
+ m_serverLabel->setEnabled(false);
+ m_serverEdit->setEnabled(false);
+
+ QString dirname = QFileDialog::getExistingDirectory(this);
+ if (dirname.isEmpty()) {
+ return; // user cancelled
+ }
+ QDir dir(dirname);
+ if (dir.exists()) {
+ m_pathEdit->setText( dir.canonicalPath() );
+ }
+ }
+
+}
+
+sword::InstallSource CSwordSetupInstallSourcesDialog::getSource() {
+
+ boost::scoped_ptr<CSwordSetupInstallSourcesDialog> dlg( new CSwordSetupInstallSourcesDialog() );
+ sword::InstallSource newSource(""); //empty, invalid Source
+
+ if (dlg->exec() == QDialog::Accepted) {
+ if (dlg->m_protocolCombo->currentText() == PROTO_FTP) {
+ newSource.type = "FTP";
+ newSource.source = dlg->m_serverEdit->text().toUtf8();
+
+ //a message to the user would be nice, but we're in message freeze right now (1.5.1)
+ if (dlg->m_serverEdit->text().right(1) == "/") { //remove a trailing slash
+ newSource.source = dlg->m_serverEdit->text().mid(0, dlg->m_serverEdit->text().length()-1).toUtf8();
+ }
+ }
+ else {
+ newSource.type = "DIR";
+ newSource.source = "local";
+ }
+ newSource.caption = dlg->m_captionEdit->text().toUtf8();
+ newSource.directory = dlg->m_pathEdit->text().toUtf8();
+ }
+ return newSource;
+}
+
+
diff --git a/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h b/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h
new file mode 100644
index 0000000..47f1973
--- /dev/null
+++ b/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h
@@ -0,0 +1,46 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+#ifndef CSWORDSETUPINSTALLSOURCESDIALOG_H
+#define CSWORDSETUPINSTALLSOURCESDIALOG_H
+
+#include "frontend/bookshelfmanager/btinstallmgr.h"
+
+#include <QDialog>
+
+#include <installmgr.h>
+
+class QLabel;
+class QComboBox;
+class QLineEdit;
+
+
+
+class CSwordSetupInstallSourcesDialog : public QDialog {
+ Q_OBJECT
+
+public:
+ static sword::InstallSource getSource();
+
+protected:
+ CSwordSetupInstallSourcesDialog();
+
+protected slots:
+ void slotOk();
+ void slotProtocolChanged();
+
+private:
+ QLabel *m_serverLabel;
+ QLineEdit *m_captionEdit, *m_serverEdit, *m_pathEdit;
+ QComboBox *m_protocolCombo;
+};
+
+
+#endif //CSWORDSETUPINSTALLSOURCESDIALOG_H
diff --git a/src/frontend/bookshelfmanager/indexpage/btindexpage.cpp b/src/frontend/bookshelfmanager/indexpage/btindexpage.cpp
new file mode 100644
index 0000000..6c45f9c
--- /dev/null
+++ b/src/frontend/bookshelfmanager/indexpage/btindexpage.cpp
@@ -0,0 +1,216 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btindexpage.h"
+
+#include "frontend/cmoduleindexdialog.h"
+#include "backend/config/cbtconfig.h"
+
+#include "util/ctoolclass.h"
+#include "util/cresmgr.h"
+#include "util/cpointers.h"
+#include "util/directoryutil.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/managers/cswordbackend.h"
+
+//Qt includes
+#include <QString>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+#include <QCheckBox>
+#include <QDir>
+#include <QPushButton>
+
+
+BtIndexPage::BtIndexPage()
+ : BtConfigPage()
+{
+
+ QVBoxLayout *vboxLayout;
+ QHBoxLayout *hboxLayout;
+ vboxLayout = new QVBoxLayout(this);
+
+ m_autoDeleteOrphanedIndicesBox = new QCheckBox(this);
+ m_autoDeleteOrphanedIndicesBox->setToolTip(tr("If selected, those indexes which have no corresponding work will be deleted when BibleTime starts"));
+ m_autoDeleteOrphanedIndicesBox->setText(tr("Automatically delete orphaned indexes when BibleTime starts"));
+ vboxLayout->addWidget(m_autoDeleteOrphanedIndicesBox);
+
+ m_moduleList = new QTreeWidget(this);
+ vboxLayout->addWidget(m_moduleList);
+
+ hboxLayout = new QHBoxLayout();
+
+ QSpacerItem *spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
+ hboxLayout->addItem(spacerItem);
+
+ m_deleteButton = new QPushButton(this);
+ m_deleteButton->setToolTip(tr("Delete the selected indexes"));
+ m_deleteButton->setText(tr("Delete"));
+ hboxLayout->addWidget(m_deleteButton);
+
+ m_createButton = new QPushButton(this);
+ m_createButton->setToolTip(tr("Create new indexes for the selected works"));
+ m_createButton->setText(tr("Create..."));
+ hboxLayout->addWidget(m_createButton);
+
+ vboxLayout->addLayout(hboxLayout);
+
+ // configure the list view
+ m_moduleList->setHeaderLabels( (QStringList(tr("Work")) << tr("Index size")) );
+ m_moduleList->setRootIsDecorated(true);
+ m_moduleList->setColumnWidth(0, CToolClass::mWidth(m_moduleList, 20) );
+ //m_moduleList->setTextAlignment(1, Qt::AlignRight); see doc...
+ m_moduleList->setSortingEnabled(false);
+
+ m_autoDeleteOrphanedIndicesBox->setChecked( CBTConfig::get( CBTConfig::autoDeleteOrphanedIndices ) );
+
+ // icons for our buttons
+ m_createButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::indexpage::create_icon));
+ m_deleteButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::indexpage::delete_icon));
+
+ // connect our signals/slots
+ connect(m_createButton, SIGNAL(clicked()), this, SLOT(createIndices()));
+ connect(m_deleteButton, SIGNAL(clicked()), this, SLOT(deleteIndices()));
+ connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), SLOT(slotSwordSetupChanged()));
+
+ populateModuleList();
+}
+
+BtIndexPage::~BtIndexPage()
+{
+ CBTConfig::set( CBTConfig::autoDeleteOrphanedIndices, m_autoDeleteOrphanedIndicesBox->isChecked() );
+
+}
+QString BtIndexPage::label()
+{
+ return tr("Create new search indexes and delete created indexes for the installed works.");
+}
+QString BtIndexPage::iconName()
+{
+ return CResMgr::bookshelfmgr::indexpage::icon;
+}
+QString BtIndexPage::header()
+{
+ return tr("Search Indexes");
+}
+
+
+/** Populates the module list with installed modules and orphaned indices */
+void BtIndexPage::populateModuleList() {
+ m_moduleList->clear();
+
+ // populate installed modules
+ m_modsWithIndices = new QTreeWidgetItem(m_moduleList);
+ m_modsWithIndices->setText(0, tr("Works with indexes"));
+ m_modsWithIndices->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsTristate);
+ m_modsWithIndices->setExpanded(true);
+
+ m_modsWithoutIndices = new QTreeWidgetItem(m_moduleList);
+ m_modsWithoutIndices->setText(0, tr("Works without indexes"));
+ m_modsWithoutIndices->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsTristate);
+ m_modsWithoutIndices->setExpanded(true);
+
+
+
+ QList<CSwordModuleInfo*>& modules = CPointers::backend()->moduleList();
+ QList<CSwordModuleInfo*>::iterator end_it = modules.end();
+ for (QList<CSwordModuleInfo*>::iterator it = modules.begin(); it != end_it; ++it) {
+ QTreeWidgetItem* item = 0;
+
+ if ((*it)->hasIndex()) {
+ item = new QTreeWidgetItem(m_modsWithIndices);
+ item->setText(0, (*it)->name());
+ item->setText(1, QString("%1 ").arg((*it)->indexSize() / 1024) + tr("KiB"));
+ item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
+ item->setCheckState(0, Qt::Unchecked);
+ }
+ else {
+ item = new QTreeWidgetItem(m_modsWithoutIndices);
+ item->setText(0, (*it)->name());
+ item->setText(1, QString("0 ") + tr("KiB"));
+ item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
+ item->setCheckState(0, Qt::Checked);
+ }
+ }
+}
+
+/** Creates indices for selected modules if no index currently exists */
+void BtIndexPage::createIndices()
+{
+ bool indicesCreated = false;
+ QList<CSwordModuleInfo*> moduleList;
+
+ for (int i = 0; i < m_modsWithoutIndices->childCount(); i++) {
+ if (m_modsWithoutIndices->child(i)->checkState(0) == Qt::Checked) {
+ CSwordModuleInfo* module = CPointers::backend()->findModuleByName(m_modsWithoutIndices->child(i)->text(0).toUtf8());
+ if (module) {
+ moduleList.append( module );
+ indicesCreated = true;
+ }
+ }
+ }
+
+ //Shows the progress dialog
+ if (indicesCreated) {
+ CModuleIndexDialog::getInstance()->indexAllModules( moduleList );
+ populateModuleList();
+ }
+}
+
+/** Deletes indices for selected modules */
+void BtIndexPage::deleteIndices()
+{
+ bool indicesDeleted = false;
+
+ for (int i = 0; i < m_modsWithIndices->childCount(); i++) {
+ if (m_modsWithIndices->child(i)->checkState(0) == Qt::Checked) {
+ CSwordModuleInfo* module = CPointers::backend()->findModuleByName(m_modsWithIndices->child(i)->text(0).toUtf8());
+ if (module) {
+ CSwordModuleInfo::deleteIndexForModule( module->name() );
+ indicesDeleted = true;
+ }
+ }
+ }
+
+ // repopulate the list if an action was taken
+ if (indicesDeleted) {
+ populateModuleList();
+ }
+}
+
+void BtIndexPage::deleteOrphanedIndices()
+{
+ QDir dir(CSwordModuleInfo::getGlobalBaseIndexLocation());
+ dir.setFilter(QDir::Dirs);
+ CSwordModuleInfo* module;
+
+ for (unsigned int i = 0; i < dir.count(); i++) {
+ if (dir[i] != "." && dir[i] != "..") {
+ if ( (module = CPointers::backend()->findModuleByName(dir[i])) ) { //mod exists
+ if (!module->hasIndex()){ //index files found, but wrong version etc.
+ CSwordModuleInfo::deleteIndexForModule( dir[i] );
+ }
+ }
+ else{ //no module exists
+ if (CBTConfig::get( CBTConfig::autoDeleteOrphanedIndices ) ){
+ CSwordModuleInfo::deleteIndexForModule( dir[i] );
+ }
+ }
+ }
+ }
+}
+
+void BtIndexPage::slotSwordSetupChanged()
+{
+ populateModuleList();
+}
+
diff --git a/src/frontend/bookshelfmanager/indexpage/btindexpage.h b/src/frontend/bookshelfmanager/indexpage/btindexpage.h
new file mode 100644
index 0000000..d8b49c4
--- /dev/null
+++ b/src/frontend/bookshelfmanager/indexpage/btindexpage.h
@@ -0,0 +1,87 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+#ifndef BTINDEXPAGE_H
+#define BTINDEXPAGE_H
+
+#include "frontend/bookshelfmanager/btconfigdialog.h"
+#include "backend/btmoduletreeitem.h"
+
+class QCheckBox;
+class QTreeWidget;
+class QTreeWidgetItem;
+
+/**
+* This class encapsulates the "Manage search indices" page of the Bookshelf
+* Manager. It allows for creation and deletion of search indicies for each
+* installed module. It also allows for deletion of orphaned indices.
+*/
+class BtIndexPage : public BtConfigPage
+{
+ Q_OBJECT
+
+public:
+ /**
+ * Constructor
+ */
+ BtIndexPage();
+
+ /**
+ * Destructor
+ */
+ ~BtIndexPage();
+
+ // BtConfigPage methods
+ QString header();
+ QString iconName();
+ QString label();
+
+public slots:
+ void slotSwordSetupChanged();
+
+protected:
+
+ /**
+ * Populates the module list with installed modules and orphaned indices
+ */
+ void populateModuleList();
+
+
+
+public slots:
+ /**
+ * Creates indices for selected modules if no index currently exists
+ */
+ void createIndices();
+ /**
+ * Deletes indices for selected modules
+ */
+ void deleteIndices();
+
+public:
+ /**
+ * Deletes orphaned indices if the autoDeleteOrphanedIndices is true
+ * Always deletes indices of existing modules where hasIndex() returns false
+ */
+ static void deleteOrphanedIndices();
+
+private:
+
+ QCheckBox *m_autoDeleteOrphanedIndicesBox;
+ QTreeWidget *m_moduleList;
+ QPushButton *m_deleteButton;
+ QPushButton *m_createButton;
+
+ QTreeWidgetItem* m_modsWithIndices;
+ QTreeWidgetItem* m_modsWithoutIndices;
+};
+
+
+#endif
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp
new file mode 100644
index 0000000..739d2ea
--- /dev/null
+++ b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp
@@ -0,0 +1,232 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btinstallmodulechooserdialog.h"
+
+#include "frontend/cmodulechooserdialog.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/btmoduletreeitem.h"
+
+#include <QString>
+#include <QList>
+#include <QWidget>
+#include <QString>
+#include <QTreeWidgetItem>
+#include <QBrush>
+#include <QPushButton>
+
+#include <QDebug>
+
+
+BtInstallModuleChooserDialog::BtInstallModuleChooserDialog(QWidget* parent, QString title, QString label, QList<CSwordModuleInfo*>* empty)
+ : CModuleChooserDialog(parent, title, label, empty)
+{
+ qDebug("BtInstallModuleChooserDialog::BtInstallModuleChooserDialog start");
+ init();
+ okButton()->setText(tr("Install"));
+ m_nameList = QStringList();
+}
+
+// Do nothing, the tree is initialized outside this class.
+void BtInstallModuleChooserDialog::initModuleItem(BTModuleTreeItem*, QTreeWidgetItem*)
+{}
+
+void BtInstallModuleChooserDialog::initModuleItem(QString name, QTreeWidgetItem* sourceItem)
+{
+ QTreeWidgetItem* moduleItem = new QTreeWidgetItem(sourceItem);
+ moduleItem->setText(0, name);
+ moduleItem->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
+ moduleItem->setCheckState(0, Qt::Checked);
+
+ // prevent double items
+ if (m_nameList.contains(name)) {
+ qDebug() << "item already in list:" << name;
+ //moduleItem->setCheckState(0, Qt::Unchecked);
+ QBrush bg(Qt::red);
+ moduleItem->setBackground(0, bg);
+ //find and change the other offending items
+ foreach (QTreeWidgetItem* doubleItem, treeWidget()->findItems(name, Qt::MatchFixedString|Qt::MatchCaseSensitive|Qt::MatchRecursive, 0)) {
+ //doubleItem->setCheckState(0, Qt::Unchecked);
+ //qDebug() << "CInstallModuleChooserDialog::initModuleItem" << doubleItem;
+ doubleItem->setBackground(0, bg);
+ }
+ m_doubleCheckedModules[name] = true;
+ enableOk(false);
+ }
+ m_nameList << name;
+}
+
+void BtInstallModuleChooserDialog::slotItemChecked(QTreeWidgetItem* item, int column)
+{
+ QString moduleName = item->text(0);
+ qDebug("BtInstallModuleChooserDialog::slotItemChecked start");
+ // handle only non-toplevel items which has duplicates and where the first column was changed
+ if (item->parent() && column == 0 && (findModuleItemsByName(moduleName).count() > 1)) {
+ //prevent handling when the color is changed
+ if (item->data(1, Qt::UserRole).toBool() == false) {
+ qDebug("was not updating");
+ item->setData(1, Qt::UserRole, true);
+ } else {
+ qDebug("was updating");
+ item->setData(1, Qt::UserRole, false);
+ return;
+ }
+
+ QList<QTreeWidgetItem*> doubleNameItems = findModuleItemsByName(moduleName);
+ QList<QTreeWidgetItem*> doubleCheckedItems;
+ foreach (QTreeWidgetItem* nItem, doubleNameItems) {
+ if (nItem->checkState(0) == Qt::Checked) {
+ doubleCheckedItems << nItem;
+ }
+ }
+
+ if (doubleCheckedItems.count() > 1) {
+ enableOk(false);
+ // color the items
+ qDebug() << "there were more than 1 item of the name" << moduleName;
+ foreach (QTreeWidgetItem* i, doubleNameItems) {
+ QBrush bg(Qt::red);
+ i->setBackground(0, bg);
+ }
+ m_doubleCheckedModules[moduleName] = true;
+ } else if (doubleCheckedItems.count() == 1) {
+ qDebug() << "there were 1 checked items of the name" << moduleName;
+ // uncolor the items
+ foreach (QTreeWidgetItem* i, doubleNameItems) {
+ i->setBackground(0, i->parent()->background(0));
+ }
+ m_doubleCheckedModules.remove(moduleName);
+ if (m_doubleCheckedModules.count() == 0) {
+ enableOk(true);
+ }
+ }
+ }
+}
+
+QList<QTreeWidgetItem*> BtInstallModuleChooserDialog::findModuleItemsByName(QString name)
+{
+ qDebug() << "BtInstallModuleChooserDialog::findModuleItemsByName:" << name << treeWidget()->topLevelItemCount();
+ QList<QTreeWidgetItem*> doubleNamedAllItems = treeWidget()->findItems(name, Qt::MatchFixedString|Qt::MatchCaseSensitive|Qt::MatchRecursive);
+ //qDebug() << "doubleNamedAllItems: " << doubleNamedAllItems.count();
+ QList<QTreeWidgetItem*> doubleNamedModuleItems;
+ foreach (QTreeWidgetItem* item, doubleNamedAllItems) {
+ //qDebug() << "item:" << item;
+ if (item->parent()) {
+ doubleNamedModuleItems << item;
+ }
+ }
+ //qDebug() << "module items:" << doubleNamedModuleItems.count();
+ return doubleNamedModuleItems;
+}
+
+void BtInstallModuleChooserDialog::enableOk(bool enabled)
+{
+ qDebug() << "BtInstallModuleChooserDialog::enableOk" << enabled;
+ okButton()->setEnabled(enabled);
+}
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h
new file mode 100644
index 0000000..39b8a96
--- /dev/null
+++ b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h
@@ -0,0 +1,53 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTINSTALLMODULECHOOSERDIALOG_H
+#define BTINSTALLMODULECHOOSERDIALOG_H
+
+#include "frontend/cmodulechooserdialog.h"
+
+#include <QObject>
+#include <QString>
+#include <QMap>
+#include <QList>
+
+class BTModuleTreeItem;
+
+class QWidget;
+class QTreeWidgetItem;
+
+
+/**
+* Confirmation dialog for installation. Lets the user
+* uncheck modules from the list.
+*/
+class BtInstallModuleChooserDialog : public CModuleChooserDialog
+{
+ Q_OBJECT
+
+public:
+ BtInstallModuleChooserDialog(QWidget* parent, QString title, QString label, QList<CSwordModuleInfo*>* empty);
+
+ void initModuleItem(QString name, QTreeWidgetItem* sourceItem);
+ void enableOk(bool enabled);
+
+public slots:
+ void slotItemChecked(QTreeWidgetItem* item, int column);
+
+protected:
+ virtual void initModuleItem(BTModuleTreeItem*, QTreeWidgetItem*);
+
+ QList<QTreeWidgetItem*> findModuleItemsByName(QString name);
+private:
+ QStringList m_nameList;
+ QMap<QString, bool> m_doubleCheckedModules;
+
+};
+
+#endif
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp b/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp
new file mode 100644
index 0000000..9f8e6b9
--- /dev/null
+++ b/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp
@@ -0,0 +1,207 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+#include "btinstallpage.h"
+
+#include "btinstallpathdialog.h"
+#include "btinstallprogressdialog.h"
+#include "btsourcewidget.h"
+#include "btsourcearea.h"
+
+#include "frontend/bookshelfmanager/btinstallmgr.h"
+#include "frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h"
+#include "frontend/bookshelfmanager/btconfigdialog.h"
+#include "frontend/bookshelfmanager/instbackend.h"
+#include "frontend/bookshelfmanager/btmodulemanagerdialog.h"
+
+#include "frontend/cmodulechooserdialog.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/managers/cswordbackend.h"
+#include "backend/config/cbtconfig.h"
+
+#include "util/cpointers.h"
+#include "util/ctoolclass.h"
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+
+#include <boost/scoped_ptr.hpp>
+
+
+#include <QAction>
+#include <QApplication>
+#include <QWidget>
+#include <QButtonGroup>
+#include <QComboBox>
+#include <QDialog>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QPushButton>
+#include <QToolButton>
+#include <QSpacerItem>
+#include <QTabBar>
+#include <QStackedWidget>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+#include <QVBoxLayout>
+#include <QFileInfo>
+#include <QMessageBox>
+#include <QProgressDialog>
+#include <QTimer>
+#include <QProgressBar>
+
+#include <QHeaderView>
+
+#include <swversion.h>
+
+
+// *********************************************************
+// *********** Config dialog page: Install/Update **********
+// *********************************************************
+
+BtInstallPage::BtInstallPage()
+ : BtConfigPage()
+{
+ qDebug("BtInstallPage::BtInstallPage() start");
+ initView();
+ initConnections();
+}
+
+void BtInstallPage::setInstallEnabled(bool b)
+{
+ qDebug("void BtInstallPage::setInstallEnabled(bool b) start");
+ m_installButton->setEnabled(b);
+}
+
+QString BtInstallPage::selectedInstallPath()
+{
+ return m_pathCombo->currentText();
+}
+
+void BtInstallPage::initView()
+{
+ qDebug("void BtInstallPage::initView() start");
+ QVBoxLayout *mainLayout = new QVBoxLayout(this);
+
+ // installation path chooser
+ QHBoxLayout* pathLayout = new QHBoxLayout();
+ // beautify the layout
+ int top; int bottom; int left; int right;
+ pathLayout->getContentsMargins(&left, &top, &right, &bottom);
+ pathLayout->setContentsMargins(left, top + 7, right, bottom + 7 );
+ QSpacerItem *pathSpacer= new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
+ QLabel* pathLabel = new QLabel(tr("Install path:"));
+ m_pathCombo = new QComboBox();
+ m_pathCombo->setToolTip(tr("The path where the new works will be installed"));
+ initPathCombo(); // set the paths and the current path
+ //m_configurePathButton = new QPushButton(tr("Configure...")); //TODO: icon only?
+ m_configurePathButton = new QToolButton(this);
+ m_configurePathButton->setToolTip(tr("Configure paths where works are installed"));
+ m_configurePathButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::installpage::path_icon));
+
+ pathLayout->addItem(pathSpacer);
+ pathLayout->addWidget(pathLabel);
+ pathLayout->addWidget(m_pathCombo);
+ pathLayout->addWidget(m_configurePathButton);
+ mainLayout->addLayout(pathLayout);
+
+ // Source widget
+ //QTabWidget* m_sourcesTabWidget;
+ m_sourceWidget = new BtSourceWidget(this);
+ mainLayout->addWidget(m_sourceWidget);
+ // Install button
+ QHBoxLayout *installButtonLayout = new QHBoxLayout();
+ installButtonLayout->setContentsMargins(0,5,0,5);
+ QSpacerItem *installButtonSpacer = new QSpacerItem(371, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
+ installButtonLayout->addItem(installButtonSpacer);
+ m_installButton = new QPushButton(tr("Install..."), this);
+ m_installButton->setToolTip(tr("Install or update selected works"));
+ m_installButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::installpage::install_icon));
+ m_installButton->setEnabled(false);
+ installButtonLayout->addWidget(m_installButton);
+
+ mainLayout->addLayout(installButtonLayout);
+}
+
+void BtInstallPage::initConnections()
+{
+ qDebug("void BtInstallPage::initConnections() start");
+ QObject::connect(m_pathCombo, SIGNAL(activated(const QString&)), this , SLOT(slotPathChanged(const QString&)));
+ QObject::connect(m_configurePathButton, SIGNAL(clicked()), this, SLOT(slotEditPaths()));
+ QObject::connect(m_installButton, SIGNAL(clicked()), m_sourceWidget, SLOT(slotInstall()) );
+
+ QObject::connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), this, SLOT(slotSwordSetupChanged()));
+ //source widget has its own connections, not here
+}
+
+void BtInstallPage::initPathCombo()
+{
+ qDebug("void BtInstallPage::initPathCombo() start");
+ //populate the combo list
+ m_pathCombo->clear();
+
+ QStringList targets = instbackend::targetList();
+ for (QStringList::iterator it = targets.begin(); it != targets.end(); ++it) {
+ if ((*it).isEmpty()) continue;
+ m_pathCombo->addItem(*it);
+ }
+
+ // choose the current value from config but check whether we have so many items
+ int configValue = CBTConfig::get(CBTConfig::installPathIndex);
+ int index = configValue > (m_pathCombo->count()-1) ? m_pathCombo->count()-1 : configValue;
+ m_pathCombo->setCurrentIndex(index);
+}
+
+void BtInstallPage::slotPathChanged(const QString& /*pathText*/)
+{
+ CBTConfig::set(CBTConfig::installPathIndex, m_pathCombo->currentIndex( ) );
+}
+
+void BtInstallPage::slotEditPaths()
+{
+ qDebug("void BtInstallPage::slotEditPaths() start");
+
+ BtInstallPathDialog* dlg = new BtInstallPathDialog();
+ int result = dlg->exec();
+ if (result == QDialog::Accepted) {
+ //dynamic_cast<BtModuleManagerDialog*>(parentDialog())->slotSwordSetupChanged();
+ CPointers::backend()->reloadModules(CSwordBackend::PathChanged);
+ }
+}
+
+// implement the BtConfigPage methods
+
+QString BtInstallPage::iconName()
+{
+ return CResMgr::bookshelfmgr::installpage::icon;
+}
+QString BtInstallPage::label()
+{
+ // TODO: move the warning to a dialog which is shown when adding a source.
+ return tr("Install and update works. Add remote or local sources, refresh them, select the works to be installed/updated and click Install.<br/><b>WARNING:</b> If you live in a persecuted country and don't want to risk detection don't use remote sources.");
+}
+QString BtInstallPage::header()
+{
+ return tr("Install/Update");
+}
+
+void BtInstallPage::slotSwordSetupChanged()
+{
+ qDebug() << "BtInstallPage::slotSwordSetupChanged";
+ initPathCombo();
+// for (int i = 0; i < m_sourceWidget->count(); i++ ) {
+// BtSourceArea* sourceArea = dynamic_cast<BtSourceArea*>(m_sourceWidget->widget(i));
+// Q_ASSERT(sourceArea);
+// sourceArea->createModuleTree();
+// }
+}
+
+
+
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpage.h b/src/frontend/bookshelfmanager/installpage/btinstallpage.h
new file mode 100644
index 0000000..4d05577
--- /dev/null
+++ b/src/frontend/bookshelfmanager/installpage/btinstallpage.h
@@ -0,0 +1,66 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTINSTALLPAGE_H
+#define BTINSTALLPAGE_H
+
+
+#include "frontend/bookshelfmanager/btconfigdialog.h"
+
+#include <QString>
+
+#include <installmgr.h>
+
+
+class BtSourceWidget;
+
+class QComboBox;
+class QPushButton;
+class QToolButton;
+
+/**
+* The Install page includes module path chooser, source/module handler and install button.
+*/
+class BtInstallPage : public BtConfigPage
+{
+ Q_OBJECT
+public:
+ BtInstallPage();
+
+ // reimplemented from btinstallpage
+ QString iconName();
+ QString label();
+ QString header();
+
+ void setInstallEnabled(bool b);
+
+ QString selectedInstallPath();
+
+public slots:
+ void slotSwordSetupChanged();
+
+private:
+ void initView();
+ void initConnections();
+ void initPathCombo();
+
+private slots:
+ void slotPathChanged(const QString& pathText);
+ void slotEditPaths();
+
+private:
+
+ QComboBox* m_pathCombo;
+ //QPushButton* m_configurePathButton;
+ QToolButton* m_configurePathButton;
+ BtSourceWidget* m_sourceWidget;
+ QPushButton* m_installButton;
+};
+
+#endif
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp
new file mode 100644
index 0000000..82b8362
--- /dev/null
+++ b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp
@@ -0,0 +1,170 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btinstallpathdialog.h"
+
+#include "frontend/bookshelfmanager/instbackend.h"
+
+#include "util/ctoolclass.h"
+#include "util/dialogutil.h"
+#include "util/directoryutil.h"
+#include "util/cresmgr.h"
+
+#include <QString>
+#include <QDialog>
+#include <QDir>
+#include <QGridLayout>
+#include <QLabel>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+#include <QPushButton>
+#include <QFileDialog>
+#include <QMessageBox>
+#include <QHeaderView>
+#include <QDialogButtonBox>
+
+#include <QDebug>
+
+BtInstallPathDialog::BtInstallPathDialog()
+{
+ setWindowTitle(tr("Bookshelf Paths"));
+
+ QVBoxLayout *mainLayout;
+ QHBoxLayout *viewLayout;
+
+ mainLayout = new QVBoxLayout(this);
+ viewLayout = new QHBoxLayout();
+
+ QString l1 = tr("Works can be installed in one or more directories. After setting up directories here you can choose one of them in Install page.");
+ QString l2 = tr("BibleTime and the Sword library find the modules from all of these directories. If the directory is removed here it still exists in the system with all the works in it. \".sword\" directory in your home directory is always used automatically and can't be removed or added.");
+
+ QLabel* mainLabel = CToolClass::explanationLabel(this,
+ tr("Configure bookshelf paths"), l1 + QString("<small><br><br>") + l2 + QString("</small>"));
+ mainLayout->addWidget(mainLabel);
+
+ QString swordConfPath = instbackend::swordConfigFilename();
+ QLabel* confPathLabel = new QLabel(tr("Configuration file for the paths is: ").append("<b>%1</b>").arg(swordConfPath), this);
+ confPathLabel->setWordWrap(true);
+ mainLayout->addWidget(confPathLabel);
+
+
+ m_swordPathListBox = new QTreeWidget(this);
+ m_swordPathListBox->header()->hide();
+
+ QDir swordDir = instbackend::swordDir();
+ QStringList targets = instbackend::targetList();
+ foreach (QString pathname, targets) {
+ if (pathname.isEmpty() || QDir(pathname) == swordDir) continue;
+ new QTreeWidgetItem(m_swordPathListBox, QStringList(pathname) );
+ }
+
+ viewLayout->addWidget(m_swordPathListBox);
+
+ QVBoxLayout* buttonLayout = new QVBoxLayout();
+
+ m_addButton = new QPushButton(tr("Add..."), this);
+ m_addButton->setToolTip(tr("Add new path"));
+ m_addButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::paths::add_icon));
+ connect(m_addButton, SIGNAL(clicked()), this, SLOT(slotAddClicked()));
+ buttonLayout->addWidget(m_addButton);
+
+ m_editButton = new QPushButton(tr("Edit..."), this);
+ m_editButton->setToolTip(tr("Edit the selected path"));
+ m_editButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::paths::edit_icon));
+ connect(m_editButton, SIGNAL(clicked()), this, SLOT(slotEditClicked()));
+ buttonLayout->addWidget(m_editButton);
+
+ m_removeButton = new QPushButton(tr("Remove"), this);
+ m_removeButton->setToolTip(tr("Remove the selected path"));
+ m_removeButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::paths::remove_icon));
+ connect(m_removeButton, SIGNAL(clicked()), this, SLOT(slotRemoveClicked()));
+ buttonLayout->addWidget(m_removeButton);
+
+ QSpacerItem* spacerItem = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
+ buttonLayout->addItem(spacerItem);
+
+ viewLayout->addLayout(buttonLayout);
+ mainLayout->addLayout(viewLayout);
+
+ QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
+ buttonBox->setOrientation(Qt::Horizontal);
+ buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok);
+ util::prepareDialogBox(buttonBox);
+ mainLayout->addWidget(buttonBox);
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+
+}
+
+void BtInstallPathDialog::slotEditClicked() {
+ if (QTreeWidgetItem* i = m_swordPathListBox->currentItem()) {
+ QString dirname = QFileDialog::getExistingDirectory(this, tr("Choose directory"), i->text(0), QFileDialog::ShowDirsOnly|QFileDialog::DontResolveSymlinks);
+
+ if (dirname.isEmpty()) { // if user cancelled the dialog
+ return;
+ }
+ QDir dir = QDir(dirname);
+ if (dir.isReadable()) {
+ const QFileInfo fi( dir.canonicalPath() );
+ if (!fi.exists() || !fi.isWritable()) {
+ const int result = QMessageBox::warning(this, tr("Use Directory?"), tr("This directory is not writable, so works can not be installed here using BibleTime. Do you want to use this directory instead of the previous value?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
+ if (result != QMessageBox::Yes) return;
+ }
+ i->setText(0, dir.absolutePath()); // absolute, not canonical
+ }
+ }
+}
+
+void BtInstallPathDialog::slotAddClicked() {
+ QString dirname = QFileDialog::getExistingDirectory(this, tr("Choose directory"), "", QFileDialog::ShowDirsOnly|QFileDialog::DontResolveSymlinks);
+ if (dirname.isEmpty()) { // if user cancelled the dialog
+ return;
+ }
+ QDir dir = QDir(dirname);
+ if (dir.isReadable()) {
+ const QFileInfo fi( dir.canonicalPath() );
+ if (!fi.exists() || !fi.isWritable()) {
+ const int result = QMessageBox::warning(this, tr("Warning"), tr("This directory is not writable, so works can not be installed here using BibleTime. Do you still want to add it to the list of bookshelf directories?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
+ if (result != QMessageBox::Yes) {
+ return;
+ }
+ }
+ new QTreeWidgetItem(m_swordPathListBox, QStringList(dir.canonicalPath()) );
+ }
+}
+
+void BtInstallPathDialog::slotRemoveClicked() {
+ QTreeWidgetItem* i = m_swordPathListBox->currentItem();
+ if (i) {
+ delete i;
+ }
+}
+
+void BtInstallPathDialog::writeSwordConfig()
+{
+ qDebug("BtInstallPathDialog::writeSwordConfig");
+ if (m_swordPathListBox->topLevelItemCount() >= 0) {
+ QStringList targets;
+ QTreeWidgetItemIterator it(m_swordPathListBox);
+ while (*it) {
+ if (!(*it)->text(0).isEmpty()) {
+ targets << (*it)->text(0);
+ }
+ ++it;
+ }
+ qDebug() << "save the target list" << targets;
+ instbackend::setTargetList(targets); //creates new Sword config
+ }
+}
+
+void BtInstallPathDialog::accept()
+{
+ writeSwordConfig();
+ QDialog::accept();
+}
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h
new file mode 100644
index 0000000..c3b56ac
--- /dev/null
+++ b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h
@@ -0,0 +1,44 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTINSTALLPATHDIALOG_H
+#define BTINSTALLPATHDIALOG_H
+
+#include <QDialog>
+
+class QPushButton;
+class QTreeWidget;
+
+
+class BtInstallPathDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ BtInstallPathDialog();
+
+public slots:
+ virtual void accept();
+
+private slots:
+ void slotAddClicked();
+ void slotRemoveClicked();
+ void slotEditClicked();
+
+private:
+ void writeSwordConfig();
+
+private:
+ QPushButton* m_editButton;
+ QPushButton* m_addButton;
+ QPushButton* m_removeButton;
+ QTreeWidget* m_swordPathListBox;
+
+};
+
+#endif
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp
new file mode 100644
index 0000000..2f60fc9
--- /dev/null
+++ b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp
@@ -0,0 +1,261 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btinstallprogressdialog.h"
+
+#include "btinstallthread.h"
+
+#include "util/ctoolclass.h"
+#include "util/cpointers.h"
+#include "backend/managers/cswordbackend.h"
+
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+#include <QDialog>
+#include <QHeaderView>
+#include <QProgressBar>
+#include <QPushButton>
+#include <QVBoxLayout>
+#include <QApplication>
+#include <QCloseEvent>
+#include <QMultiMap>
+
+#include <QDebug>
+
+
+BtInstallProgressDialog::BtInstallProgressDialog(QWidget* parent, QTreeWidget* selectedModulesTreeWidget, QString destination)
+ : QDialog(parent)
+{
+ // we want this dialog to be deleted when user closes it or the downloads are completed
+ setAttribute(Qt::WA_DeleteOnClose, true);
+ setWindowTitle(tr("Install Progress"));
+ //create the dialog which shows the status and lets the user stop installation
+ m_statusWidget = new QTreeWidget();
+ m_statusWidget->setRootIsDecorated(false);
+ m_statusWidget->setHeaderLabels(QStringList(tr("Work")) << tr("Progress") << QString::null);
+ m_statusWidget->header()->setStretchLastSection(false);
+ m_statusWidget->header()->setResizeMode(1, QHeaderView::Stretch);
+ m_statusWidget->header()->setMovable(false);
+ //m_statusWidget->setColumnWidth(1, CToolClass::mWidth(m_statusWidget, 2));
+
+ foreach (QTreeWidgetItem* sourceItem, selectedModulesTreeWidget->invisibleRootItem()->takeChildren()) {
+ // create items and threads for modules under this source
+ foreach (QTreeWidgetItem* moduleItem, sourceItem->takeChildren()) {
+ if (moduleItem->checkState(0) == Qt::Checked) {
+ // create a thread for this module
+ BtInstallThread* thread = new BtInstallThread(this, moduleItem->text(0), sourceItem->text(0), destination);
+ m_waitingThreads.insert(sourceItem->text(0), thread);
+ m_threadsByModule.insert(moduleItem->text(0), thread);
+ // progress widget/item
+ QPushButton* stopButton = new QPushButton(tr("Stop"), m_statusWidget);
+ stopButton->setFixedSize(stopButton->sizeHint());
+
+ // the item
+ QTreeWidgetItem* progressItem = new QTreeWidgetItem(m_statusWidget);
+ m_statusWidget->setColumnWidth(2, stopButton->sizeHint().width());
+ progressItem->setSizeHint(2, stopButton->sizeHint());
+ progressItem->setText(0, moduleItem->text(0));
+ progressItem->setFlags(Qt::ItemIsEnabled);
+ m_statusWidget->setItemWidget(progressItem, 2, stopButton);
+ progressItem->setText(1, tr("Waiting for turn..."));
+
+ //connect the signals between the dialog, items and threads
+ QObject::connect(stopButton, SIGNAL(clicked()), thread, SLOT(slotStopInstall()), Qt::QueuedConnection);
+ QObject::connect(thread, SIGNAL(installStopped(QString, QString)), this, SLOT(slotOneItemStopped(QString, QString)), Qt::QueuedConnection);
+ //is this needed or is statusUpdated enough?
+ QObject::connect(thread, SIGNAL(installCompleted(QString, QString, int)), this, SLOT(slotOneItemCompleted(QString, QString, int)), Qt::QueuedConnection);
+ QObject::connect(thread, SIGNAL(statusUpdated(QString, int)), this, SLOT(slotStatusUpdated(QString, int)), Qt::QueuedConnection);
+ QObject::connect(thread, SIGNAL(downloadStarted(QString)), this, SLOT(slotDownloadStarted(QString)), Qt::QueuedConnection);
+
+ QObject::connect(thread, SIGNAL(preparingInstall(QString, QString)), this, SLOT(slotInstallStarted(QString, QString)), Qt::QueuedConnection);
+
+ }
+ }
+ }
+
+ m_statusWidget->setMinimumWidth(m_statusWidget->size().width());
+ QPushButton* stopAllButton = new QPushButton(tr("Stop All"), this);
+
+ QVBoxLayout* layout = new QVBoxLayout(this);
+ layout->addWidget(m_statusWidget);
+ layout->addWidget(stopAllButton);
+
+ connect(stopAllButton, SIGNAL(clicked()), SLOT(slotStopInstall()) );
+
+ qApp->processEvents();
+
+ startThreads();
+
+}
+
+void BtInstallProgressDialog::startThreads()
+{
+ // remove all the updated modules from the backend module list at once
+ //foreach (QString mName, m_threadsByModule.keys()) {
+ //}
+ //QList<CSwordModuleInfo*> CPointers::backend()->takeModulesFromList(m_threadsByModule.keys());
+ qDebug() << "start threads...";
+ //loop through the multimap of the waiting threads, start at most 3 threads for each source
+ QMultiMap<QString, BtInstallThread*>::iterator threadIterator = m_waitingThreads.end();
+// concurrency is disabled for now
+// while (threadIterator != m_waitingThreads.end()) {
+// QString sourceName = threadIterator.key();
+// qDebug() << sourceName;
+// if (m_runningThreads.values(sourceName).count() < 3) {
+// BtInstallThread* t = threadIterator.value();
+// m_runningThreads.insert(sourceName, t);
+// threadIterator = m_waitingThreads.erase(threadIterator);
+// t->start();
+// }
+// else ++threadIterator;
+// }
+ //non-concurrent
+ if (threadIterator != m_waitingThreads.begin()) {
+ // go to the last item which is actually the first in the visible list
+ // because the iterator is reversed compared to insert order
+ threadIterator--;
+ QString sourceName = threadIterator.key();
+ BtInstallThread* t = threadIterator.value();
+ m_runningThreads.insert(sourceName, t);
+ threadIterator = m_waitingThreads.erase(threadIterator);
+ t->start();
+ }
+
+ qDebug("BtInstallProgressDialog::startThreads end");
+}
+
+BtInstallProgressDialog::~BtInstallProgressDialog()
+{}
+
+
+void BtInstallProgressDialog::slotOneItemCompleted(QString module, QString source, int status)
+{
+ QString message;
+ //status comes from the sword installer. TODO: Additionally we should check that there are files really installed.
+ if (status != 0) {
+ message = tr("Failed");
+ }
+ else {
+ message = tr("Completed");
+ }
+ oneItemStoppedOrCompleted(module, source, message);
+}
+
+void BtInstallProgressDialog::slotOneItemStopped(QString module, QString source)
+{
+ oneItemStoppedOrCompleted(module, source, tr("Cancelled"));
+}
+
+void BtInstallProgressDialog::oneItemStoppedOrCompleted(QString module, QString source, QString statusMessage)
+{
+ qDebug() << "\n**********************************\nBtInstallProgressDialog::oneItemStoppedOrCompleted" << module << statusMessage << "\n******************************************";
+ // update the list item
+ m_statusWidget->setItemWidget(getItem(module), 1, 0);
+ getItem(module)->setText(1, statusMessage);
+ m_statusWidget->itemWidget(getItem(module), 2)->setEnabled(false);
+ getItem(module)->setDisabled(true);
+
+ qDebug() << "remove from threads maps" << source << m_threadsByModule.value(module);
+ m_runningThreads.remove(source, m_threadsByModule.value(module));
+ m_waitingThreads.remove(source, m_threadsByModule.value(module));
+
+//concurrency is disabled for now
+// //start a waiting thread if there are any
+// QList<BtInstallThread*> threadsForSource = m_waitingThreads.values(source);
+// qDebug() << threadsForSource;
+// if (!threadsForSource.isEmpty()) {
+// qDebug() << "Threads are waiting for turn";
+// BtInstallThread* thread = threadsForSource.at(0);
+// m_waitingThreads.remove(source, thread);
+// m_runningThreads.insert(source, thread);
+// thread->start();
+// }
+
+ //non-concurrent
+ QMultiMap<QString, BtInstallThread*>::iterator threadIterator = m_waitingThreads.end();
+ if (m_runningThreads.size() == 0 && threadIterator != m_waitingThreads.begin()) {
+ threadIterator--; // the last item
+ QString sourceName = threadIterator.key();
+ BtInstallThread* t = threadIterator.value();
+ m_runningThreads.insert(sourceName, t);
+ threadIterator = m_waitingThreads.erase(threadIterator);
+ t->start();
+ }
+
+ if (threadsDone()) {
+ qDebug() << "close the dialog";
+ close();
+ }
+}
+
+void BtInstallProgressDialog::slotStopInstall()
+{
+ qDebug("BtInstallProgressDialog::slotStopInstall");
+
+ // Clear the waiting threads map, stop all running threads.
+
+ m_waitingThreads.clear();
+ if (m_runningThreads.count() > 0) {
+ foreach(BtInstallThread* thread, m_runningThreads) {
+ thread->slotStopInstall();
+ }
+ } else {
+ close();
+ }
+}
+
+void BtInstallProgressDialog::slotStatusUpdated(QString module, int status)
+{
+ //qDebug("BtInstallProgressDialog::slotStatusUpdated");
+ //qDebug() << "module:" << module << "status:" << status;
+ // find the progress bar for this module and update the value
+ QWidget* itemWidget = m_statusWidget->itemWidget(getItem(module) , 1);
+ QProgressBar* bar = dynamic_cast<QProgressBar*>(itemWidget);
+ if (bar) bar->setValue(status);
+}
+
+void BtInstallProgressDialog::slotInstallStarted(QString module, QString)
+{
+ getItem(module)->setText(1, tr("Preparing install..."));
+}
+
+void BtInstallProgressDialog::slotDownloadStarted(QString module)
+{
+ qDebug() << "BtInstallProgressDialog::slotDownloadStarted" << module;
+ getItem(module)->setText(1, QString::null);
+ //m_statusWidget->itemWidget(getItem(module), 1)->setVisible(true);
+
+ QProgressBar* bar = new QProgressBar(m_statusWidget);
+ bar->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
+ bar->setValue(0);
+ m_statusWidget->setItemWidget(getItem(module), 1, bar);
+}
+
+QTreeWidgetItem* BtInstallProgressDialog::getItem(QString moduleName)
+{
+ //qDebug() << "BtInstallProgressDialog::getItem" << moduleName;
+ return m_statusWidget->findItems(moduleName, Qt::MatchExactly).at(0);
+}
+
+void BtInstallProgressDialog::closeEvent(QCloseEvent* event)
+{
+ qDebug("BtInstallProgressDialog::closeEvent");
+
+ if (event->spontaneous()) {
+ event->ignore();
+ return;
+ }
+ // other parts of the UI/engine must be updated
+ CPointers::backend()->reloadModules(CSwordBackend::AddedModules);
+}
+
+bool BtInstallProgressDialog::threadsDone()
+{
+ return (m_waitingThreads.count() == 0 && m_runningThreads.count() == 0);
+}
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h
new file mode 100644
index 0000000..67aa8fb
--- /dev/null
+++ b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h
@@ -0,0 +1,70 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTINSTALLPROGRESSDIALOG_H
+#define BTINSTALLPROGRESSDIALOG_H
+
+#include <QDialog>
+#include <QString>
+#include <QMultiMap>
+
+class QTreeWidget;
+class QTreeWidgetItem;
+
+class BtInstallThread;
+
+
+/**
+
+*/
+class BtInstallProgressDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ BtInstallProgressDialog(QWidget* parent, QTreeWidget* selectedModulesTreeWidget, QString destination);
+
+ ~BtInstallProgressDialog();
+
+public slots:
+ void slotOneItemCompleted(QString module, QString source, int status);
+ void slotOneItemStopped(QString module, QString source);
+ void slotStopInstall();
+ void slotStatusUpdated(QString module, int status);
+ void slotDownloadStarted(QString module);
+ void slotInstallStarted(QString module, QString);
+
+protected:
+ /**
+ * Handles closing by the window close button, Cancel (Stop) All button, or completing
+ * the downloads.
+ */
+ virtual void closeEvent(QCloseEvent* event);
+
+//signals:
+// void swordSetupChanged();
+
+private:
+
+ //TODO: using maps is tedious and error prone. Find better solution for handling the modules
+ // and their states.
+ QMultiMap<QString, BtInstallThread*> m_waitingThreads;
+ QMultiMap<QString, BtInstallThread*> m_runningThreads;
+ QMap<QString, BtInstallThread*> m_threadsByModule;
+ //QList<BtInstallThread*> m_doneThreads;
+
+ QTreeWidget* m_statusWidget;
+
+private:
+ QTreeWidgetItem* getItem(QString moduleName);
+ bool threadsDone();
+ void startThreads();
+ void oneItemStoppedOrCompleted(QString module, QString source, QString message);
+};
+
+#endif
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallthread.cpp b/src/frontend/bookshelfmanager/installpage/btinstallthread.cpp
new file mode 100644
index 0000000..adab4fa
--- /dev/null
+++ b/src/frontend/bookshelfmanager/installpage/btinstallthread.cpp
@@ -0,0 +1,199 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btinstallthread.h"
+
+#include "frontend/bookshelfmanager/btinstallmgr.h"
+#include "frontend/bookshelfmanager/instbackend.h"
+#include "util/cpointers.h"
+#include "backend/managers/cswordbackend.h"
+
+#include <QApplication>
+#include <QString>
+#include <QThread>
+#include <QDir>
+
+#include <QDebug>
+
+// sword
+#include <filemgr.h>
+
+BtInstallThread::BtInstallThread(QObject* parent, QString moduleName, QString sourceName, QString destinationName)
+ : QThread(parent),
+ done(false),
+ m_module(moduleName),
+ m_destination(destinationName),
+ m_source(sourceName),
+ m_cancelled(false),
+ m_installSource(instbackend::source(sourceName)),
+ m_backendForSource(instbackend::backend(m_installSource))
+{
+ m_iMgr = new BtInstallMgr();
+}
+
+
+BtInstallThread::~BtInstallThread()
+{
+ delete m_iMgr;
+}
+
+void BtInstallThread::run()
+{
+ qDebug() << "****************************************\nBtInstallThread::run, mod:" << m_module << "\n************************************";
+
+
+ emit preparingInstall(m_module, m_source);
+
+ //make sure target/mods.d and target/modules exist
+ //TODO: move this to some common precondition
+ QDir dir(m_destination);
+ if (!dir.exists()) {
+ dir.mkdir(m_destination);
+ qDebug() << "made directory" << m_destination;
+ }
+ if (!dir.exists("modules")) {
+ dir.mkdir("modules");
+ qDebug() << "made directory" << m_destination << "/modules";
+ }
+ if (!dir.exists("mods.d")) {
+ dir.mkdir("mods.d");
+ qDebug() << "made directory" << m_destination << "/mods.d";
+ }
+
+ QObject::connect(m_iMgr, SIGNAL(percentCompleted(int, int)), this, SLOT(slotManagerStatusUpdated(int, int)), Qt::QueuedConnection);
+ QObject::connect(m_iMgr, SIGNAL(downloadStarted()), this, SLOT(slotDownloadStarted()), Qt::QueuedConnection);
+
+ //check whether it's an update. If yes, remove existing module first
+ //TODO: silently removing without undo if the user cancels the update is WRONG!!!
+ removeModule();
+
+ // manager for the destination path
+ sword::SWMgr lMgr( m_destination.toLatin1() );
+
+ if (instbackend::isRemote(m_installSource)) {
+ qDebug() << "calling install";
+ int status = m_iMgr->installModule(&lMgr, 0, m_module.toLatin1(), &m_installSource);
+ if (status != 0) {
+ qWarning() << "Error with install: " << status << "module:" << m_module;
+ }
+ else {
+ done = true;
+ emit installCompleted(m_module, m_source, status);
+ }
+ }
+ else { //local source
+ emit statusUpdated(m_module, 0);
+ int status = m_iMgr->installModule(&lMgr, m_installSource.directory.c_str(), m_module.toLatin1());
+ if (status > 0) {
+ qWarning() << "Error with install: " << status << "module:" << m_module;
+ }
+ else if (status == -1) {
+ // it was terminated, do nothing
+ }
+ else {
+ emit statusUpdated(m_module, 100);
+ done = true;
+ emit installCompleted(m_module, m_source, status);
+ }
+ }
+}
+
+void BtInstallThread::slotStopInstall()
+{
+ qDebug() << "*************************************\nBtInstallThread::slotStopInstall" << m_module << "\n********************************";
+ if (!done) {
+ done = true;
+ qDebug() << "*********************************\nBtInstallThread::slotStopInstall, installing" << m_module << "was cancelled\n**************************************";
+ m_iMgr->terminate();
+ //this->terminate(); // It's dangerous to forcibly stop, but we will clean up the files
+ qDebug() << "BtInstallThread::slotStopInstall 2";
+ //qApp->processEvents();
+ // wait to terminate for some secs. We rather let the execution go on and cleaning up to fail than the app to freeze
+ int notRun = this->wait(200);
+ if (notRun) {
+ this->terminate();
+ this->wait(2);
+ qDebug() << "installthread ("<< m_module << ") terminated, delete m_iMgr";
+ delete m_iMgr; // this makes sure the ftp library will be cleaned up in the destroyer
+ m_iMgr = 0;
+ }
+ qDebug() << "BtInstallThread::slotStopInstall 3";
+ // cleanup: remove the module, remove the temp files
+ if (true) {
+ qDebug() << "BtInstallThread::slotStopInstall 4";
+ // remove the installed module, just to be sure because mgr may
+ // have been terminated when copying files
+ removeModule();
+ removeTempFiles();
+ qDebug() << "BtInstallThread::slotStopInstall will emit installStopped...";
+ emit installStopped(m_module, m_source);
+ }
+ }
+}
+
+void BtInstallThread::slotManagerStatusUpdated(int totalProgress, int /*fileProgress*/)
+{
+ //qDebug("BtInstallThread::slotManagerStatusUpdated");
+ emit statusUpdated(m_module, totalProgress);
+}
+
+void BtInstallThread::slotDownloadStarted()
+{
+ qDebug("BtInstallThread::slotDownloadStarted");
+ emit downloadStarted(m_module);
+}
+
+void BtInstallThread::removeModule()
+{
+ qDebug() << "BtInstallThread::removeModule start";
+ CSwordModuleInfo* m;
+ m = CPointers::backend()->findModuleByName(m_module);
+ if (!m) {
+ m = instbackend::backend(instbackend::source(m_destination.toLatin1()))->findModuleByName(m_module);
+ }
+ if (m) { //module found?
+ qDebug() << "BtInstallThread::removeModule, module" << m_module << "found";
+ QString prefixPath = m->config(CSwordModuleInfo::AbsoluteDataPath) + "/";
+ QString dataPath = m->config(CSwordModuleInfo::DataPath);
+ if (dataPath.left(2) == "./") {
+ dataPath = dataPath.mid(2);
+ }
+
+ if (prefixPath.contains(dataPath)) {
+ prefixPath.remove( prefixPath.indexOf(dataPath), dataPath.length() );
+ }
+ else {
+ prefixPath = QString::fromLatin1(CPointers::backend()->prefixPath);
+ }
+
+ sword::SWMgr mgr(prefixPath.toLatin1());
+ BtInstallMgr iMgr;
+ iMgr.removeModule(&mgr, m->name().toLatin1());
+ } else {
+ qDebug() << "BtInstallThread::removeModule, module" << m_module << "not found";
+ }
+}
+
+void BtInstallThread::removeTempFiles()
+{
+ qDebug("BtInstallThread::removeTempFiles start");
+
+ // (take the remote conf file for this module, take DataPath,
+ // take the absolute path of the InstallMgr)
+
+ //sword::InstallSource is = instbackend::source(m_source);
+ if (instbackend::isRemote(m_installSource)) {
+ // get the path for the module temp files
+ CSwordModuleInfo* mInfo = m_backendForSource->findModuleByName(m_module);
+ QString dataPath = mInfo->config(CSwordModuleInfo::AbsoluteDataPath);
+ qDebug() << "Delete path:" << dataPath;
+ // it's easier to use sword than qt
+ sword::FileMgr::removeDir(dataPath.toLatin1().data());
+ }
+}
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallthread.h b/src/frontend/bookshelfmanager/installpage/btinstallthread.h
new file mode 100644
index 0000000..d10db95
--- /dev/null
+++ b/src/frontend/bookshelfmanager/installpage/btinstallthread.h
@@ -0,0 +1,99 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTINSTALLTHREAD_H
+#define BTINSTALLTHREAD_H
+
+#include "frontend/bookshelfmanager/btinstallmgr.h"
+
+#include <QThread>
+
+#include <boost/scoped_ptr.hpp>
+
+class BtInstallProgressDialog;
+
+/**
+* Thread for installing a module.
+*
+* See the Qt thread documents. We have to be careful with signals and slots,
+* with other things.
+
+The main thread creates and owns the BtInstallThread object.
+When the install thread (the run() method) has been started
+the install thread object receives status update signals
+from the installmgr object. This works because these signals are sent
+from the running install thread but received in the thread object which
+lives in the main thread (note the difference between a thread object and a
+running thread). The slot of the thread object is executed in the main thread
+event loop, not in the install thread.
+
+The running thread sends update signals to the progress dialog.
+(This works because the signals are queued, i.e. the dialog is running
+in the main app event loop which queues the signals. ???)
+
+When the user cancels installing the main thread sends signal to a slot
+in the thread object. The slot is then run in the main thread, not
+in the install thread (note again the difference between a thread object and a
+running thread). That slot terminates the running install thread immediately.
+That is not the cleanest way to do it, but the Sword library has no good
+support for threads. Terminating a Sword InstallMgr takes time and leads to
+slow response. Therefore we stop installing by force and clean up the
+temporary files manually.
+
+* Terminating a thread forcibly is "dangerous and discouraged" but we have to do it,
+* I couldn't get cancelling work reliably otherwise. The Sword library is bad for threads.
+* We use ftp connection and file resources; the connection can be ignored but the files
+* have to be cleaned up after termination.
+*/
+class BtInstallThread : public QThread
+{
+ Q_OBJECT
+public:
+ BtInstallThread(QObject* parent, QString moduleName, QString sourceName, QString destinationName);
+
+ ~BtInstallThread();
+
+public slots:
+ void slotStopInstall();
+ void slotManagerStatusUpdated(int totalProgress, int fileProgress);
+ void slotDownloadStarted();
+
+public: // data member
+ bool done;
+
+protected:
+ virtual void run();
+ void removeModule();
+ void removeTempFiles();
+
+ QString m_module;
+ QString m_destination;
+ QString m_source;
+ bool m_cancelled;
+ BtInstallMgr* m_iMgr;
+ //sword::InstallSource m_installSource;
+ //BtInstallMgr m_iMgr;
+ sword::InstallSource m_installSource;
+ //TODO: it would be best to get the backend from the bookshelf manager install page
+ // where it has already been created. Could fasten the progress dialog startup.
+ boost::scoped_ptr<CSwordBackend> m_backendForSource;
+
+signals:
+ /** Emitted when the install progress status is updated. */
+ void statusUpdated(QString module, int progressPercent);
+ /** Emitted when installing has been stopped/cancelled. */
+ void installStopped(QString module, QString source);
+ /** Emitted when installing is complete. */
+ void installCompleted(QString module, QString source, int errorStatus);
+ /** Emitted when the first file download has been started. */
+ void downloadStarted(QString module);
+ void preparingInstall(QString module, QString source);
+};
+
+#endif
diff --git a/src/frontend/bookshelfmanager/installpage/btsourcearea.cpp b/src/frontend/bookshelfmanager/installpage/btsourcearea.cpp
new file mode 100644
index 0000000..2f8de1a
--- /dev/null
+++ b/src/frontend/bookshelfmanager/installpage/btsourcearea.cpp
@@ -0,0 +1,298 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btsourcearea.h"
+
+#include "frontend/bookshelfmanager/instbackend.h"
+
+#include "util/ctoolclass.h"
+#include "util/cpointers.h"
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+
+#include "backend/managers/cswordbackend.h"
+#include "frontend/btaboutmoduledialog.h"
+
+#include <installmgr.h>
+
+#include <QString>
+#include <QWidget>
+#include <QMap>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QSpacerItem>
+#include <QLabel>
+#include <QPushButton>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+#include <QHeaderView>
+
+#include <QDebug>
+#include <QTime>
+
+// ****************************************************************
+// ******** Installation source and module list widget ************
+// ****************************************************************
+
+BtSourceArea::BtSourceArea(const QString& sourceName)
+ : QWidget(),
+ m_sourceName(sourceName),
+ m_treeAlreadyInitialized(false),
+ m_remoteBackend(0) //important!
+{
+ m_checkedModules = QMap<QString, bool>();
+ qDebug() << "BtSourceArea::BtSourceArea, " << m_sourceName;
+ initView();
+}
+
+BtSourceArea::~BtSourceArea()
+{
+ delete m_remoteBackend;
+}
+
+void BtSourceArea::initView()
+{
+ qDebug("BtSourceArea::initView");
+ QVBoxLayout *mainLayout = new QVBoxLayout(this);
+ //QHBoxLayout *refreshLabelLayout = new QHBoxLayout();
+ //QLabel *refreshLabel = new QLabel(tr("Last refreshed:"));
+ //m_refreshTimeLabel = new QLabel();
+ //QSpacerItem *refreshLabelSpacer = new QSpacerItem(201, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
+
+ //refreshLabelLayout->addWidget(refreshLabel);
+ //refreshLabelLayout->addWidget(m_refreshTimeLabel);
+ //refreshLabelLayout->addItem(refreshLabelSpacer);
+ // TODO: or would it be better to integrate this information into the tooltip
+ // of the source tab?
+ //mainLayout->addLayout(refreshLabelLayout);
+
+ // source related button row
+ QHBoxLayout *sourceLayout = new QHBoxLayout();
+ m_refreshButton = new QPushButton(tr("Refresh..."));
+ m_refreshButton->setToolTip(tr("Refresh the list of works from this source"));
+ m_refreshButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::installpage::refresh_icon));
+ //m_refreshButton->setEnabled(false);
+ QSpacerItem *sourceSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
+ //m_editButton = new QPushButton(tr("Edit..."));
+ //m_editButton->setEnabled(false); // TODO after writing the edit widget
+ m_deleteButton = new QPushButton(tr("Delete..."));
+ m_deleteButton->setToolTip(tr("Delete this source"));
+ m_deleteButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::installpage::delete_icon));
+ //m_deleteButton->setEnabled(false);
+ m_addButton = new QPushButton(tr("Add..."));
+ m_addButton->setToolTip(tr("Add new source"));
+ m_addButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::installpage::add_icon));
+
+ sourceLayout->addWidget(m_refreshButton);
+ sourceLayout->addItem(sourceSpacer);
+ //sourceLayout->addWidget(m_editButton);
+ sourceLayout->addWidget(m_deleteButton);
+ sourceLayout->addWidget(m_addButton);
+
+ mainLayout->addLayout(sourceLayout);
+ // There are no views for the stack yet, see initSources
+ m_view = new QTreeWidget(this);
+ m_view->setHeaderLabels(QStringList() << tr("Work") << tr("Description"));
+ m_view->setColumnWidth(0, CToolClass::mWidth(m_view, 20));
+ mainLayout->addWidget(m_view);
+
+ connect(m_view, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), SLOT(slotItemDoubleClicked(QTreeWidgetItem*, int)));
+ connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), SLOT(slotSwordSetupChanged()));
+ connect(this, SIGNAL(signalCreateTree()), SLOT(slotCreateTree()), Qt::QueuedConnection);
+}
+
+QSize BtSourceArea::sizeHint() const
+{
+ return QSize(100, m_refreshButton->height() + (m_view->header()->height() * 5));
+}
+
+void BtSourceArea::initTreeFirstTime()
+{
+ if (!m_treeAlreadyInitialized) {
+ createModuleTree();
+ m_treeAlreadyInitialized = true;
+ }
+}
+
+void BtSourceArea::createModuleTree()
+{
+ qDebug("BtSourceArea::createModuleTree start");
+ // Start creating tree with a queued connection.
+ // This makes showing the dialog possible even before the tree is initialized.
+ emit signalCreateTree();
+}
+void BtSourceArea::slotCreateTree()
+{
+ qDebug()<<"BtSourceArea::slotCreateTree" << QTime::currentTime ();
+ //let the dialog become visible
+ QCoreApplication::processEvents();
+ // Creating the view and populating list may take time
+ QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
+
+ // disconnect the signal so that we don't have to run functions for every module
+ // (note: what to do if we want to restore the item selection when rebuilding?
+ disconnect(m_view, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotSelectionChanged(QTreeWidgetItem*, int)) );
+ m_view->clear();
+
+ // TODO: if the tree already exists for this source,
+ // maybe the selections should be preserved
+ m_checkedModules.clear();
+
+ sword::InstallSource is = instbackend::source(m_sourceName);
+ delete m_remoteBackend; // the old one can be deleted
+ m_remoteBackend = instbackend::backend(is);
+ Q_ASSERT(m_remoteBackend);
+ m_moduleList = m_remoteBackend->moduleList();
+
+ // give the list to BTModuleTreeItem, create filter to remove
+ // those modules which are installed already
+ InstalledFilter alreadyInstalledFilter(m_sourceName);
+ QList<BTModuleTreeItem::Filter*> filterList;
+ filterList.append(&alreadyInstalledFilter);
+ BTModuleTreeItem rootItem(filterList, BTModuleTreeItem::CatLangMod, &m_moduleList);
+
+ addToTree(&rootItem, m_view->invisibleRootItem());
+ QCoreApplication::processEvents();
+ // receive signal when user checks modules
+ connect(m_view, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotSelectionChanged(QTreeWidgetItem*, int)) );
+ QApplication::restoreOverrideCursor();
+ qDebug()<< "BtSourceArea::createModuleTree end"<< QTime::currentTime ();
+}
+
+void BtSourceArea::addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem)
+{
+ //qDebug()<<"BtSourceArea::addToTree "<<item->text();
+ //qDebug() << "BTMTItem type: " << item->type();
+
+ foreach (BTModuleTreeItem* i, item->children()) {
+ addToTree(i, new QTreeWidgetItem(widgetItem));
+ }
+ if (item->type() != BTModuleTreeItem::Root) {
+ CSwordModuleInfo* mInfo = item->moduleInfo();
+ widgetItem->setText(0, item->text());
+ if (item->type() == BTModuleTreeItem::Category || item->type() == BTModuleTreeItem::Language) {
+ //qDebug() << "item"<<item->text()<< "was cat or lang";
+ widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsTristate);
+ }
+ if (item->type() == BTModuleTreeItem::Module) {
+ //qDebug() << "item"<<item->text()<< "was a module";
+ widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
+ widgetItem->setCheckState(0, Qt::Unchecked);
+
+ CSwordModuleInfo* const installedModule = CPointers::backend()->findModuleByName(mInfo->name());
+ QString installedV;
+
+ if (!installedModule) {
+ // possible TODO: save the module list of a source before refreshing,
+ // compare after refreshing, mark the newly added modules
+ //if not newly added:
+ //state: installable (no indicator)
+ //else: status: newly added, color yellow
+ } else { // the module is already installed
+ QBrush bg(QColor(255,153,153));
+ widgetItem->setBackground(0, bg);
+ widgetItem->setBackground(1, bg);
+ installedV = QString(installedModule->config(CSwordModuleInfo::ModuleVersion).toLatin1());
+ // set the color for the parent items
+ QTreeWidgetItem* parent1 = widgetItem->parent();
+ if (parent1) {
+ parent1->setBackground(0,bg);
+ parent1->setBackground(1,bg);
+ QTreeWidgetItem* parent2 = parent1->parent();
+ if (parent2) {
+ parent2->setBackground(0,bg);
+ parent2->setBackground(1,bg);
+ }
+ }
+ }
+
+
+ QString descr(mInfo->config(CSwordModuleInfo::Description));
+ QString toolTipText = CToolClass::remoteModuleToolTip(mInfo, installedV);
+
+ widgetItem->setText(1, descr);
+ widgetItem->setToolTip(0, toolTipText);
+ widgetItem->setToolTip(1, toolTipText);
+ }
+ }
+}
+
+QTreeWidget* BtSourceArea::treeWidget()
+{
+ return m_view;
+}
+
+// return the selected modules
+QMap<QString, bool>* BtSourceArea::selectedModules()
+{
+ return &m_checkedModules;
+}
+
+// when a module is checked/unchecked
+void BtSourceArea::slotSelectionChanged(QTreeWidgetItem* item, int column)
+{
+ //qDebug("BtSourceArea::slotSelectionChanged");
+ // modify the internal list of selected (actually checked) modules
+ // if() leaves groups away
+ if (!item->childCount() && column == 0) {
+ foreach (CSwordModuleInfo* module, m_moduleList) {
+ if (module->name() == item->text(0)) {
+ if (item->checkState(0) == Qt::Checked) {
+ qDebug() << module->name() << "was checked";
+ m_checkedModules.insert(module->name(), true);
+ } else {
+ qDebug() << module->name() << "was unchecked";
+ m_checkedModules.remove(module->name());
+ }
+ emit signalSelectionChanged(m_sourceName, m_checkedModules.count());
+ break;
+ }
+ }
+ }
+}
+
+void BtSourceArea::slotItemDoubleClicked(QTreeWidgetItem* item, int /*column*/)
+{
+ CSwordModuleInfo* mInfo = m_remoteBackend->findModuleByName(item->text(0));
+ if (mInfo) {
+ BTAboutModuleDialog* dialog = new BTAboutModuleDialog(this, mInfo);
+ dialog->show();
+ dialog->raise();
+ }
+}
+
+BtSourceArea::InstalledFilter::InstalledFilter(QString sourceName)
+ : BTModuleTreeItem::Filter(),
+ m_source(instbackend::source(sourceName)),
+ m_swordBackend(instbackend::backend(m_source))
+{
+ // these are set once to optimize away repeated calls
+ // m_source, m_swordBackend
+
+}
+//filter out already installed, not updateable modules
+bool BtSourceArea::InstalledFilter::filter(CSwordModuleInfo* mInfo)
+{
+ //qDebug() << "BtSourceArea::InstalledFilter::filter, module " << mInfo->name();
+ CSwordModuleInfo* const installedModule = CPointers::backend()->findModuleByName(mInfo->name());
+ if (installedModule) {
+ //qDebug("already installed, check if it's an update...");
+ const sword::SWVersion installedVersion(installedModule->config(CSwordModuleInfo::ModuleVersion).toLatin1());
+ const sword::SWVersion newVersion(mInfo->config(CSwordModuleInfo::ModuleVersion).toLatin1());
+ if (installedVersion >= newVersion) {
+ return false;
+ }
+ }
+ return true;
+}
+
+void BtSourceArea::slotSwordSetupChanged()
+{
+ createModuleTree();
+}
diff --git a/src/frontend/bookshelfmanager/installpage/btsourcearea.h b/src/frontend/bookshelfmanager/installpage/btsourcearea.h
new file mode 100644
index 0000000..814bde8
--- /dev/null
+++ b/src/frontend/bookshelfmanager/installpage/btsourcearea.h
@@ -0,0 +1,97 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTSOURCEAREA_H
+#define BTSOURCEAREA_H
+
+#include "backend/btmoduletreeitem.h"
+
+#include <boost/scoped_ptr.hpp>
+
+#include <installmgr.h>
+
+#include <QWidget>
+#include <QMap>
+#include <QApplication>
+
+class QTreeWidget;
+class QTreeWidgetItem;
+class QLabel;
+class QPushButton;
+
+/**
+* Area for one install source.
+*
+* - Tree widget for modules
+* - Buttons for handling the source(s): refresh, edit, remove, add
+*
+* Each source has
+* QTreeWidget, populated with the module tree if the source
+* module list is in a local cache. Refreshing the source refreshes
+* the cache and rebuilds the module tree. Sources are not refreshed
+* automatically, only by the user action, one source at a time.
+*/
+class BtSourceArea : public QWidget
+{
+ Q_OBJECT
+
+ friend class BtSourceWidget;
+public:
+
+ struct InstalledFilter : BTModuleTreeItem::Filter {
+ InstalledFilter(QString sourceName);
+ bool filter(CSwordModuleInfo*);
+ sword::InstallSource m_source;
+ boost::scoped_ptr<CSwordBackend> m_swordBackend;
+ };
+
+ BtSourceArea(const QString& sourceName);
+ ~BtSourceArea();
+
+ void initView();
+ /** Reimplemented from QWidget. */
+ virtual QSize sizeHint() const;
+ void initTreeFirstTime();
+ QTreeWidget* treeWidget();
+
+ QMap<QString, bool>* selectedModules();
+
+public slots:
+ void slotSwordSetupChanged();
+ /** Create a module tree for a tree widget */
+ void createModuleTree();
+
+signals:
+ void signalSelectionChanged(QString sourceName, int selectedCount);
+ void signalCreateTree();
+
+private slots:
+ void slotCreateTree();
+ void slotSelectionChanged(QTreeWidgetItem* item, int column);
+ void slotItemDoubleClicked(QTreeWidgetItem* item, int column);
+private:
+ void addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem);
+
+ QString m_sourceName;
+ bool m_treeAlreadyInitialized;
+ QMap<QString, bool> m_checkedModules;
+ CSwordBackend* m_remoteBackend; // needed for the module list
+ QList<CSwordModuleInfo*> m_moduleList;
+
+ QTreeWidget* m_view;
+ QLabel* m_refreshTimeLabel;
+ QPushButton* m_refreshButton;
+ QPushButton* m_editButton;
+ QPushButton* m_deleteButton;
+ QPushButton* m_addButton;
+
+
+};
+
+#endif
diff --git a/src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp b/src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp
new file mode 100644
index 0000000..586a680
--- /dev/null
+++ b/src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp
@@ -0,0 +1,403 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btsourcewidget.h"
+
+#include "btinstallpage.h"
+#include "btsourcearea.h"
+#include "btinstallprogressdialog.h"
+#include "btinstallmodulechooserdialog.h"
+
+#include "frontend/bookshelfmanager/btmodulemanagerdialog.h"
+#include "frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h"
+#include "frontend/bookshelfmanager/btinstallmgr.h"
+#include "frontend/bookshelfmanager/instbackend.h"
+
+
+#include <QString>
+#include <QWidget>
+#include <QTabWidget>
+#include <QMessageBox>
+#include <QProgressDialog>
+#include <QPushButton>
+#include <QApplication>
+#include <QFileInfo>
+#include <QTabBar>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+#include <QHBoxLayout>
+#include <QLabel>
+
+// ****************************************************************
+// ******** Tab Widget that holds source widgets ******************
+// ****************************************************************
+
+BtSourceWidget::BtSourceWidget(BtInstallPage* parent)
+ : QTabWidget(parent),
+ m_page(parent)
+{
+ qDebug("BtSourceWidget::BtSourceWidget start");
+ initSources();
+
+ // TODO: choose the page from config
+
+}
+
+BtSourceArea* BtSourceWidget::area()
+{
+ return dynamic_cast<BtSourceArea*>(currentWidget());
+}
+
+QString BtSourceWidget::currentSourceName()
+{
+ qDebug() << "BtSourceWidget::currentSourceName: " << m_sourceNameList.at(currentIndex());
+ return m_sourceNameList.at(currentIndex());
+}
+
+void BtSourceWidget::initSourceConnections()
+{
+ qDebug("void BtSourceWidget::initSourceConnections() start");
+ if (area()) {
+ connect(area()->m_refreshButton, SIGNAL(clicked()), SLOT(slotRefresh()));
+ //connect(area()->m_editButton, SIGNAL(clicked()), SLOT(slotEdit()));
+ connect(area()->m_deleteButton, SIGNAL(clicked()), SLOT(slotDelete()));
+ connect(area()->m_addButton, SIGNAL(clicked()), SLOT(slotAdd()));
+ connect(area(), SIGNAL(signalSelectionChanged(QString, int)), SLOT(slotModuleSelectionChanged(QString, int)) );
+ }
+ qDebug("void BtSourceWidget::initSourceConnections() end");
+}
+
+void BtSourceWidget::slotEdit()
+{
+ qDebug("BtSourceWidget::slotEdit");
+ // open the source editor dialog
+
+ // if the source was changed, init the sources
+
+}
+
+void BtSourceWidget::slotDelete()
+{
+ qDebug("void BtSourceWidget::slotDelete() start");
+ // ask for confirmation
+ int ret = QMessageBox::warning(this, tr("Delete Source?"),
+ tr("Do you really want to delete this source?"),
+ QMessageBox::Yes | QMessageBox::No);
+
+ if (ret == QMessageBox::Yes) {
+ instbackend::deleteSource(currentSourceName());
+
+ // remove the UI elements
+ m_sourceNameList.removeAt(currentIndex());
+ QWidget* w = currentWidget();
+ removeTab(currentIndex());
+ delete w;
+ }
+}
+
+void BtSourceWidget::slotAdd()
+{
+ qDebug("void BtSourceWidget::slotAdd() start");
+ qDebug("open the old dialog, TODO: write new one");
+ sword::InstallSource newSource = CSwordSetupInstallSourcesDialog::getSource();
+ if ( !((QString)newSource.type.c_str()).isEmpty() ) { // we have a valid source to add
+ instbackend::addSource(newSource);
+ addSource(QString(newSource.caption.c_str()));
+ }
+}
+
+
+void BtSourceWidget::slotRefresh()
+{
+ qDebug("void BtSourceWidget::slotRefresh() start");
+ // (re)build the module cache for the source
+
+ QString sourceName = currentSourceName();
+
+ // quick enough, make it modal so that we don't need to take care of anything else
+ m_progressDialog = new QProgressDialog("", tr("Cancel"), 0 ,100, this);
+ m_progressDialog->setWindowTitle(tr("Refreshing Source"));
+ m_progressDialog->setMinimumDuration(0);
+
+ // TODO: get rid of the backend code, BtInstallMgr and progressdialog could handle this
+ //write method BtInstallMgr::slotRefreshCanceled()
+ connect(m_progressDialog, SIGNAL(canceled()), SLOT(slotRefreshCanceled()));
+
+ // BACKEND CODE **********************************************************
+ // would this be possible: instbackend::refreshSource( arguments );
+ qDebug("void BtSourceWidget::slotRefresh 1");
+ BtInstallMgr iMgr;
+ m_currentInstallMgr = &iMgr; //for the progress dialog
+ sword::InstallSource is = instbackend::source(sourceName);
+ bool success = false;
+ qDebug("void BtSourceWidget::slotRefresh 2");
+ // connect this directly to the dialog setValue(int) if possible
+ connect(&iMgr, SIGNAL(percentCompleted(const int, const int)), SLOT(slotRefreshCompleted(const int, const int)));
+
+ if (instbackend::isRemote(is)) {
+ m_progressDialog->show();
+ qApp->processEvents();
+ this->slotRefreshCompleted(0,0);
+ m_progressDialog->setLabelText(tr("Connecting..."));
+ m_progressDialog->setValue(0);
+ qApp->processEvents();
+ //qApp->flush();
+ //qApp->processEvents();
+ //m_progressDialog->repaint();
+ //qApp->processEvents();
+ qDebug("void BtSourceWidget::slotRefresh 3");
+ bool successful = iMgr.refreshRemoteSource( &is );
+ if (!successful ) { //make sure the sources were updated sucessfully
+ success = true;
+ m_progressDialog->setValue(100); //make sure the dialog closes
+ }
+ else {
+ qWarning("InstallMgr: refreshRemoteSources returned an error.");
+ success = false;
+ }
+ }
+ else {
+ // Local source, update the list
+ success = true;
+ }
+
+ delete m_progressDialog;
+ m_progressDialog = 0;
+
+ // rebuild the view tree and refresh the view
+ if (success) {
+ qDebug("void BtSourceWidget::slotRefresh 4");
+ area()->createModuleTree();
+ }
+}
+
+//TODO: try to move this to BtInstallMgr
+void BtSourceWidget::slotRefreshCanceled()
+{
+ qDebug("BtSourceWidget::slotRefreshCanceled");
+ Q_ASSERT(m_currentInstallMgr);
+ if (m_currentInstallMgr) {
+ m_currentInstallMgr->terminate();
+ }
+ qApp->processEvents();
+}
+
+//TODO: try to move this to progress dialog
+void BtSourceWidget::slotRefreshCompleted(const int, const int current)
+{
+ qDebug("BtSourceWidget::slotRefreshCompleted");
+ if (m_progressDialog) {
+ if (m_progressDialog->labelText() != tr("Refreshing...")) {
+ m_progressDialog->setLabelText(tr("Refreshing..."));
+ }
+ m_progressDialog->setValue(current);
+ }
+ qApp->processEvents();
+}
+
+// init the tabbar, setup the module tree for the current source
+void BtSourceWidget::initSources()
+{
+ qDebug("void BtSourceWidget::initSources() start");
+
+ // ***** Use the backend to get the list of sources *****
+ instbackend::initPassiveFtpMode();
+ QStringList sourceList = instbackend::sourceList();
+
+ // Add a default entry, the Crosswire main repository
+ // TODO: this is easy for the user, but should the edit dialog
+ // open automatically?
+ if (!sourceList.count()) {
+ sword::InstallSource is("FTP"); //default return value
+ is.caption = "Crosswire";
+ is.source = "ftp.crosswire.org";
+ is.directory = "/pub/sword/raw";
+ // passive ftp is not needed here, it's the default
+
+ instbackend::addSource(is);
+
+ sourceList = instbackend::sourceList();
+ //Q_ASSERT( sourceList.count() > 0 );
+ }
+ qDebug("void BtSourceWidget::initSources 1");
+ // Add the sources to the widget
+ foreach (QString sourceName, sourceList) {
+ addSource(sourceName);
+ }
+ // connect this after the tabs have been created,
+ // otherwise the signal is caught too early.
+ QObject::connect(this, SIGNAL(currentChanged(int)), this, SLOT(slotTabSelected(int)));
+ qDebug("void BtSourceWidget::initSources end");
+ // TODO: select the current source from the config
+ // It's important to choose something because the tree is not initialized until now
+ setCurrentIndex(0);
+ slotTabSelected(0); // setting the index wasn't enough if there were only 1 tab
+
+ if (sourceList.count() == 0) {
+ QHBoxLayout* l = new QHBoxLayout(this);
+ QLabel* message = new QLabel(QString("<i>") + tr("No sources were found in the SWORD configuration and BibleTime couldn't create a default source. Check your SWORD configuration and that the configuration path is writable. Then restart the Bookshelf Manager.") + QString("</i>"), this);
+ message->setWordWrap(true);
+ l->addWidget(message);
+ }
+}
+
+void BtSourceWidget::addSource(const QString& sourceName)
+{
+ qDebug("void BtSourceWidget::addSource(const QString& sourceName) start");
+ // The source has already been added to the backend.
+
+ QString type;
+ QString server;
+ QString path;
+ sword::InstallSource is = instbackend::source(sourceName);
+ if (instbackend::isRemote(is)) {
+ type = tr("Remote:");
+ server = is.source.c_str();
+ path = is.directory.c_str();
+ }
+ else { // local source
+ type = tr("Local:");
+ QFileInfo fi( is.directory.c_str() );
+ path = is.directory.c_str();
+ if (!(fi.isDir() )) {
+ path = path + QString(" ") + tr("Not a directory!"); //TODO: change this
+ }
+ if (!fi.isReadable()) {
+ path = path + QString(" ") + tr("Not readable!"); //TODO: change this
+ }
+ }
+
+ // Here the tab UI is created and added to the tab widget
+ BtSourceArea* area = new BtSourceArea(sourceName);
+ int tabNumber = this->addTab(area, sourceName);
+
+ // TODO: add "remote/local", server, path etc.
+ QString toolTip(QString("<p style='white-space:pre'>") + sourceName + QString("<br/><b>") + type + QString("</b> ") + server + path + QString("</p>"));
+ tabBar()->setTabToolTip(tabNumber, toolTip);
+
+ //select the new tab
+ setCurrentIndex(tabNumber);
+ m_sourceNameList.append(sourceName);
+ initSourceConnections();
+ qDebug("BtSourceWidget::addSource end");
+}
+
+//
+void BtSourceWidget::slotModuleSelectionChanged(QString sourceName, int selectedCount)
+{
+ //TODO: editing sources should update the map also
+ qDebug("BtSourceWidget::slotModuleSelectionChanged start");
+
+ int overallCount = 0;
+ m_selectedModulesCountMap.insert(sourceName, selectedCount);
+ foreach (int count, m_selectedModulesCountMap) {
+ qDebug() << "add" << count << "to overall count of selected modules";
+ overallCount += count;
+ }
+
+ if (overallCount > 0) {
+ m_page->setInstallEnabled(true);
+ } else {
+ m_page->setInstallEnabled(false);
+ }
+}
+
+void BtSourceWidget::slotTabSelected(int /*index*/)
+{
+ BtSourceArea* area = dynamic_cast<BtSourceArea*>(currentWidget());
+ if (area) area->initTreeFirstTime();
+}
+
+void BtSourceWidget::slotInstall()
+{
+ qDebug("void BtInstallPage::slotInstall start");
+
+ // check that the destination path is writable, do nothing if not and user doesn't want to continue
+ QDir dir = QDir(dynamic_cast<BtInstallPage*>(parent())->selectedInstallPath());
+ bool canWrite = true;
+ if (dir.isReadable()) {
+ const QFileInfo fi( dir.canonicalPath() );
+ if (!fi.exists() || !fi.isWritable()) {
+ canWrite = false;
+ }
+ } else {
+ canWrite = false;
+ }
+ if (!canWrite) {
+ const int result = QMessageBox::warning(this, tr("Warning"), tr("The destination directory is not writable or does not exist. Installation will fail unless this has first been fixed."), QMessageBox::Ignore|QMessageBox::Cancel, QMessageBox::Cancel);
+ if (result != QMessageBox::Ignore) {
+ return;
+ }
+ }
+
+ // create the confirmation dialog
+ // (module tree dialog, modules taken from all sources)
+ QString dlgTitle(tr("Install/Update works?"));
+ QString dlgLabel(tr("Do you really want to install these works?") +
+ QString("<br/><br/><small>") +
+ tr("Only one version of a work can be installed at the same time. Select only one if there are items marked with red.") +
+ QString("</small>"));
+
+ // with empty list we avoid creating the module tree inside the dialog code
+ QList<CSwordModuleInfo*> emptyList;
+ BtInstallModuleChooserDialog* dlg = new BtInstallModuleChooserDialog(this, dlgTitle, dlgLabel, &emptyList);
+ //dlg->setGrouping(BTModuleTreeItem::Mod);
+ QTreeWidget* treeWidget = dlg->treeWidget();
+ QTreeWidgetItem* rootItem = treeWidget->invisibleRootItem();
+
+ QStringList nameList;
+
+ // loop through each tab
+ for (int tab = 0; tab < count(); ++tab) {
+ BtSourceArea* sArea = dynamic_cast<BtSourceArea*>(widget(tab));
+ if (sArea && sArea->selectedModules()->count() > 0) {
+ // there are selected modules in the source, create items for these
+ QTreeWidgetItem* sourceItem = new QTreeWidgetItem(rootItem);
+ sourceItem->setText(0, m_sourceNameList.at(tab));
+ sourceItem->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsTristate|Qt::ItemIsEnabled);
+ foreach (QString mName, sArea->selectedModules()->keys()) {
+ dlg->initModuleItem(mName, sourceItem);
+ }
+ sourceItem->setExpanded(true);
+ }
+ }
+
+ //user accepts the dialog
+ connect(dlg, SIGNAL(modulesChanged(QList<CSwordModuleInfo*>, QTreeWidget*)), SLOT(slotInstallAccepted(QList<CSwordModuleInfo*>, QTreeWidget*)) );
+ // user checks/unchecks an item, needed for preventing double items
+ QObject::connect(treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*, int)), dlg, SLOT(slotItemChecked(QTreeWidgetItem*, int)));
+ dlg->exec();
+ // The OK signal sent by the dialog is catched with slotInstallAccepted.
+}
+
+void BtSourceWidget::slotStopInstall(QTreeWidget* /*treeWidget*/)
+{
+ qDebug() << "BtSourceWidget::slotStopInstall";
+ // not needed?
+}
+
+void BtSourceWidget::slotInstallAccepted(QList<CSwordModuleInfo*> /*modules*/, QTreeWidget* treeWidget)
+{
+ qDebug() << "BtSourceWidget::slotInstallAccepted";
+
+ //TODO: first remove all modules which will be updated from the module list
+ // but what modules? all with the same real name? (there may be _n modules...)
+
+ BtModuleManagerDialog* parentDialog = dynamic_cast<BtModuleManagerDialog*>(dynamic_cast<BtInstallPage*>(parent())->parentDialog());
+
+ BtInstallProgressDialog* dlg = new BtInstallProgressDialog(parentDialog, treeWidget, dynamic_cast<BtInstallPage*>(parent())->selectedInstallPath());
+
+ if (!parentDialog) qDebug("error, wrong parent!");
+
+ m_page->setInstallEnabled(false);
+ // the progress dialog is now modal, it can be made modeless later.
+ dlg->exec();
+
+ qDebug("BtSourceWidget::slotInstallAccepted end");
+}
diff --git a/src/frontend/bookshelfmanager/installpage/btsourcewidget.h b/src/frontend/bookshelfmanager/installpage/btsourcewidget.h
new file mode 100644
index 0000000..812c6ac
--- /dev/null
+++ b/src/frontend/bookshelfmanager/installpage/btsourcewidget.h
@@ -0,0 +1,86 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+#ifndef BTSOURCEWIDGET_H
+#define BTSOURCEWIDGET_H
+
+class CSwordModuleInfo;
+
+#include <QTabWidget>
+#include <QString>
+#include <QMap>
+
+class BtInstallMgr;
+class BtInstallPage;
+class BtSourceArea;
+
+class QProgressDialog;
+class QTreeWidget;
+
+/**
+* Tabwidget which holds the source widgets.
+* This widget implements the slots for the source action buttons and
+* applies the actions to the proper source(s).
+*/
+class BtSourceWidget : public QTabWidget
+{
+ Q_OBJECT
+public:
+ friend class BtInstallPage;
+
+ BtSourceWidget(BtInstallPage* parent);
+ virtual ~BtSourceWidget() {}
+
+ BtSourceArea* area();
+ QString currentSourceName();
+
+public slots:
+ /** Install button has been clicked. */
+ void slotInstall();
+ /** "Stop All" button clicked */
+ void slotStopInstall(QTreeWidget* treeWidget);
+
+private:
+ void initSourceConnections();
+ /** Add tabs/views for each source. */
+ void initSources();
+
+ /** Add one source to tabs/stack. */
+ void addSource(const QString& sourceName);
+
+private slots:
+
+ void slotRefresh();
+
+ void slotRefreshCanceled();
+
+ void slotRefreshCompleted(int, int);
+
+ /** Edit button clicked. */
+ void slotEdit();
+ /** Delete button clicked. */
+ void slotDelete();
+ /** Add button clicked. */
+ void slotAdd();
+ /** Modules have been checked/unchecked in the view. */
+ void slotModuleSelectionChanged(QString sourceName, int selectedCount);
+
+ void slotTabSelected(int index);
+ void slotInstallAccepted(QList<CSwordModuleInfo*> mi, QTreeWidget* treeWidget);
+
+
+
+private:
+ QStringList m_sourceNameList;
+ BtInstallPage* m_page;
+ QProgressDialog* m_progressDialog; // for refreshing
+ BtInstallMgr* m_currentInstallMgr; // for refreshing
+ QMap<QString, int> m_selectedModulesCountMap;
+};
+
+#endif
diff --git a/src/frontend/bookshelfmanager/instbackend.cpp b/src/frontend/bookshelfmanager/instbackend.cpp
new file mode 100644
index 0000000..f981f54
--- /dev/null
+++ b/src/frontend/bookshelfmanager/instbackend.cpp
@@ -0,0 +1,280 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "instbackend.h"
+
+#include "frontend/bookshelfmanager/btinstallmgr.h"
+#include "backend/managers/cswordbackend.h"
+
+#include "util/cpointers.h"
+#include "util/directoryutil.h"
+
+//Qt includes
+#include <QFile>
+#include <QFileInfo>
+#include <QDir>
+#include <QMessageBox>
+
+#include <QDebug>
+
+//Sword includes
+#include <filemgr.h>
+#include <swconfig.h>
+#include <swbuf.h>
+
+//Stl includes
+#include <functional>
+#include <map>
+#include <utility>
+
+using namespace sword;
+
+namespace instbackend {
+
+/** Adds the source described by Source to the backend. */
+bool addSource(sword::InstallSource& source)
+{
+ qDebug("backend::addSource");
+ SWConfig config(configFilename().toLatin1());
+ if (!strcmp(source.type, "FTP")) {
+ //make sure the path doesn't have a trailing slash, sword doesn't like it
+ if (source.directory[ source.directory.length()-1 ] == '/') {
+ source.directory--; //make one char shorter
+ }
+
+ config["Sources"].insert( std::make_pair(SWBuf("FTPSource"), source.getConfEnt()) );
+ }
+ else if (!strcmp(source.type, "DIR")) {
+ config["Sources"].insert( std::make_pair(SWBuf("DIRSource"), source.getConfEnt()) );
+ }
+ config.Save();
+ return true;
+}
+
+/** Returns the Source struct. */
+sword::InstallSource source(QString name)
+{
+ qDebug("backend::source");
+ BtInstallMgr mgr;
+ InstallSourceMap::iterator source = mgr.sources.find(name.toLatin1().data());
+ if (source != mgr.sources.end()) {
+ return *(source->second);
+ }
+ else { //not found in Sword, may be a local DIR source
+ SWConfig config(configFilename().toLatin1());
+ SectionMap::iterator sourcesSection = config.Sections.find("Sources");
+ if (sourcesSection != config.Sections.end()) {
+ ConfigEntMap::iterator sourceBegin =
+ sourcesSection->second.lower_bound("DIRSource");
+ ConfigEntMap::iterator sourceEnd =
+ sourcesSection->second.upper_bound("DIRSource");
+
+ while (sourceBegin != sourceEnd) {
+ InstallSource is("DIR", sourceBegin->second.c_str());
+ if (!strcmp(is.caption, name.toLatin1()) ) { //found local dir source
+ return is;
+ }
+
+ sourceBegin++;//next source
+ }
+ }
+ }
+
+ InstallSource is("EMPTY"); //default return value
+ is.caption = "unknown caption";
+ is.source = "unknown source";
+ is.directory = "unknown dir";
+ return is;
+}
+
+/** Deletes the source. */
+bool deleteSource(QString name)
+{
+ qDebug("backend::deleteSource");
+ sword::InstallSource is = source(name );
+
+ SWConfig config(configFilename().toLatin1());
+
+ //this code can probably be shortened by using the stl remove_if functionality
+ std::pair< ConfigEntMap::iterator, ConfigEntMap::iterator > range =
+ isRemote(is)
+ ? config["Sources"].equal_range("FTPSource")
+ : config["Sources"].equal_range("DIRSource");
+
+ ConfigEntMap::iterator it = range.first;
+ while (it != range.second) {
+ if (it->second == is.getConfEnt()) {
+ // qWarning("found the source!");
+ config["Sources"].erase(it);
+ break;
+ }
+ ++it;
+ }
+
+ config.Save();
+ return true; //TODO: dummy
+}
+
+/** Refreshes the remote source module list. */
+bool refreshSource(QString /*name*/)
+{
+ // not possible until manager and progressdialog work together
+ return true; //TODO: dummy
+}
+
+/** Returns the moduleinfo list for the source. Delete the pointer after using. IS THIS POSSIBLE?*/
+QList<CSwordModuleInfo*> moduleList(QString /*name*/)
+{
+ QList<CSwordModuleInfo*> list; //TODO: dummy
+ return list;
+}
+
+bool isRemote(const sword::InstallSource& source)
+{
+ return !strcmp(source.type, "FTP");
+}
+
+const QString configPath() {
+ const char *envhomedir = getenv("HOME");
+ QString confPath = QString(envhomedir ? envhomedir : ".");
+ confPath.append("/.sword/InstallMgr");
+
+ return confPath;
+}
+
+const QString configFilename() {
+ return (configPath() + "/InstallMgr.conf");
+}
+
+QStringList targetList()
+{
+ qDebug("backend::targetList");
+ QStringList names = CPointers::backend()->swordDirList();
+ return names;
+}
+
+bool setTargetList( const QStringList& targets )
+{
+ qDebug("backend::setTargetList");
+ //saves a new Sword config using the provided target list
+ //QString filename = KGlobal::dirs()->saveLocation("data", "bibletime/") + "sword.conf"; //default is to assume the real location isn't writable
+ //QString filename = util::filesystem::DirectoryUtil::getUserBaseDir().canonicalPath().append("/.sword/sword.conf");
+ //bool directAccess = false;
+ QString filename = swordConfigFilename();
+ QFileInfo i(filename);
+ QFileInfo dirInfo(i.absolutePath());
+
+
+ if ( !i.exists() && dirInfo.isWritable() ) {
+ // if the file doesn't exist but the parent is writable, create it
+ qWarning() << "The Sword config file does not exist, it has to be created";
+ QFile f(filename);
+ f.open(QIODevice::WriteOnly);
+ f.close();
+ i.refresh();
+ }
+ if ( i.exists() && i.isWritable() ) { //we can write to the file ourself
+ qDebug() << "The Sword config file is writable";
+ } else {
+ // There is no way to save to the file
+ qWarning() << "The Sword config file is not writable!";
+ QMessageBox::warning(0, QObject::tr("Can't write file"), QObject::tr("The Sword config file can't be written!"));
+ return false;
+ }
+ SWConfig conf(filename.toLocal8Bit());
+ conf.Sections.clear();
+ bool setDataPath = false;
+ for (QStringList::const_iterator it = targets.begin(); it != targets.end(); ++it) {
+ QString t = *it;
+ if (t.contains( util::filesystem::DirectoryUtil::getUserHomeDir().canonicalPath().append("/.sword") )) {
+ //we don't want $HOME/.sword in the config
+ continue;
+ }
+ else {
+ qDebug() << "Add path to the conf file" << filename << ":" << t;
+ conf["Install"].insert( std::make_pair(!setDataPath ? SWBuf("DataPath") : SWBuf("AugmentPath"), t.toLocal8Bit().data()) );
+ setDataPath = true;
+ }
+ }
+ qDebug() << "save the sword conf...";
+ conf.Save();
+ CPointers::backend()->reloadModules(CSwordBackend::PathChanged);
+ return true;
+}
+
+QStringList sourceList()
+{
+ qDebug("backend::sourceList");
+ BtInstallMgr mgr;
+ Q_ASSERT(mgr.installConf);
+
+ QStringList names;
+
+ //add Sword remote sources
+ for (InstallSourceMap::iterator it = mgr.sources.begin(); it != mgr.sources.end(); it++) {
+ names << QString::fromLocal8Bit(it->second->caption);
+ }
+
+ // Add local directory sources
+ SWConfig config(configFilename().toLatin1());
+ sword::SectionMap::iterator sourcesSection = config.Sections.find("Sources");
+ if (sourcesSection != config.Sections.end()) {
+ sword::ConfigEntMap::iterator sourceBegin = sourcesSection->second.lower_bound("DIRSource");
+ sword::ConfigEntMap::iterator sourceEnd = sourcesSection->second.upper_bound("DIRSource");
+
+ while (sourceBegin != sourceEnd) {
+ InstallSource is("DIR", sourceBegin->second.c_str());
+ names << QString::fromLatin1(is.caption.c_str());
+
+ sourceBegin++;
+ }
+ }
+
+ return names;
+}
+
+
+void initPassiveFtpMode()
+{
+ qDebug("backend::initPassiveFtpMode");
+ SWConfig config(configFilename().toLatin1());
+ config["General"]["PassiveFTP"] = "true";
+ config.Save();
+}
+const QString swordConfigFilename()
+{
+ qDebug("backend::swordConfigFilename");
+ qDebug() << util::filesystem::DirectoryUtil::getUserHomeDir().absolutePath().append("/.sword/sword.conf");
+ return util::filesystem::DirectoryUtil::getUserHomeDir().absolutePath().append("/.sword/sword.conf");
+}
+
+const QDir swordDir()
+{
+ return QDir(util::filesystem::DirectoryUtil::getUserHomeDir().absolutePath().append("/.sword/"));
+}
+
+CSwordBackend* backend( const sword::InstallSource& is)
+{
+ qDebug("backend::backend");
+ CSwordBackend* ret = 0;
+ if (isRemote(is)) {
+ ret = new CSwordBackend( QString(is.localShadow.c_str()), false );
+ }
+ else {
+ ret = new CSwordBackend( QString(is.directory.c_str()), false);
+ }
+
+ Q_ASSERT(ret);
+ if (ret) {
+ ret->initModules(CSwordBackend::OtherChange);
+ }
+ return ret;
+}
+
+}
diff --git a/src/frontend/bookshelfmanager/instbackend.h b/src/frontend/bookshelfmanager/instbackend.h
new file mode 100644
index 0000000..4f60ed9
--- /dev/null
+++ b/src/frontend/bookshelfmanager/instbackend.h
@@ -0,0 +1,74 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef INSTBACKEND_H
+#define INSTBACKEND_H
+
+#include "backend/managers/cswordbackend.h"
+
+class CSwordModuleInfo;
+
+#include <QString>
+#include <QDir>
+
+#include <installmgr.h>
+
+
+namespace instbackend {
+
+/** Adds the source to the backend. */
+bool addSource(sword::InstallSource& source);
+
+/** Returns the source struct. */
+sword::InstallSource source(QString name);
+
+/** Deletes the source. */
+bool deleteSource(QString name);
+
+/** Refreshes the remote source module list. */
+bool refreshSource(QString name);
+
+/** Returns the moduleinfo list for the source. */
+QList<CSwordModuleInfo*> moduleList(QString name);
+
+/** Tells if the source is remote or local. */
+bool isRemote(const sword::InstallSource& source);
+
+/** Returns the list of available install target paths. */
+QStringList targetList();
+
+/** Saves the list of available install target paths to the sword config. Return success indicator.*/
+bool setTargetList( const QStringList& targets );
+
+QStringList sourceList();
+
+/** Returns the path of the sword installer configuration file. */
+const QString configPath();
+
+/** Returns the name of the sword installer configuration file. */
+const QString configFilename();
+
+/** Sets the passive mode for as default.
+* TODO: see if we can en/disable this per source.
+*/
+void initPassiveFtpMode();
+
+/** Returns the file name for the Sword config file. */
+const QString swordConfigFilename();
+
+/** Returns the Sword directory ($HOME/.sword/) as a QDir, created with absolute path (not canonical).
+*/
+const QDir swordDir();
+
+/** Returns backend Sword manager for the source. */
+CSwordBackend* backend( const sword::InstallSource& is);
+
+}
+
+#endif
diff --git a/src/frontend/bookshelfmanager/removepage/btremovepage.cpp b/src/frontend/bookshelfmanager/removepage/btremovepage.cpp
new file mode 100644
index 0000000..c4324e3
--- /dev/null
+++ b/src/frontend/bookshelfmanager/removepage/btremovepage.cpp
@@ -0,0 +1,229 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+#include "btremovepage.h"
+
+
+#include "backend/btmoduletreeitem.h"
+#include "backend/config/cbtconfig.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+
+#include "util/ctoolclass.h"
+#include "util/cpointers.h"
+#include "util/directoryutil.h"
+#include "util/cresmgr.h"
+
+#include <swmgr.h>
+#include <installmgr.h>
+
+#include <QString>
+#include <QGridLayout>
+#include <QLabel>
+#include <QPushButton>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+#include <QMessageBox>
+#include <QList>
+#include <QMultiMap>
+
+#include <QDebug>
+
+
+
+BtRemovePage::BtRemovePage()
+ : BtConfigPage()
+{
+ QGridLayout* layout = new QGridLayout(this);
+ layout->setMargin(5);
+
+ layout->setSpacing(10);
+ layout->setColumnStretch(1,1);
+ layout->setRowStretch(2,1);
+
+ m_view = new QTreeWidget(this);
+ m_view->setHeaderLabels(QStringList() << tr("Work") << tr("Install path"));
+ m_view->setColumnWidth(0, CToolClass::mWidth(m_view, 20));
+
+ layout->addWidget( m_view, 2, 0, 1, 2);
+
+ m_removeButton = new QPushButton(tr("Remove..."), this);
+ m_removeButton->setToolTip(tr("Remove the selected works"));
+ m_removeButton->setIcon( util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::removepage::remove_icon) );
+ m_removeButton->setEnabled(false);
+ layout->addWidget(m_removeButton, 3, 1, Qt::AlignRight);
+
+ connect(m_view, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), SLOT(slotItemDoubleClicked(QTreeWidgetItem*, int)));
+ connect(m_removeButton, SIGNAL(clicked()), this, SLOT(slotRemoveModules()));
+ connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), SLOT(slotSwordSetupChanged()));
+ populateModuleList();
+}
+
+QString BtRemovePage::label()
+{
+ return tr("Remove installed works. Select the works and click Remove button.");
+}
+QString BtRemovePage::iconName()
+{
+ return CResMgr::bookshelfmgr::removepage::icon;
+}
+QString BtRemovePage::header()
+{
+ return tr("Remove");
+}
+
+
+void BtRemovePage::populateModuleList()
+{
+
+ m_view->clear();
+ m_selectedModules.clear();
+
+ // disconnect the signal so that we don't have to run functions for every module
+ disconnect(m_view, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotSelectionChanged(QTreeWidgetItem*, int)) );
+
+ QList<BTModuleTreeItem::Filter*> empty;
+ BTModuleTreeItem rootItem(empty, (BTModuleTreeItem::Grouping)CBTConfig::get(CBTConfig::bookshelfGrouping));
+ addToTree(&rootItem, m_view->invisibleRootItem());
+
+ // receive signal when user checks modules
+ connect(m_view, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotSelectionChanged(QTreeWidgetItem*, int)) );
+ qDebug("BtSourceArea::createModuleTree end");
+}
+
+void BtRemovePage::addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem)
+{
+ //qDebug()<<"BtRemovePage::addToTree "<<item->text();
+ //qDebug() << "BTMTItem type: " << item->type();
+
+ foreach (BTModuleTreeItem* i, item->children()) {
+ addToTree(i, new QTreeWidgetItem(widgetItem));
+ }
+ if (item->type() != BTModuleTreeItem::Root) {
+ CSwordModuleInfo* mInfo = item->moduleInfo();
+ widgetItem->setText(0, item->text());
+ if (item->type() == BTModuleTreeItem::Category || item->type() == BTModuleTreeItem::Language) {
+ //qDebug() << "item"<<item->text()<< "was cat or lang";
+ widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsTristate);
+ }
+ if (item->type() == BTModuleTreeItem::Module) {
+ //qDebug() << "item"<<item->text()<< "was a module";
+ widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
+ widgetItem->setCheckState(0, Qt::Unchecked);
+
+ //TODO: add the relevant information in to item or tooltip
+ // (install path, is still available from some source)
+
+ QString descr(mInfo->config(CSwordModuleInfo::AbsoluteDataPath));
+ QString toolTipText = CToolClass::moduleToolTip(mInfo);
+ widgetItem->setText(1, descr);
+ widgetItem->setToolTip(0, toolTipText);
+ widgetItem->setToolTip(1, descr);
+ }
+ }
+}
+
+
+
+void BtRemovePage::slotRemoveModules()
+{
+ if ( m_selectedModules.empty() ) {
+ return; //no message, just do nothing
+ }
+
+ QStringList moduleNames;
+ foreach (CSwordModuleInfo* m, m_selectedModules) {
+ moduleNames.append(m->name());
+ }
+ const QString message = tr("You selected the following work(s): ")
+ .append(moduleNames.join(", "))
+ .append("\n\n")
+ .append(tr("Do you really want to remove them from your system?"));
+
+ if ((QMessageBox::question(this, tr("Remove Works?"), message, QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)) { //Yes was pressed.
+
+ // Update the module list before really removing. Remember deleting the pointers later.
+ QList<CSwordModuleInfo*> toBeDeleted = CPointers::backend()->takeModulesFromList(moduleNames);
+
+ sword::InstallMgr installMgr;
+ QMap<QString, sword::SWMgr*> mgrDict; //maps config paths to SWMgr objects
+ foreach ( CSwordModuleInfo* mInfo, toBeDeleted ) {
+ Q_ASSERT(mInfo); // Only installed modules could have been selected and returned by takeModulesFromList
+ // Find the install path for the sword manager
+ QString prefixPath = mInfo->config(CSwordModuleInfo::AbsoluteDataPath) + "/";
+ QString dataPath = mInfo->config(CSwordModuleInfo::DataPath);
+ if (dataPath.left(2) == "./") {
+ dataPath = dataPath.mid(2);
+ }
+ if (prefixPath.contains(dataPath)) { //remove module part to get the prefix path
+ prefixPath = prefixPath.remove( prefixPath.indexOf(dataPath), dataPath.length() );
+ }
+ else { //This is an error, should not happen
+ qWarning() << "Removing" << mInfo->name() << "didn't succeed because the absolute path" << prefixPath << "didn't contain the data path" << dataPath;
+ continue; // don't remove this, go to next of the for loop
+ }
+
+ // Create the sword manager and remove the module
+ sword::SWMgr* mgr = mgrDict[ prefixPath ];
+ if (!mgr) { //create new mgr if it's not yet available
+ mgrDict.insert(prefixPath, new sword::SWMgr(prefixPath.toLocal8Bit()));
+ mgr = mgrDict[ prefixPath ];
+ }
+ qDebug() << "Removing the module"<< mInfo->name() << "...";
+ installMgr.removeModule(mgr, mInfo->module()->Name());
+ }
+ //delete the removed moduleinfo pointers
+ qDeleteAll(toBeDeleted);
+ //delete all mgrs which were created above
+ qDeleteAll(mgrDict);
+ mgrDict.clear();
+ }
+}
+
+
+void BtRemovePage::slotSelectionChanged(QTreeWidgetItem* item, int column)
+{
+ //qDebug("BtRemovePage::slotSelectionChanged");
+ // modify the internal list of checked modules
+ // if() leaves groups away
+ if (!item->childCount() && column == 0) {
+ CSwordModuleInfo* mInfo = 0;
+ //qDebug("BtRemovePage::slotSelectionChanged");
+ foreach (CSwordModuleInfo* module, CPointers::backend()->moduleList()) {
+ if (module->name() == item->text(0) && module->config(CSwordModuleInfo::AbsoluteDataPath) == item->text(1)) {
+ mInfo = module;
+ break;
+ }
+ }
+ Q_ASSERT(mInfo); // this should have been found
+ if (item->checkState(0) == Qt::Checked) {
+ //qDebug() << item->text(0) << "in" << item->text(1) << "was checked";
+ m_selectedModules.append(mInfo);
+ } else {
+ //qDebug() << mInfo->name() << "was unchecked";
+ m_selectedModules.removeAll(mInfo); // there is only one, it's a pointer
+ }
+
+ if (m_selectedModules.count() > 0) {
+ m_removeButton->setEnabled(true);
+ } else {
+ m_removeButton->setEnabled(false);
+ }
+ }
+}
+
+void BtRemovePage::slotItemDoubleClicked(QTreeWidgetItem* /*item*/, int /*column*/)
+{
+ // TODO: Open the About dialog.
+}
+
+void BtRemovePage::slotSwordSetupChanged()
+{
+ populateModuleList();
+}
diff --git a/src/frontend/bookshelfmanager/removepage/btremovepage.h b/src/frontend/bookshelfmanager/removepage/btremovepage.h
new file mode 100644
index 0000000..046534c
--- /dev/null
+++ b/src/frontend/bookshelfmanager/removepage/btremovepage.h
@@ -0,0 +1,67 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+#ifndef BTREMOVEPAGE_H
+#define BTREMOVEPAGE_H
+
+#include "frontend/bookshelfmanager/btconfigdialog.h"
+#include "backend/btmoduletreeitem.h"
+
+#include <QString>
+#include <QMultiMap>
+
+//class BTModuleTreeItem;
+
+class QTreeWidget;
+class QTreeWidgetItem;
+class QPushButton;
+
+
+class BtRemovePage : public BtConfigPage
+{
+ Q_OBJECT
+
+public:
+ BtRemovePage();
+
+ ~BtRemovePage(){}
+
+ // BtConfigPage methods
+ QString header();
+ QString iconName();
+ QString label();
+
+ void populateModuleList();
+
+//signals:
+ //void swordSetupChanged();
+
+public slots:
+ void slotSwordSetupChanged();
+
+private slots:
+
+ void slotRemoveModules();
+ /** Handles activating the Remove button. */
+ void slotSelectionChanged(QTreeWidgetItem* item, int column);
+ void slotItemDoubleClicked(QTreeWidgetItem* item, int column);
+
+private: // methods
+ void addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem);
+
+private: // data
+ QTreeWidget* m_view;
+ QPushButton* m_removeButton;
+ /** Map of module name and install path (absolute path from the moduleinfo config entry).*/
+ QList<CSwordModuleInfo*> m_selectedModules;
+
+};
+
+#endif
diff --git a/src/frontend/btaboutmoduledialog.cpp b/src/frontend/btaboutmoduledialog.cpp
new file mode 100644
index 0000000..1cb326e
--- /dev/null
+++ b/src/frontend/btaboutmoduledialog.cpp
@@ -0,0 +1,45 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btaboutmoduledialog.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "util/dialogutil.h"
+
+#include <QWidget>
+#include <QDialog>
+#include <QTextEdit>
+#include <QVBoxLayout>
+#include <QDialogButtonBox>
+
+BTAboutModuleDialog::BTAboutModuleDialog(QWidget* parent, CSwordModuleInfo* info)
+ : QDialog(parent)
+{
+ //Set the flag to destroy when closed - otherwise eats memory
+ setAttribute(Qt::WA_DeleteOnClose);
+ setWindowTitle(tr("Information About %1").arg(info->name()));
+ resize(650, 400);
+ QVBoxLayout* vboxLayout = new QVBoxLayout(this);
+
+ QTextEdit* textEdit = new QTextEdit(this);
+ textEdit->setReadOnly(true);
+ textEdit->setTextInteractionFlags(Qt::TextSelectableByMouse);
+ vboxLayout->addWidget(textEdit);
+ textEdit->setHtml(info->aboutText());
+
+ QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
+ buttonBox->setOrientation(Qt::Horizontal);
+ buttonBox->setStandardButtons(QDialogButtonBox::Close);
+ util::prepareDialogBox(buttonBox);
+ vboxLayout->addWidget(buttonBox);
+
+
+ QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+
+}
diff --git a/src/frontend/btaboutmoduledialog.h b/src/frontend/btaboutmoduledialog.h
new file mode 100644
index 0000000..b705893
--- /dev/null
+++ b/src/frontend/btaboutmoduledialog.h
@@ -0,0 +1,30 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTABOUTMODULEDIALOG_H
+#define BTABOUTMODULEDIALOG_H
+
+#include <QDialog>
+
+class CSwordModuleInfo;
+class QWidget;
+
+/**
+ Dialog to show the information about a module.
+
+ @author The BibleTime team <info@bibletime.info>
+*/
+class BTAboutModuleDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ BTAboutModuleDialog(QWidget* parent, CSwordModuleInfo* info);
+};
+
+#endif
diff --git a/src/frontend/cdragdrop.cpp b/src/frontend/cdragdrop.cpp
new file mode 100644
index 0000000..84d6376
--- /dev/null
+++ b/src/frontend/cdragdrop.cpp
@@ -0,0 +1,57 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 2007 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+#include "cdragdrop.h"
+
+#include <QString>
+#include <QByteArray>
+#include <QMimeData>
+#include <QList>
+
+BTMimeData::BTMimeData()
+{}
+
+BTMimeData::~BTMimeData()
+{}
+
+/** Creates a new BTMimeData.
+* Creates a new bookmark item and appends it to the list.
+*/
+BTMimeData::BTMimeData(QString module, QString key, QString description)
+{
+ appendBookmark(module, key, description);
+}
+
+/** Creates a new BTMimeData, setting the text MIME type (see QMimeData::setText()). */
+BTMimeData::BTMimeData(QString text)
+{
+ setText(text);
+}
+
+/** Appends a new bookmark item into the list.*/
+void BTMimeData::appendBookmark(QString module, QString key, QString description)
+{
+ BookmarkItem bm = BookmarkItem(module, key, description);
+ m_bookmarkList.append(bm);
+ setData("BibleTime/Bookmark", QByteArray());
+}
+
+
+
+/** Returns the first bookmark item in the list. */
+const BookmarkItem& BTMimeData::bookmark() const
+{
+ return m_bookmarkList.first();
+}
+
+/** Creates a new bookmark item. */
+BookmarkItem::BookmarkItem(QString module, QString key, QString description)
+: m_moduleName(module), m_key(key), m_description(description)
+{}
diff --git a/src/frontend/cdragdrop.h b/src/frontend/cdragdrop.h
new file mode 100644
index 0000000..2804544
--- /dev/null
+++ b/src/frontend/cdragdrop.h
@@ -0,0 +1,85 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 2007 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CDRAGDROP_H
+#define CDRAGDROP_H
+
+#include <QMimeData>
+#include <QString>
+#include <QStringList>
+
+
+/** Class which represents a bookmark.
+* Includes key, module name and description, all QStrings which have getter methods.
+* Can be created only through BTMimeData object.
+*/
+class BookmarkItem {
+public:
+ /** Returns the key */
+ const QString& key() const {return m_key;} ;
+ /** Returns the module name */
+ const QString& module() const {return m_moduleName;} ;
+ /** Returns the bookmark description */
+ const QString& description() const {return m_description;};
+protected:
+ friend class BTMimeData;
+ BookmarkItem(QString, QString, QString);
+ QString m_moduleName; //the module which is used by this item
+ QString m_key; //the key of a bookmark
+ QString m_description; //the description of a bookmark
+};
+
+
+/**
+* Represents the Drag'n'Drop data.
+* Inherits QMimeData as described in its documentation,
+* "storing custom data in a QMimeData object": approach 3.
+* Any custom data may be added and extracted as with QMimeData, but this class
+* includes also a list of bookmark items.
+* For further documentation see http://doc.trolltech.com/4.3/dnd.html
+*/
+class BTMimeData : public QMimeData {
+ Q_OBJECT
+public:
+
+ /** Type for bookmark item list. Usage: BTMimeData::ItemList. */
+ typedef QList<BookmarkItem> ItemList;
+
+ /** Creates a new empty BTMimeData. */
+ BTMimeData();
+
+ virtual ~BTMimeData();
+
+ /** Creates a new BTMimeData.
+ * Creates a new bookmark item and appends it to the list.
+ * MIME type "BibleTime/Bookmark" is added.
+ * Bookmarks can not be reached by data() method, use bookmark() or bookmarks() instead.
+ */
+ BTMimeData(QString module, QString key, QString description);
+ /** Creates a new BTMimeData, setting the text MIME type (see QMimeData::setText()). */
+ BTMimeData(QString text);
+
+
+ /** Appends a new bookmark item into the list.
+ * Creates the item using the arguments.
+ * MIME type "BibleTime/Bookmark" is added.
+ */
+ virtual void appendBookmark(QString module, QString key, QString description);
+ /** Returns the bookmarks list. */
+ virtual const ItemList& bookmarks() const {return m_bookmarkList;} ;
+ /** Returns the first bookmark item in the list. */
+ virtual const BookmarkItem& bookmark() const;
+
+private:
+ ItemList m_bookmarkList;
+};
+
+#endif
diff --git a/src/frontend/cdragdropmgr.cpp b/src/frontend/cdragdropmgr.cpp
new file mode 100644
index 0000000..11dab79
--- /dev/null
+++ b/src/frontend/cdragdropmgr.cpp
@@ -0,0 +1,262 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#include "cdragdropmgr.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/managers/cswordbackend.h"
+#include "backend/keys/cswordversekey.h"
+#include "util/cpointers.h"
+
+//Sword includes
+#include "versekey.h"
+
+//Qt includes
+#include <qevent.h>
+#include <qdom.h>
+//Added by qt3to4:
+#include <Q3CString>
+
+
+//This is the old old d'n'd system. Use cdragdrop instead.
+
+
+CDragDropMgr::BTDrag::BTDrag( const QString& xml, QWidget* dragSource, const char* name)
+: Q3TextDrag(xml, dragSource, name) {}
+;
+
+//static function to see whether we can decode tje given mime type
+bool CDragDropMgr::BTDrag::canDecode( const QMimeSource * mime ) {
+ if ( mime->provides("BibleTime/DND") ) { //we can decode this type!
+ return true;
+ }
+ return false; //not yet implemented
+};
+
+bool CDragDropMgr::BTDrag::provides( const char* type ) const {
+ return (type == "BibleTime/DND"); //return only true if the type is BibleTime/DND
+};
+
+const char* CDragDropMgr::BTDrag::format( int i ) const {
+ if ( i == 0) { //we support only one format!
+ return "BibleTime/DND";
+ };
+ return 0;
+};
+
+bool CDragDropMgr::BTDrag::decode(const QMimeSource* e, QString& str) {
+ if (canDecode(e)) {
+ str = QString( e->encodedData( "BibleTime/DND" ) );
+ return true;
+ }
+ return false;
+};
+
+bool CDragDropMgr::BTDrag::decode(const QMimeSource* e, QString& str, Q3CString& /*subtype*/) {
+ return decode(e, str);
+};
+
+QByteArray CDragDropMgr::BTDrag::encodedData( const char* /*type*/ ) const {
+ return Q3TextDrag::encodedData("text/plain"); //hack because QTextDrag only accepts text/plainand not our BibleTime/DND type
+};
+
+///////////////////////////// new class //////////////////////
+
+CDragDropMgr::Item::Item( const QString& text )
+: m_type(Text),
+m_bookmarkModuleName(QString::null),
+m_bookmarkKey(QString::null),
+m_bookmarkDescription(QString::null),
+m_text(text) {}
+
+CDragDropMgr::Item::Item( const QString& moduleName, const QString& key, const QString& description )
+: m_type(Bookmark),
+m_bookmarkModuleName(moduleName),
+m_bookmarkKey(key),
+m_bookmarkDescription(description),
+m_text(QString::null) {
+ //we have to make sure the key is saved in it's english representation, so we convert it
+ if (CSwordModuleInfo* mod = CPointers::backend()->findModuleByName( moduleName )) {
+ if (mod->type() == CSwordModuleInfo::Bible || mod->type() == CSwordModuleInfo::Commentary) {
+ CSwordVerseKey vk(0);
+ vk.key( key );
+ vk.setLocale("en");
+
+ m_bookmarkKey = vk.key();
+ // qWarning("english key of %s is %s", key.latin1(), m_bookmarkKey.latin1());
+ }
+ }
+}
+
+CDragDropMgr::Item::~Item() {}
+
+const CDragDropMgr::Item::Type& CDragDropMgr::Item::type() const {
+ //returns the type of drag & drop action this item represents
+ return m_type;
+}
+
+/** Returns the text which is used by this DragDrop Item, only valid if type() == Text */
+const QString& CDragDropMgr::Item::text() const {
+ // Q_ASSERT(!m_text.isEmpty());
+ return m_text;
+}
+
+/** Returns the key, ony valid if type() == Bookmark */
+const QString& CDragDropMgr::Item::bookmarkKey() const {
+ // Q_ASSERT(!m_bookmarkKey.isEmpty());
+ return m_bookmarkKey;
+}
+
+/** Returns the bookmark module, ony valid if type() == Bookmark */
+const QString& CDragDropMgr::Item::bookmarkModule() const {
+ // Q_ASSERT(!m_bookmarkModuleName.isEmpty());
+ return m_bookmarkModuleName;
+}
+
+/** Returns the bookmark description, ony valid if type() == Bookmark */
+const QString& CDragDropMgr::Item::bookmarkDescription() const {
+ // Q_ASSERT(!m_bookmarkDescription.isEmpty());
+ return m_bookmarkDescription;
+}
+
+////////////////////////////////// NEW CLASS //////////////////////////
+
+CDragDropMgr::CDragDropMgr() {}
+
+CDragDropMgr::~CDragDropMgr() {}
+
+const bool CDragDropMgr::canDecode( const QMimeSource* const mime ) {
+ if (CDragDropMgr::BTDrag::canDecode(mime)) {
+ return true;
+ }
+ else if( Q3TextDrag::canDecode(mime) ) {
+ qWarning("QTextDrag can decode this mime!");
+ return true;
+ };
+ return false;
+};
+
+Q3DragObject* const CDragDropMgr::dragObject( CDragDropMgr::ItemList& items, QWidget* dragSource ) {
+ if ( items.count() ) {
+ //process the items and set the data to the dragobject we return later
+ QDomDocument doc("DOC");
+ doc.appendChild( doc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
+ QDomElement content = doc.createElement("BibleTimeDND");
+ content.setAttribute("syntaxVersion", "1.0");
+ doc.appendChild(content);
+
+ CDragDropMgr::ItemList::iterator it;
+ for ( it = items.begin(); it != items.end(); ++it ) {
+ Item item = (*it);
+ if (item.type() == Item::Bookmark) { //a bookmark was dragged
+ //append the XML stuff for a bookmark
+ QDomElement bookmark = doc.createElement("BOOKMARK");
+ bookmark.setAttribute("key", item.bookmarkKey());
+ bookmark.setAttribute("description", item.bookmarkDescription());
+ bookmark.setAttribute("moduleName", item.bookmarkModule());
+
+ content.appendChild(bookmark);
+ }
+ else if (item.type() == Item::Text) { //plain text was dragged
+ //append the XML stuff for plain text
+ QDomElement plainText = doc.createElement("TEXT");
+ plainText.setAttribute("text", item.text());
+
+ content.appendChild(plainText);
+ }
+ }
+
+ BTDrag* dragObject = new BTDrag( doc.toString(), dragSource );
+ // qWarning("DND data created: %s", (const char*)doc.toString().utf8());
+ return dragObject;
+ };
+ return 0;
+};
+
+CDragDropMgr::ItemList CDragDropMgr::decode( const QMimeSource* const src) {
+ //if the drag was started by another widget which doesn't use CDragDropMgr (a drag created by QTextDrag)
+ if (canDecode(src) && Q3TextDrag::canDecode(src)) { //if we can decode but it's a QTextDrag and not a BTDrag object
+ QString text;
+ Q3TextDrag::decode(src, text);
+ // qWarning(text.latin1());
+
+ CDragDropMgr::ItemList dndItems;
+ dndItems.append( Item(text) );
+ return dndItems;
+ }
+ else if (!canDecode(src)) { //if we can't decode it
+ return CDragDropMgr::ItemList();
+ };
+
+ QString xmlData;
+ BTDrag::decode(src, xmlData);
+
+ if (xmlData.isEmpty()) { //something went wrong!
+ // qWarning("CDragDropMgr::decode: empty xml data!");
+ return CDragDropMgr::ItemList();
+ }
+ // else {
+ // qWarning("Drag&Drop data is: %s", xmlData.latin1());
+ // }
+
+ //we can handle the dropEvent and have xml data to work on!
+ ItemList dndItems;
+
+ QDomDocument doc;
+ doc.setContent( xmlData );
+
+ QDomElement document = doc.documentElement();
+ if( document.tagName() != "BibleTimeDND" ) { //BibleTime was used in syntax version 1.0
+ qWarning("DragDropMgr::decode: Missing BibleTimeDND doc");
+ return CDragDropMgr::ItemList();
+ }
+ // see if there's a section with the name MAINWINDOW
+ QDomElement elem = document.firstChild().toElement();
+ while (!elem.isNull()) {
+ if (elem.tagName() == "BOOKMARK") { //we found a bookmark!
+ // qWarning("found a bookmark!");
+ const QString key = elem.hasAttribute("key") ? elem.attribute("key") : QString::null;
+ const QString moduleName = elem.hasAttribute("moduleName") ? elem.attribute("moduleName") : QString::null;
+ const QString description = elem.hasAttribute("description") ? elem.attribute("description") : QString::null;
+
+ dndItems.append( CDragDropMgr::Item(moduleName, key, description) );
+ }
+ else if (elem.tagName() == "TEXT") { //we found a plain text passage!
+ const QString text = elem.hasAttribute("text") ? elem.attribute("text") : QString::null;
+ dndItems.append( CDragDropMgr::Item(text) );
+ };
+ elem = elem.nextSibling().toElement();
+ };
+
+ return dndItems;
+};
+
+/** Returns which type the given drop event has, if it's a mixed one (both bookmarks and plain text), which shouldn't happen, it return Item::Unknown. */
+CDragDropMgr::Item::Type CDragDropMgr::dndType( const QMimeSource* e ) {
+ ItemList dndItems = decode(e);
+ if (dndItems.isEmpty()) {//wrong dropEvent or something strange
+ return Item::Unknown;
+ };
+
+ //check whether all items have the ssame type, if they do return the type
+ //as soon as two items have different types return Item::Unknown
+ ItemList::Iterator it;
+ Item::Type type = Item::Unknown;
+ for( it = dndItems.begin(); it != dndItems.end(); ++it ) {
+ if( type == Item::Unknown) { //if Unknown is set this is the first loop, don't return Unknown
+ type = (*it).type();
+ }
+ else if (type != (*it).type() ) {//items have different type, return Item::Unknown
+ return Item::Unknown;
+ };
+ };
+ return type;
+}
diff --git a/src/frontend/cdragdropmgr.h b/src/frontend/cdragdropmgr.h
new file mode 100644
index 0000000..5abad6c
--- /dev/null
+++ b/src/frontend/cdragdropmgr.h
@@ -0,0 +1,160 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CDRAGDROPMGR_H
+#define CDRAGDROPMGR_H
+
+//Qt includes
+#include <QString>
+#include <q3cstring.h>
+#include <q3dragobject.h>
+#include <q3valuelist.h>
+//Added by qt3to4:
+#include <QDropEvent>
+
+//forward declarations
+class QDropEvent;
+class QWidget;
+
+/** This class is the drag'n' drop manager for BibleTime.
+ *
+ * This d'n'd system is replaced with the new classes in cdragdrop.h/cpp. (cdragdropmgr will be deleted later.)
+ *
+ * The dnd is managed by XML code, which defines the type of the drag/drop, the items and the action (moe, copy etc.).
+ * It's possible to create the XML code by passing a list of keys etc.
+ *
+ * Functions:
+ * - dnd_type(), returns either CDragDropMgr::Action_Drag or CDragDropMgr::Action_Drop
+ * - dnd_action(), returns either CDragDropMgr::Move or CDragDropMgr::Copy
+ * - dnd_acceptDrop(), returns true or false. True if the drop could be handled by the CDragDropMgr class, otherwise false
+ *
+ *
+ * The functions which create the XML stuff can't be reimplemented, too. Otherwise we could not guarantee for good XML code
+ * which works everywhere.
+ *
+ * @author The BibleTime team
+ */
+class CDragDropMgr {
+public:
+ //The class which represents one single drag&drop entry (e.g. a bookmark or a portion of text)
+ class Item {
+public:
+ /**
+ * The possible types of Drag&Drop actions.
+ */
+ enum Type {
+ Bookmark = 0, /* A bookmark: Has a key, a module and a description*/
+ Text, /* Simple text, e.g. can be dropped on a module to start a search in this module using the dropped text */
+ Unknown /* For situatiosn like CDragDropMgr::dndType */
+ };
+ /**
+ * This function returns the type of drag this item has
+ */
+ const CDragDropMgr::Item::Type& type() const;
+ /**
+ * Returns the key, ony valid if type() == Bookmark
+ */
+ const QString& bookmarkKey() const;
+ /**
+ * Returns the module name, ony valid if type() == Bookmark
+ */
+ const QString& bookmarkModule() const;
+ /**
+ * Returns the bookmark description, ony valid if type() == Bookmark
+ */
+ const QString& bookmarkDescription() const;
+ /**
+ * Returns the text which is used by this DragDrop Item, only valid if type() == Text
+ */
+ const QString& text() const;
+
+ // protected:
+ friend class CDragDropMgr;
+ /*
+ * We use protected constructor and destructor because creation of objects
+ * of this class sould only be possible for CDragDropMgr
+ */
+
+ /** Constructor for a text item
+ * This constructor automatically sets the type member to Text
+ * This is also the default constructor
+ */
+ Item(const QString& text = QString::null );
+ /** Constructor for a Bookmark item
+ * This constructor automatically sets the type member to Bookmark
+ */
+ Item(const QString& moduleName, const QString& key, const QString& description);
+ virtual ~Item();
+
+private:
+ Type m_type; //the member to save the type of the action
+ QString m_bookmarkModuleName; //the modules which is used by this item, only valid for type() == Bookmark
+ QString m_bookmarkKey; //the key of a bookmark, only valid if type() == Bookmark
+ QString m_bookmarkDescription; //the description of a bookmark, only valid if type() == Bookmark
+ QString m_text; //the text of this item, only valid if type() == Text
+ }
+ ; //end of class CDragDropMgr::Item
+
+ //the item list we're using
+ typedef Q3ValueList<Item> ItemList;
+
+ /** Return whether the drop should be accepted
+ * This functions tests whether the drop should be accepted or not. It returns true if the drop object
+ * is supported by the CDragDropMgr and if it cotains valid data. Oterwise this function returns false.
+ */
+ static const bool canDecode( const QMimeSource* const mime );
+ /**
+ * This function returns the drag object with the data which represents the items given as parameter
+ * If the list is invalid or empty we return NULL.
+ */
+ static Q3DragObject* const dragObject( CDragDropMgr::ItemList& items, QWidget* dragSource );
+
+ /**
+ * Decodes the XML stuff we passed to the dragObject at creation time.
+ * Returns a list of CDragDropMgr::Item objects.
+ * If it's a wrong dropEvent we return an empty ist
+ */
+ static CDragDropMgr::ItemList decode( const QMimeSource* const src );
+ /**
+ * Returns which type the given drop event has, if it's a mixed one (both bookmarks and plain text),
+ * which shouldn't happen, it return Item::Unknown.
+ * It also returns Unknown if the drop event is not supported.
+ */
+ static CDragDropMgr::Item::Type dndType( const QMimeSource* e );
+
+protected:
+ //The class which represents our XML drag object stuff
+class BTDrag : public Q3TextDrag {
+public:
+ BTDrag( const QString& xml, QWidget* dragSource = 0, const char* name = 0);
+ //reimplemented static publoc function to provide functionality for BibleTime XML drags
+ static bool canDecode( const QMimeSource * e );
+ virtual bool provides( const char* type ) const;
+ virtual const char* format( int i = 0 ) const;
+
+ virtual QByteArray encodedData( const char* type ) const;
+
+protected:
+ friend class CDragDropMgr;
+ //made protected because the BibleTime classes may not manage the data of BTDrag
+ // virtual void setText(const QString& text);
+
+ //made protected because the BibleTime classes should not manage the DRag&Drop stuff themself
+ static bool decode(const QMimeSource* e, QString& str);
+ static bool decode(const QMimeSource* e, QString& str, Q3CString& subtype);
+ };
+
+ //protected constructor and destructor because we do not allow inheritance, functionality is provided by static functions
+ CDragDropMgr();
+ virtual ~CDragDropMgr();
+};
+
+#endif
diff --git a/src/frontend/cexportmanager.cpp b/src/frontend/cexportmanager.cpp
new file mode 100644
index 0000000..5c94c39
--- /dev/null
+++ b/src/frontend/cexportmanager.cpp
@@ -0,0 +1,546 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#include "cexportmanager.h"
+
+#include "backend/keys/cswordkey.h"
+#include "backend/keys/cswordversekey.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/managers/creferencemanager.h"
+#include "backend/managers/cdisplaytemplatemgr.h"
+#include "backend/rendering/centrydisplay.h"
+#include "backend/rendering/chtmlexportrendering.h"
+#include "backend/rendering/cplaintextexportrendering.h"
+
+#include "frontend/cprinter.h"
+
+#include "util/ctoolclass.h"
+#include <boost/scoped_ptr.hpp>
+
+//Qt includes
+#include <QClipboard>
+#include <QList>
+#include <QProgressDialog>
+#include <QTextStream>
+#include <QApplication>
+#include <QFileDialog>
+
+//KDE includes
+
+
+//Sword includes
+#include <swkey.h>
+#include <listkey.h>
+
+using namespace Rendering;
+using namespace Printing;
+
+CExportManager::CExportManager(const QString& caption, const bool showProgress, const QString& progressLabel, const CSwordBackend::FilterOptions filterOptions, const CSwordBackend::DisplayOptions displayOptions) {
+ m_caption = !caption.isEmpty() ? caption : QString::fromLatin1("BibleTime");
+ m_progressLabel = progressLabel;
+ m_filterOptions = filterOptions;
+ m_displayOptions = displayOptions;
+ m_showProgress = showProgress;
+ m_progressDialog = 0;
+}
+
+bool CExportManager::saveKey(CSwordKey* key, const Format format, const bool addText) {
+ if (!key) {
+ return false;
+ }
+ if (!key->module()) {
+ return false;
+ }
+ const QString filename = getSaveFileName(format);
+ if (filename.isEmpty()) {
+ return false;
+ }
+
+ CSwordBackend::FilterOptions filterOptions = m_filterOptions;
+ filterOptions.footnotes = false;
+ filterOptions.strongNumbers = false;
+ filterOptions.morphTags = false;
+ filterOptions.lemmas = false;
+ filterOptions.scriptureReferences = false;
+ filterOptions.textualVariants = false;
+
+ CHTMLExportRendering::Settings settings(addText);
+ boost::scoped_ptr<CTextRendering> render (
+ (format == HTML)
+ ? new CHTMLExportRendering(settings, m_displayOptions, filterOptions)
+ : new CPlainTextExportRendering(settings, m_displayOptions, filterOptions)
+ );
+
+ QString text;
+ QString startKey;
+ QString stopKey;
+
+ QList<CSwordModuleInfo*> modules;
+ modules.append(key->module());
+
+ CSwordVerseKey *vk = dynamic_cast<CSwordVerseKey*>(key);
+ if (vk && vk->isBoundSet()) {
+ text = render->renderKeyRange( QString::fromUtf8(vk->LowerBound()), QString::fromUtf8(vk->UpperBound()), modules );
+ }
+ else { //no range supported
+ text = render->renderSingleKey(key->key(), modules);
+ }
+
+ if (!progressWasCancelled()) {
+ CToolClass::savePlainFile(filename, text, false, (format==HTML) ? QTextCodec::codecForName("UTF-8") : QTextCodec::codecForLocale() );
+ closeProgressDialog();
+ return true;
+ }
+ return false;
+}
+
+bool CExportManager::saveKeyList(sword::ListKey* list, CSwordModuleInfo* module, const Format format, const bool addText) {
+ if (!list->Count())
+ return false;
+
+ const QString filename = getSaveFileName(format);
+ if (filename.isEmpty()) {
+ return false;
+ }
+
+ CSwordBackend::FilterOptions filterOptions = m_filterOptions;
+ filterOptions.footnotes = false;
+ filterOptions.strongNumbers = false;
+ filterOptions.morphTags = false;
+ filterOptions.lemmas = false;
+ filterOptions.scriptureReferences = false;
+ filterOptions.textualVariants = false;
+
+ CHTMLExportRendering::Settings settings(addText);
+ boost::scoped_ptr<CTextRendering> render (
+ (format == HTML)
+ ? new CHTMLExportRendering(settings, m_displayOptions, filterOptions)
+ : new CPlainTextExportRendering(settings, m_displayOptions, filterOptions)
+ );
+
+ CTextRendering::KeyTree tree;
+
+ setProgressRange(list->Count());
+ CTextRendering::KeyTreeItem::Settings itemSettings;
+ itemSettings.highlight = false;
+
+ *list = sword::TOP;
+ while (!list->Error() && !progressWasCancelled()) {
+ tree.append( new CTextRendering::KeyTreeItem(QString::fromLocal8Bit((const char*)(*list)) , module, itemSettings) );
+ incProgress();
+
+ (*list)++;
+ }
+
+ const QString text = render->renderKeyTree(tree);
+
+ if (!progressWasCancelled()) {
+ CToolClass::savePlainFile(filename, text, false, (format==HTML) ? QTextCodec::codecForName("UTF-8") : QTextCodec::codecForLocale() );
+ closeProgressDialog();
+ return true;
+ }
+ return false;
+}
+
+bool CExportManager::saveKeyList(QList<CSwordKey*>& list, const Format format, const bool addText ) {
+ if (!list.count())
+ return false;
+
+ const QString filename = getSaveFileName(format);
+ if (filename.isEmpty()) {
+ return false;
+ }
+
+ CSwordBackend::FilterOptions filterOptions = m_filterOptions;
+ filterOptions.footnotes = false;
+ filterOptions.strongNumbers = false;
+ filterOptions.morphTags = false;
+ filterOptions.lemmas = false;
+ filterOptions.scriptureReferences = false;
+ filterOptions.textualVariants = false;
+
+ CHTMLExportRendering::Settings settings(addText);
+ boost::scoped_ptr<CTextRendering> render (
+ (format == HTML)
+ ? new CHTMLExportRendering(settings, m_displayOptions, filterOptions)
+ : new CPlainTextExportRendering(settings, m_displayOptions, filterOptions)
+ );
+
+ CTextRendering::KeyTree tree;
+
+ setProgressRange(list.count());
+ CTextRendering::KeyTreeItem::Settings itemSettings;
+ itemSettings.highlight = false;
+
+ QListIterator<CSwordKey*> it(list);
+ while (it.hasNext() && !progressWasCancelled()){
+ CSwordKey* k = it.next();
+ tree.append( new CTextRendering::KeyTreeItem(k->key(), k->module(), itemSettings) );
+ incProgress();
+ };
+
+ const QString text = render->renderKeyTree(tree);
+
+ if (!progressWasCancelled()) {
+ CToolClass::savePlainFile(filename, text, false, (format==HTML) ? QTextCodec::codecForName("UTF-8") : QTextCodec::codecForLocale() );
+ closeProgressDialog();
+ return true;
+ }
+ return false;
+}
+
+bool CExportManager::copyKey(CSwordKey* key, const Format format, const bool addText) {
+ if (!key) {
+ return false;
+ }
+ if (!key->module()) {
+ return false;
+ }
+
+ CSwordBackend::FilterOptions filterOptions = m_filterOptions;
+ filterOptions.footnotes = false;
+ filterOptions.strongNumbers = false;
+ filterOptions.morphTags = false;
+ filterOptions.lemmas = false;
+ filterOptions.scriptureReferences = false;
+ filterOptions.textualVariants = false;
+
+ CHTMLExportRendering::Settings settings(addText);
+ boost::scoped_ptr<CTextRendering> render (
+ (format == HTML)
+ ? new CHTMLExportRendering(settings, m_displayOptions, filterOptions)
+ : new CPlainTextExportRendering(settings, m_displayOptions, filterOptions)
+ );
+
+ QString text;
+ QString startKey;
+ QString stopKey;
+
+ QList<CSwordModuleInfo*> modules;
+ modules.append(key->module());
+
+ CSwordVerseKey *vk = dynamic_cast<CSwordVerseKey*>(key);
+ if (vk && vk->isBoundSet()) {
+ text = render->renderKeyRange(
+ QString::fromUtf8(vk->LowerBound()),
+ QString::fromUtf8(vk->UpperBound()),
+ modules
+ );
+ }
+ else { //no range supported
+ text = render->renderSingleKey(key->key(), modules);
+ }
+
+ QApplication::clipboard()->setText(text);
+ return true;
+}
+
+bool CExportManager::copyKeyList(sword::ListKey* list, CSwordModuleInfo* module, const Format format, const bool addText) {
+ if (!list->Count())
+ return false;
+
+ CSwordBackend::FilterOptions filterOptions = m_filterOptions;
+ filterOptions.footnotes = false;
+ filterOptions.strongNumbers = false;
+ filterOptions.morphTags = false;
+ filterOptions.lemmas = false;
+ filterOptions.scriptureReferences = false;
+ filterOptions.textualVariants = false;
+
+ CHTMLExportRendering::Settings settings(addText);
+ boost::scoped_ptr<CTextRendering> render (
+ (format == HTML)
+ ? new CHTMLExportRendering(settings, m_displayOptions, filterOptions)
+ : new CPlainTextExportRendering(settings, m_displayOptions, filterOptions)
+ );
+
+ CTextRendering::KeyTree tree;
+ CTextRendering::KeyTreeItem::Settings itemSettings;
+ itemSettings.highlight = false;
+
+ *list = sword::TOP;
+ while (!list->Error() && !progressWasCancelled()) {
+ tree.append( new CTextRendering::KeyTreeItem(QString::fromLocal8Bit((const char*)(*list)) , module, itemSettings) );
+
+ (*list)++;
+ }
+
+ const QString text = render->renderKeyTree(tree);
+ QApplication::clipboard()->setText(text);
+ return true;
+}
+
+
+bool CExportManager::copyKeyList(QList<CSwordKey*>& list, const Format format, const bool addText ) {
+ if (!list.count())
+ return false;
+
+ CSwordBackend::FilterOptions filterOptions = m_filterOptions;
+ filterOptions.footnotes = false;
+ filterOptions.strongNumbers = false;
+ filterOptions.morphTags = false;
+ filterOptions.lemmas = false;
+ filterOptions.scriptureReferences = false;
+ filterOptions.textualVariants = false;
+
+ CHTMLExportRendering::Settings settings(addText);
+ boost::scoped_ptr<CTextRendering> render (
+ (format == HTML)
+ ? new CHTMLExportRendering(settings, m_displayOptions, filterOptions)
+ : new CPlainTextExportRendering(settings, m_displayOptions, filterOptions)
+ );
+
+ CTextRendering::KeyTree tree;
+
+ CTextRendering::KeyTreeItem::Settings itemSettings;
+ itemSettings.highlight = false;
+
+ QListIterator<CSwordKey*> it(list);
+ while (it.hasNext() && !progressWasCancelled()){
+ CSwordKey* k = it.next();
+ tree.append( new CTextRendering::KeyTreeItem(k->key(), k->module(), itemSettings) );
+ incProgress();
+ };
+
+ const QString text = render->renderKeyTree(tree);
+ QApplication::clipboard()->setText(text);
+ if (!progressWasCancelled()){
+ closeProgressDialog();
+ }
+ return true;
+}
+
+bool CExportManager::printKeyList(sword::ListKey* list, CSwordModuleInfo* module, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions) {
+ CPrinter::KeyTreeItem::Settings settings;
+ CPrinter::KeyTree tree;
+
+ QString startKey, stopKey;
+ setProgressRange(list->Count());
+
+ (*list) = sword::TOP;
+ while (!list->Error() && !progressWasCancelled()) {
+ sword::VerseKey* vk = dynamic_cast<sword::VerseKey*>(list);
+ if (vk) {
+ startKey = QString::fromUtf8((const char*)(vk->LowerBound()) );
+ stopKey = QString::fromUtf8((const char*)(vk->UpperBound()) );
+ tree.append( new CPrinter::KeyTreeItem(startKey, stopKey, module, settings) );
+ }
+ else {
+ startKey = QString::fromUtf8((const char*)*list);
+ tree.append( new CPrinter::KeyTreeItem(startKey, module, settings) );
+ }
+
+ (*list)++;
+ incProgress();
+ }
+
+ boost::scoped_ptr<CPrinter> printer(new CPrinter(0, displayOptions, filterOptions));
+
+ if (!progressWasCancelled()) {
+ printer->printKeyTree(tree);
+ closeProgressDialog();
+ return true;
+ }
+
+ return false;
+}
+
+bool CExportManager::printKey( CSwordModuleInfo* module, const QString& startKey, const QString& stopKey, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions ) {
+ CPrinter::KeyTreeItem::Settings settings;
+ settings.keyRenderingFace =
+ displayOptions.verseNumbers
+ ? CPrinter::KeyTreeItem::Settings::SimpleKey
+ : CPrinter::KeyTreeItem::Settings::NoKey;
+
+ CPrinter::KeyTree tree;
+ if (startKey != stopKey) {
+ tree.append( new CPrinter::KeyTreeItem(startKey, stopKey, module, settings) );
+ }
+ else {
+ tree.append( new CPrinter::KeyTreeItem(startKey, module, settings) );
+ }
+
+ boost::scoped_ptr<CPrinter> printer(new CPrinter(0, displayOptions, filterOptions));
+ printer->printKeyTree(tree);
+ return true;
+}
+
+bool CExportManager::printKey( CSwordKey* key, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions) {
+ CPrinter::KeyTreeItem::Settings settings;
+ settings.keyRenderingFace =
+ displayOptions.verseNumbers
+ ? CPrinter::KeyTreeItem::Settings::SimpleKey
+ : CPrinter::KeyTreeItem::Settings::NoKey;
+
+ CPrinter::KeyTree tree;
+ tree.append( new CPrinter::KeyTreeItem(key->key(), key->module(), settings) );
+
+ boost::scoped_ptr<CPrinter> printer(new CPrinter(0, displayOptions, filterOptions));
+ printer->printKeyTree(tree);
+ return true;
+}
+
+/** Prints a key using the hyperlink created by CReferenceManager. */
+bool CExportManager::printByHyperlink( const QString& hyperlink, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions ) {
+ QString moduleName;
+ QString keyName;
+ CReferenceManager::Type type;
+
+ CReferenceManager::decodeHyperlink(hyperlink, moduleName, keyName, type);
+ if (moduleName.isEmpty()) {
+ moduleName = CReferenceManager::preferredModule(type);
+ }
+
+ CPrinter::KeyTree tree;
+ CPrinter::KeyTreeItem::Settings settings;
+ settings.keyRenderingFace =
+ displayOptions.verseNumbers
+ ? CPrinter::KeyTreeItem::Settings::SimpleKey
+ : CPrinter::KeyTreeItem::Settings::NoKey;
+
+ CSwordModuleInfo* module = backend()->findModuleByName(moduleName);
+ Q_ASSERT(module);
+
+ if (module) {
+ //check if we have a range of entries or a single one
+ if ((module->type() == CSwordModuleInfo::Bible) || (module->type() == CSwordModuleInfo::Commentary)) {
+ sword::ListKey verses = sword::VerseKey().ParseVerseList((const char*)keyName.toUtf8(), "Genesis 1:1", true);
+
+ for (int i = 0; i < verses.Count(); ++i) {
+ sword::VerseKey* element = dynamic_cast<sword::VerseKey*>(verses.GetElement(i));
+ if (element) {
+ const QString startKey = QString::fromUtf8(element->LowerBound().getText());
+ const QString stopKey = QString::fromUtf8(element->UpperBound().getText());
+
+ tree.append( new CPrinter::KeyTreeItem(startKey, stopKey, module, settings) );
+ }
+ else if (verses.GetElement(i)) {
+ const QString key = QString::fromUtf8(verses.GetElement(i)->getText());
+
+ tree.append( new CPrinter::KeyTreeItem(key, module, settings) );
+ }
+ }
+ }
+ else {
+ tree.append( new CPrinter::KeyTreeItem(keyName, module, settings) );
+ }
+ }
+
+ boost::scoped_ptr<CPrinter> printer(new CPrinter(0, displayOptions, filterOptions));
+ printer->printKeyTree(tree);
+ return true;
+}
+
+bool CExportManager::printKeyList(const QStringList& list,CSwordModuleInfo* module, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions) {
+ CPrinter::KeyTreeItem::Settings settings;
+ settings.keyRenderingFace =
+ displayOptions.verseNumbers
+ ? CPrinter::KeyTreeItem::Settings::SimpleKey
+ : CPrinter::KeyTreeItem::Settings::NoKey;
+
+ CPrinter::KeyTree tree;
+ setProgressRange(list.count());
+
+ const QStringList::const_iterator end = list.constEnd();
+ for (QStringList::const_iterator it = list.constBegin(); (it != end) && !progressWasCancelled(); ++it) {
+ tree.append( new CPrinter::KeyTreeItem(*it, module, settings) );
+ incProgress();
+ }
+
+ boost::scoped_ptr<CPrinter> printer(new CPrinter(0, displayOptions, filterOptions));
+
+ if (!progressWasCancelled()) {
+ printer->printKeyTree(tree);
+ closeProgressDialog();
+ return true;
+ }
+
+ return false;
+}
+
+/** Returns the string for the filedialogs to show the correct files. */
+const QString CExportManager::filterString( const Format format ) {
+ switch (format) {
+ case HTML:
+ return QObject::tr("HTML files") + QString(" (*.html *.htm);;") + QObject::tr("All files") + QString(" (*.*)");
+ case Text:
+ return QObject::tr("Text files") + QString(" (*.txt);;") + QObject::tr("All files") + QString(" (*.*)");
+ default:
+ return QObject::tr("All files") + QString(" (*.*)");
+ }
+}
+
+/** Returns a filename to save a file. */
+const QString CExportManager::getSaveFileName(const Format format) {
+ return QFileDialog::getSaveFileName(0, QObject::tr("Save file"), "", filterString(format), 0);
+}
+
+/** Returns a string containing the linebreak for the current format. */
+const QString CExportManager::lineBreak(const Format format) {
+ if (static_cast<bool>(m_displayOptions.lineBreaks))
+ return (format == HTML) ? QString::fromLatin1("<br/>\n") : QString::fromLatin1("\n");
+
+ return QString::null;
+}
+
+/** No descriptions */
+void CExportManager::setProgressRange( const int items ) {
+ if (QProgressDialog* dlg = progressDialog()) {
+ dlg->setMaximum(items);
+ dlg->setValue(0);
+ dlg->setMinimumDuration(0);
+ dlg->show();
+ // dlg->repaint();
+ qApp->processEvents(); //do not lock the GUI!
+ }
+}
+
+/** Creates the progress dialog with the correct settings. */
+QProgressDialog* CExportManager::progressDialog() {
+ if (!m_showProgress) {
+ return 0;
+ }
+
+ if (!m_progressDialog) {
+ m_progressDialog = new QProgressDialog(0, Qt::Dialog );
+ m_progressDialog->setLabelText(m_progressLabel);
+
+ m_progressDialog->setWindowTitle("BibleTime");
+ }
+
+ return m_progressDialog;
+}
+
+/** Increments the progress by one item. */
+void CExportManager::incProgress() {
+ if (QProgressDialog* dlg = progressDialog()) {
+ dlg->setValue( dlg->value() + 1 );
+ }
+}
+
+/** No descriptions */
+bool CExportManager::progressWasCancelled() {
+ if (QProgressDialog* dlg = progressDialog()) {
+ return dlg->wasCanceled();
+ }
+
+ return true;
+}
+
+/** Closes the progress dialog immediatly. */
+void CExportManager::closeProgressDialog() {
+ if (QProgressDialog* dlg = progressDialog()) {
+ dlg->close();
+ dlg->reset();
+ }
+
+ qApp->processEvents(); //do not lock the GUI!
+}
diff --git a/src/frontend/cexportmanager.h b/src/frontend/cexportmanager.h
new file mode 100644
index 0000000..210bb2b
--- /dev/null
+++ b/src/frontend/cexportmanager.h
@@ -0,0 +1,95 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CEXPORTMANAGER_H
+#define CEXPORTMANAGER_H
+
+#include "backend/config/cbtconfig.h"
+#include "backend/managers/cswordbackend.h"
+#include "util/cpointers.h"
+
+#include <QString>
+#include <QList>
+
+class ListKey;
+class CSwordKey;
+class CSwordModuleInfo;
+class QProgressDialog;
+
+/** Contains the functions to export text to disk, clipboard or printer.
+ * @author The BibleTime team
+ */
+class CExportManager : CPointers {
+public:
+ /** The format the export actions should have
+ */
+ enum Format {
+ HTML,
+ Text
+ };
+
+ CExportManager(const QString& caption, const bool showProgress = true, const QString& progressLabel = QString::null, const CSwordBackend::FilterOptions filterOptions = CBTConfig::getFilterOptionDefaults(), const CSwordBackend::DisplayOptions displayOptions = CBTConfig::getDisplayOptionDefaults());
+
+ bool saveKey(CSwordKey* key, const Format format, const bool addText);
+ bool saveKeyList(sword::ListKey* list, CSwordModuleInfo* module, const Format format, const bool addText);
+ bool saveKeyList(QList<CSwordKey*>& list, const Format format, const bool addText );
+
+ bool copyKey(CSwordKey* key, const Format format, const bool addText);
+ bool copyKeyList(sword::ListKey* list, CSwordModuleInfo* module, const Format format, const bool addText);
+ bool copyKeyList(QList<CSwordKey*>& list, const Format format, const bool addText );
+
+ bool printKey(CSwordKey* key, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions);
+ bool printKey( CSwordModuleInfo* module, const QString& startKey, const QString& stopKey, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions );
+ bool printByHyperlink(const QString& hyperlink, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions);
+ bool printKeyList(sword::ListKey* list, CSwordModuleInfo* module, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions);
+ bool printKeyList(const QStringList& list,CSwordModuleInfo* module, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions);
+
+protected: // Protected methods
+ /**
+ * Returns the string for the filedialogs to show the correct files.
+ */
+ const QString filterString( const Format format );
+ /**
+ * Returns a filename to save a file.
+ */
+ const QString getSaveFileName(const Format format);
+ /**
+ * Returns a string containing the linebreak for the current format.
+ */
+ const QString lineBreak( const Format format );
+
+private:
+ QString m_caption;
+ QString m_progressLabel;
+ bool m_showProgress;
+ CSwordBackend::FilterOptions m_filterOptions;
+ CSwordBackend::DisplayOptions m_displayOptions;
+
+ QProgressDialog* m_progressDialog;
+
+ /**
+ * Creates the progress dialog with the correct settings.
+ */
+ QProgressDialog* progressDialog();
+ /**
+ * Returns the CSS string used in HTML pages.
+ */
+ void setProgressRange( const int item );
+ /**
+ * Increments the progress by one item.
+ */
+ inline void incProgress();
+ bool progressWasCancelled();
+ /**
+ * Closes the progress dialog immediately.
+ */
+ void closeProgressDialog();
+};
+
+#endif
diff --git a/src/frontend/cinfodisplay.cpp b/src/frontend/cinfodisplay.cpp
new file mode 100644
index 0000000..0c167c4
--- /dev/null
+++ b/src/frontend/cinfodisplay.cpp
@@ -0,0 +1,466 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+// BibleTime includes
+#include "cinfodisplay.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/keys/cswordkey.h"
+#include "backend/keys/cswordversekey.h"
+#include "backend/managers/creferencemanager.h"
+#include "backend/managers/cdisplaytemplatemgr.h"
+
+#include "backend/config/cbtconfig.h"
+#include "frontend/crossrefrendering.h"
+
+#include "frontend/display/cdisplay.h"
+#include "frontend/display/creaddisplay.h"
+
+#include <boost/scoped_ptr.hpp>
+
+// Sword includes
+#include <listkey.h>
+
+// Qt includes
+#include <QLayout>
+#include <QLabel>
+#include <QRegExp>
+#include <QVBoxLayout>
+#include <QAction>
+#include <QDebug>
+#include <QSize>
+
+using namespace Rendering;
+using namespace sword;
+
+namespace InfoDisplay {
+
+CInfoDisplay::CInfoDisplay(QWidget *parent) : QWidget(parent)
+{
+ QVBoxLayout* layout = new QVBoxLayout(this);
+ setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
+
+ m_htmlPart = CDisplay::createReadInstance(0, this);
+ m_htmlPart->setMouseTracking(false); //we don't want strong/lemma/note mouse infos
+ m_htmlPart->view()->setAcceptDrops(false);
+
+ m_copyAction = new QAction(tr("Copy"), this);
+ m_copyAction->setShortcut( QKeySequence(Qt::CTRL + Qt::Key_C) );
+ QObject::connect(m_copyAction, SIGNAL(triggered()), m_htmlPart->connectionsProxy(), SLOT(copySelection()) );
+
+ connect(
+ m_htmlPart->connectionsProxy(),
+ SIGNAL(referenceClicked(const QString&, const QString&)),
+ SLOT(lookupInfo(const QString&, const QString&))
+ );
+
+ layout->addWidget(m_htmlPart->view());
+ QString initialMagText = tr("<small>This is the Mag viewer area. Hover the mouse over links or other items which include some data and the contents appear in the Mag after a short delay. Move the mouse into Mag rapidly or lock the view by pressing and holding Shift while moving the mouse.</small>");
+ m_htmlPart->setText(initialMagText);
+}
+
+
+CInfoDisplay::~CInfoDisplay() {
+ delete m_copyAction;
+}
+
+void CInfoDisplay::lookupInfo(const QString &mod_name, const QString &key_text) {
+ qDebug("CInfoDisplay::lookup");
+ qDebug() << mod_name << key_text;
+ CSwordModuleInfo* m = CPointers::backend()->findModuleByName(mod_name);
+ Q_ASSERT(m);
+ if (!m)
+ return;
+
+ boost::scoped_ptr<CSwordKey> key( CSwordKey::createInstance(m) );
+ key->key( key_text );
+
+ CDisplayTemplateMgr* mgr = CPointers::displayTemplateManager();
+ CDisplayTemplateMgr::Settings settings;
+ settings.pageCSS_ID = "infodisplay";
+ // settings.langAbbrev = "";
+ QString content = mgr->fillTemplate(CBTConfig::get
+ (CBTConfig::displayStyle), key->renderedText(), settings);
+ m_htmlPart->setText(content);
+ // qWarning("setting text:\n%s", content.latin1());
+}
+
+void CInfoDisplay::setInfo(const InfoType type, const QString& data) {
+ ListInfoData list;
+ list.append( qMakePair(type, data) );
+
+ setInfo(list);
+}
+
+
+void CInfoDisplay::setInfo(const ListInfoData& list) {
+ //if the widget is hidden it would be inefficient to render and display the data
+ if (!isVisible()) {
+ return;
+ }
+
+ if (list.count() == 0) {
+ m_htmlPart->setText("<html></html>");
+ return;
+ }
+
+ QString text;
+
+ ListInfoData::const_iterator end = list.end();
+ for (ListInfoData::const_iterator it = list.begin(); it != end; ++it) {
+ switch ( (*it).first ) {
+ case Lemma:
+ text.append( decodeStrongs( (*it).second ) );
+ continue;
+ case Morph:
+ text.append( decodeMorph( (*it).second ) );
+ continue;
+ case CrossReference:
+ text.append( decodeCrossReference( (*it).second ) );
+ continue;
+ case Footnote:
+ text.append( decodeFootnote( (*it).second ) );
+ continue;
+ case WordTranslation:
+ text.append( getWordTranslation( (*it).second ) );
+ continue;
+ case WordGloss:
+ //text.append( getWordTranslation( (*it).second ) );
+ continue;
+ case Abbreviation:
+ text.append( decodeAbbreviation( (*it).second ) );
+ continue;
+ case Text:
+ text.append( (*it).second );
+ continue;
+ default:
+ continue;
+ };
+ }
+
+ CDisplayTemplateMgr* mgr = CPointers::displayTemplateManager();
+ CDisplayTemplateMgr::Settings settings;
+ settings.pageCSS_ID = "infodisplay";
+ // settings.langAbbrev = "";
+ QString content = mgr->fillTemplate(CBTConfig::get
+ (CBTConfig::displayStyle), text, settings);
+
+ // qWarning("setting text:\n%s", content.latin1());
+
+ m_htmlPart->setText(content);
+}
+
+
+const QString CInfoDisplay::decodeAbbreviation( const QString& data ) {
+ // QStringList strongs = QStringList::split("|", data);
+ QString ret;
+ QString text = data;
+
+ ret.append(
+ QString("<div class=\"abbreviation\"><h3>%1: %2</h3><p>%3</p></div>")
+ .arg(tr("Abbreviation"))
+ .arg("text")
+ .arg(text));
+
+ return ret;
+}
+
+const QString CInfoDisplay::decodeCrossReference( const QString& data ) {
+ Q_ASSERT(!data.isEmpty());
+ if (data.isEmpty()) {
+ return QString("<div class=\"crossrefinfo\"><h3>%1</h3></div>")
+ .arg(tr("Cross references"));
+ }
+
+ // qWarning("setting crossref %s", data.latin1());
+
+ CSwordBackend::DisplayOptions dispOpts;
+ dispOpts.lineBreaks = false;
+ dispOpts.verseNumbers = true;
+
+ CSwordBackend::FilterOptions filterOpts;
+ filterOpts.headings = false;
+ filterOpts.strongNumbers = false;
+ filterOpts.morphTags = false;
+ filterOpts.lemmas = false;
+ filterOpts.footnotes = false;
+ filterOpts.scriptureReferences = false;
+
+ CrossRefRendering renderer(dispOpts, filterOpts);
+ CTextRendering::KeyTree tree;
+
+ // const bool isBible = true;
+ CSwordModuleInfo* module = CBTConfig::get
+ (CBTConfig::standardBible);
+
+ //a prefixed module gives the module to look into
+ QRegExp re("^[^ ]+:");
+ // re.setMinimal(true);
+ int pos = re.indexIn(data);
+ if (pos != -1) {
+ pos += re.matchedLength()-1;
+ }
+
+ if (pos > 0) {
+ const QString moduleName = data.left(pos);
+ // qWarning("found module %s", moduleName.latin1());
+ module = CPointers::backend()->findModuleByName(moduleName);
+ if (!module) {
+ module = CBTConfig::get
+ (CBTConfig::standardBible);
+ }
+ // Q_ASSERT(module);
+ }
+
+ //Q_ASSERT(module); //why? the existense of the module is tested later
+ CTextRendering::KeyTreeItem::Settings settings (
+ false,
+ CTextRendering::KeyTreeItem::Settings::CompleteShort
+ );
+
+ if (module && (module->type() == CSwordModuleInfo::Bible)) {
+ VerseKey vk;
+ sword::ListKey refs = vk.ParseVerseList((const char*)data.mid((pos == -1) ? 0 : pos+1).toUtf8(), "Gen 1:1", true);
+
+ for (int i = 0; i < refs.Count(); ++i) {
+ SWKey* key = refs.getElement(i);
+ Q_ASSERT(key);
+ VerseKey* vk = dynamic_cast<VerseKey*>(key);
+
+ CTextRendering::KeyTreeItem* itm = (CTextRendering::KeyTreeItem*)0; //explicit conversion for MS VS
+ if (vk && vk->isBoundSet()) { //render a range of keys
+ itm = new CTextRendering::KeyTreeItem(
+ QString::fromUtf8(vk->LowerBound().getText()),
+ QString::fromUtf8(vk->UpperBound().getText()),
+ module,
+ settings
+ );
+ }
+ else {
+ itm = new CTextRendering::KeyTreeItem(
+ QString::fromUtf8(key->getText()),
+ QString::fromUtf8(key->getText()),
+ module,
+ settings
+ );
+ }
+
+ Q_ASSERT(itm);
+
+ tree.append( itm );
+ }
+ }
+ else if (module) {
+ CTextRendering::KeyTreeItem* itm = new CTextRendering::KeyTreeItem(
+ data.mid((pos == -1) ? 0 : pos+1),
+ module,
+ settings
+ );
+ tree.append( itm );
+ }
+
+ // qWarning("rendered the tree: %s", renderer.renderKeyTree(tree).latin1());
+ //spanns containing rtl text need dir=rtl on their parent tag to be aligned properly
+ return QString("<div class=\"crossrefinfo\"><h3>%1</h3><div class=\"para\" dir=\"%2\">%3</div></div>")
+ .arg(tr("Cross references"))
+ .arg(module ? ((module->textDirection() == CSwordModuleInfo::LeftToRight) ? "ltr" : "rtl") : "")
+ .arg(renderer.renderKeyTree(tree));
+}
+
+/*!
+ \fn CInfoDisplay::decodeFootnote( const QString& data )
+ */
+const QString CInfoDisplay::decodeFootnote( const QString& data ) {
+ QStringList list = data.split("/");
+ Q_ASSERT(list.count() >= 3);
+ if (!list.count()) {
+ return QString::null;
+ }
+
+ const QString modulename = list.first();
+ const QString swordFootnote = list.last();
+
+ // remove the first and the last and then rejoin it to get a key
+ list.pop_back(); list.pop_front();
+ const QString keyname = list.join("/");
+
+ CSwordModuleInfo* module = CPointers::backend()->findModuleByName(modulename);
+ if (!module) {
+ return QString::null;
+ }
+
+ boost::scoped_ptr<CSwordKey> key( CSwordKey::createInstance(module) );
+ key->key(keyname);
+ key->renderedText(); //force entryAttributes
+
+ const char* note =
+ module->module()->getEntryAttributes()
+ ["Footnote"][swordFootnote.toLatin1().data()]["body"].c_str();
+
+ QString text = module->isUnicode() ? QString::fromUtf8(note) : QString(note);
+ text = QString::fromUtf8(module->module()->RenderText(
+ module->isUnicode()
+ ? (const char*)text.toUtf8()
+ : (const char*)text.toLatin1()
+ ));
+
+ return QString("<div class=\"footnoteinfo\"><h3>%1</h3><p>%2</p></div>")
+ .arg(tr("Footnote"))
+ .arg(text);
+}
+
+const QString CInfoDisplay::decodeStrongs( const QString& data ) {
+ QStringList strongs = data.split("|");
+ QString ret;
+
+ QStringList::const_iterator end = strongs.end();
+ for (QStringList::const_iterator it = strongs.begin(); it != end; ++it) {
+ CSwordModuleInfo* const module = CBTConfig::get
+ (
+ ((*it).left(1) == QString("H")) ?
+ CBTConfig::standardHebrewStrongsLexicon :
+ CBTConfig::standardGreekStrongsLexicon
+ );
+
+ QString text;
+ if (module) {
+ boost::scoped_ptr<CSwordKey> key( CSwordKey::createInstance(module) );
+ key->key( (*it).mid(1) ); //skip H or G (language sign), will have to change later if we have better modules
+ text = key->renderedText();
+ }
+ //if the module could not be found just display an empty lemma info
+
+ ret.append(
+ QString("<div class=\"strongsinfo\"><h3>%1: %2</h3><p>%3</p></div>")
+ .arg(tr("Strongs"))
+ .arg(*it)
+ .arg(text)
+ );
+ }
+
+ return ret;
+}
+
+const QString CInfoDisplay::decodeMorph( const QString& data ) {
+ QStringList morphs = data.split("|");
+ QString ret;
+
+ foreach(QString morph, morphs) {
+ //qDebug() << "CInfoDisplay::decodeMorph, morph: " << morph;
+ CSwordModuleInfo* module = 0;
+ bool skipFirstChar = false;
+ QString value = "";
+ QString valueClass = "";
+
+ int valStart = morph.indexOf(':');
+ if (valStart > -1) {
+ valueClass = morph.mid(0, valStart);
+ //qDebug() << "valueClass: " << valueClass;
+ module = CPointers::backend()->findModuleByName( valueClass );
+ }
+ value = morph.mid(valStart+1); //works for prepended module and without (-1 +1 == 0).
+
+ // if we don't have a class assigned or desired one isn't installed...
+ if (!module) {
+ // Morphs usually don't have [GH] prepended, but some old OLB
+ // codes do. We should check if we're digit after first char
+ // to better guess this.
+ if (value.size() > 1 && value.at(1).isDigit()) {
+ switch (value.at(0).toLatin1()) {
+ case 'G':
+ module = CBTConfig::get
+ (CBTConfig::standardGreekMorphLexicon);
+ skipFirstChar = true;
+ break;
+ case 'H':
+ module = CBTConfig::get
+ (CBTConfig::standardHebrewMorphLexicon);
+ skipFirstChar = true;
+ break;
+ default:
+ skipFirstChar = false;
+ //TODO: we can't tell here if it's a greek or hebrew moprh code, that's a problem we have to solve
+ // module = CBTConfig::get(CBTConfig::standardGreekMorphLexicon);
+ break;
+ }
+ }
+ //if it is still not set use the default
+ if (!module) {
+ module = CBTConfig::get
+ (CBTConfig::standardGreekMorphLexicon);
+ }
+ }
+
+ QString text;
+ //Q_ASSERT(module);
+ if (module) {
+ boost::scoped_ptr<CSwordKey> key( CSwordKey::createInstance(module) );
+
+ //skip H or G (language sign) if we have to skip it
+ const bool isOk = key->key( skipFirstChar ? value.mid(1) : value );
+ //Q_ASSERT(isOk);
+ if (!isOk) { //try to use the other morph lexicon, because this one failed with the current morph code
+ key->module(CBTConfig::get
+ (CBTConfig::standardHebrewMorphLexicon));
+ key->key( skipFirstChar ? value.mid(1) : value );
+ }
+
+ text = key->renderedText();
+ }
+
+ //if the module wasn't found just display an empty morph info
+ ret.append( QString("<div class=\"morphinfo\"><h3>%1: %2</h3><p>%3</p></div>")
+ .arg(tr("Morphology"))
+ .arg(value)
+ .arg(text)
+ );
+ }
+
+ return ret;
+}
+
+const QString CInfoDisplay::getWordTranslation( const QString& data ) {
+ CSwordModuleInfo* const module = CBTConfig::get
+ (CBTConfig::standardLexicon);
+ if (!module) {
+ return QString::null;
+ }
+
+ boost::scoped_ptr<CSwordKey> key( CSwordKey::createInstance(module) );
+ key->key( data );
+ if (key->key().toUpper() != data.toUpper()) { //key not present in the lexicon
+ return QString::null;
+ }
+
+ QString ret = QString("<div class=\"translationinfo\"><h3>%1: %2</h3><p>%3</p></div>")
+ .arg(tr("Word lookup"))
+ .arg(data)
+ .arg(key->renderedText());
+
+ return ret;
+}
+
+
+/*!
+ \fn CInfoDisplay::clearInfo()
+ */
+void CInfoDisplay::clearInfo() {
+ CDisplayTemplateMgr* tmgr = CPointers::displayTemplateManager();
+ CDisplayTemplateMgr::Settings settings;
+ settings.pageCSS_ID = "infodisplay";
+
+ m_htmlPart->setText( tmgr->fillTemplate(CBTConfig::get(CBTConfig::displayStyle), QString::null, settings) );
+}
+
+QSize CInfoDisplay::sizeHint() const
+{
+ return QSize(100,150);
+}
+
+} //end of namespace InfoDisplay
diff --git a/src/frontend/cinfodisplay.h b/src/frontend/cinfodisplay.h
new file mode 100644
index 0000000..040667f
--- /dev/null
+++ b/src/frontend/cinfodisplay.h
@@ -0,0 +1,71 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CINFODISPLAY_H
+#define CINFODISPLAY_H
+
+//Backend
+#include "backend/rendering/ctextrendering.h"
+
+//Qt includes
+#include <QWidget>
+#include <QPair>
+#include <QList>
+
+//class forward declarations
+class CReadDisplay;
+class QAction;
+class QSize;
+
+namespace InfoDisplay {
+
+class CInfoDisplay : public QWidget {
+ Q_OBJECT
+public:
+ enum InfoType {
+ Abbreviation,
+ CrossReference,
+ Footnote,
+ Lemma,
+ Morph,
+ WordTranslation,
+ WordGloss,
+ Text
+ };
+
+ typedef QPair<InfoType, QString> InfoData;
+ typedef QList<InfoData> ListInfoData;
+
+ CInfoDisplay(QWidget *parent = 0);
+ virtual ~CInfoDisplay();
+
+ void setInfo(const InfoType, const QString& data);
+ void setInfo(const ListInfoData&);
+ void clearInfo();
+ QSize sizeHint() const;
+
+protected:
+ const QString decodeAbbreviation( const QString& data );
+ const QString decodeCrossReference( const QString& data );
+ const QString decodeFootnote( const QString& data );
+ const QString decodeStrongs( const QString& data );
+ const QString decodeMorph( const QString& data );
+ const QString getWordTranslation( const QString& data );
+
+protected slots:
+ void lookupInfo(const QString &, const QString &);
+
+private:
+ CReadDisplay* m_htmlPart;
+ QAction* m_copyAction;
+};
+
+} //end of InfoDisplay namespace
+
+#endif
diff --git a/src/frontend/cinputdialog.cpp b/src/frontend/cinputdialog.cpp
new file mode 100644
index 0000000..59b178d
--- /dev/null
+++ b/src/frontend/cinputdialog.cpp
@@ -0,0 +1,95 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+//own includes
+#include "cinputdialog.h"
+#include "util/dialogutil.h"
+
+//Qt includes
+#include <QDialog>
+#include <QWidget>
+#include <QLabel>
+#include <QTextEdit>
+#include <QPushButton>
+#include <QDialogButtonBox>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+
+#include <QDebug>
+
+
+CInputDialog::CInputDialog
+ (const QString& caption, const QString& description, const QString& text, QWidget *parent, Qt::WindowFlags wflags )
+ : QDialog(parent, wflags)
+{
+ QVBoxLayout *vboxLayout;
+ QLabel *label;
+ QHBoxLayout *hboxLayout;
+ QPushButton *clearButton;
+ QSpacerItem *spacerItem;
+ QDialogButtonBox *buttonBox;
+
+ setWindowTitle(caption);
+
+ resize(400, 300);
+ vboxLayout = new QVBoxLayout(this);
+ label = new QLabel(description, this);
+ vboxLayout->addWidget(label);
+
+ m_textEdit = new QTextEdit(this);
+ vboxLayout->addWidget(m_textEdit);
+ m_textEdit->setWordWrapMode( QTextOption::WordWrap );
+ m_textEdit->setText(text);
+ if (!text.isEmpty())
+ m_textEdit->selectAll();
+
+ hboxLayout = new QHBoxLayout();
+ clearButton = new QPushButton(this);
+ clearButton->setText(tr("Clear"));
+ hboxLayout->addWidget(clearButton);
+ spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
+ hboxLayout->addItem(spacerItem);
+ buttonBox = new QDialogButtonBox(this);
+ buttonBox->setOrientation(Qt::Horizontal);
+ buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok);
+ util::prepareDialogBox(buttonBox);
+ hboxLayout->addWidget(buttonBox);
+
+ vboxLayout->addLayout(hboxLayout);
+
+ QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+ QObject::connect(clearButton, SIGNAL(clicked()), m_textEdit, SLOT(clear()));
+
+ m_textEdit->setFocus();
+}
+
+/** Returns the text entered at the moment. */
+const QString CInputDialog::text() {
+ return m_textEdit->toPlainText();
+}
+
+/** A static function to get some using CInputDialog. */
+const QString CInputDialog::getText
+ ( const QString& caption, const QString& description, const QString& text, bool* ok, QWidget* parent, Qt::WindowFlags wflags)
+{
+ CInputDialog* dlg = new CInputDialog(caption, description, text, parent, wflags);
+
+ QString ret = QString::null;
+ *ok = (dlg->exec() == QDialog::Accepted)?true:false;
+ if (*ok) {
+ //qDebug() << "dialog was accepted, return text: " << dlg->text();
+ ret = dlg->text();
+ }
+
+ delete dlg;
+ return ret;
+}
diff --git a/src/frontend/cinputdialog.h b/src/frontend/cinputdialog.h
new file mode 100644
index 0000000..7cd30b2
--- /dev/null
+++ b/src/frontend/cinputdialog.h
@@ -0,0 +1,43 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CINPUTDIALOG_H
+#define CINPUTDIALOG_H
+
+
+#include <QDialog>
+
+class QTextEdit;
+class QWidget;
+
+/** This is a small input dialog with
+ * a multiline edit for the text input.
+ * @author The BibleTime team
+ */
+class CInputDialog : public QDialog {
+ Q_OBJECT
+public:
+ CInputDialog(const QString& caption, const QString& description, const QString& text, QWidget *parent=0, Qt::WindowFlags wflags = Qt::Dialog);
+ /**
+ * A static function to get some using CInputDialog.
+ */
+ static const QString getText( const QString& caption, const QString& description, const QString& text = QString::null, bool* ok = 0, QWidget* parent = 0, Qt::WindowFlags wflags = Qt::Dialog);
+ /**
+ * Returns the text entered at the moment.
+ */
+ const QString text();
+ // ~CInputDialog();
+
+private:
+ QTextEdit* m_textEdit;
+};
+
+#endif
diff --git a/src/frontend/cmdiarea.cpp b/src/frontend/cmdiarea.cpp
new file mode 100644
index 0000000..69f3e7a
--- /dev/null
+++ b/src/frontend/cmdiarea.cpp
@@ -0,0 +1,244 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cmdiarea.h"
+
+//QT includes
+#include <QTimer>
+#include <QEvent>
+#include <QWindowStateChangeEvent>
+#include <QMdiSubWindow>
+#include <QDebug>
+
+CMDIArea::CMDIArea(QWidget *parent) : QMdiArea(parent),
+ m_mdiArrangementMode(ArrangementModeManual)
+{
+ setActivationOrder( CreationOrder ); //keep window order consistent
+ connect(this, SIGNAL(subWindowActivated(QMdiSubWindow*)), this, SLOT(slotClientActivated(QMdiSubWindow*)));
+}
+
+QMdiSubWindow* CMDIArea::addSubWindow(QWidget * widget, Qt::WindowFlags windowFlags)
+{
+ QMdiSubWindow* subWindow = QMdiArea::addSubWindow(widget, windowFlags);
+ subWindow->installEventFilter(this);
+
+ //If we do have a maximized Window, set it to normal so that the new window can be seen
+ if (activeSubWindow() && activeSubWindow()->isMaximized()){
+ activeSubWindow()->showNormal();
+ }
+
+ if (m_mdiArrangementMode == ArrangementModeManual)
+ {
+ subWindow->resize(400, 400); //set the window to be big enough
+ subWindow->raise();
+ }
+ else
+ {
+ triggerWindowUpdate();
+ }
+ return subWindow;
+}
+
+void CMDIArea::deleteAll() {
+ closeAllSubWindows();
+}
+
+void CMDIArea::setMDIArrangementMode( const MDIArrangementMode newArrangementMode ) {
+ m_mdiArrangementMode = newArrangementMode;
+ triggerWindowUpdate();
+}
+
+CMDIArea::MDIArrangementMode CMDIArea::getMDIArrangementMode(void) const {
+ return m_mdiArrangementMode;
+}
+
+void CMDIArea::myTileVertical() {
+ if (!updatesEnabled() || !usableWindowList().count() ) {
+ return;
+ }
+
+ QList<QMdiSubWindow*> windows = usableWindowList();
+ if (activeSubWindow() && activeSubWindow()->isMaximized()){
+ if (activeSubWindow()->size() != this->size()) {
+ activeSubWindow()->resize(this->size());
+ }
+ }
+ else if (windows.count() == 1) {
+ windows.at(0)->showMaximized();
+ }
+ else {
+ setUpdatesEnabled(false);
+ QMdiSubWindow* active = activeSubWindow();
+ QMdiArea::tileSubWindows();
+ if (active) active->setFocus();
+ setUpdatesEnabled(true);
+ }
+ emitWindowCaptionChanged();
+}
+
+void CMDIArea::myTileHorizontal() {
+ if (!updatesEnabled() || !usableWindowList().count() ) {
+ return;
+ }
+
+ QList<QMdiSubWindow*> windows = usableWindowList();
+
+ if (activeSubWindow() && activeSubWindow()->isMaximized()){
+ if (activeSubWindow()->size() != this->size()) {
+ activeSubWindow()->resize(this->size());
+ }
+ }
+ else if (windows.count() == 1) {
+ windows.at(0)->showMaximized();
+ }
+ else {
+ setUpdatesEnabled(false);
+
+ QMdiSubWindow* active = activeSubWindow();
+
+ const int heightForEach = height() / windows.count();
+ unsigned int y = 0;
+ foreach (QMdiSubWindow *window, windows) {
+ window->showNormal();
+
+ const int preferredHeight = window->minimumHeight() + window->baseSize().height();
+ const int actHeight = qMax(heightForEach, preferredHeight);
+
+ window->setGeometry( 0, y, width(), actHeight );
+ y += actHeight;
+ }
+ active->setFocus();
+ setUpdatesEnabled(true);
+ }
+ emitWindowCaptionChanged();
+}
+
+void CMDIArea::myCascade() {
+ if (!updatesEnabled() || !usableWindowList().count() ) {
+ return;
+ }
+
+ QList<QMdiSubWindow*> windows = usableWindowList();
+
+ if (activeSubWindow() && activeSubWindow()->isMaximized()){
+ if (activeSubWindow()->size() != this->size()) {
+ activeSubWindow()->resize(this->size());
+ }
+ }
+ else if (windows.count() == 1) {
+ windows.at(0)->showMaximized();
+ }
+ else {
+ setUpdatesEnabled(false);
+
+ QMdiSubWindow* active = activeSubWindow();
+
+ const unsigned int offsetX = 40;
+ const unsigned int offsetY = 40;
+ const unsigned int windowWidth = width() - (windows.count()-1)*offsetX;
+ const unsigned int windowHeight = height() - (windows.count()-1)*offsetY;
+ unsigned int x = 0;
+ unsigned int y = 0;
+
+ foreach (QMdiSubWindow* window, windows) {
+ if (window == active) { //leave out the active window which should be the top window
+ continue;
+ }
+ window->raise(); //make it the on-top-of-window-stack window to make sure they're in the right order
+ window->setGeometry(x, y, windowWidth, windowHeight);
+ x += offsetX;
+ y += offsetY;
+ }
+ active->setGeometry(x, y, windowWidth, windowHeight);
+ active->raise();
+ active->activateWindow();
+
+ setUpdatesEnabled(true);
+ }
+ emitWindowCaptionChanged();
+}
+
+void CMDIArea::emitWindowCaptionChanged() {
+ QString appCaption;
+ if (activeSubWindow()) {
+ appCaption = activeSubWindow()->windowTitle();
+ }
+ emit sigSetToplevelCaption(appCaption);
+}
+
+QList<QMdiSubWindow*> CMDIArea::usableWindowList() {
+ //Take care: when new windows are added, they will not appear
+ //in subWindowList() when their ChildAdded-Event is triggered
+ QList<QMdiSubWindow*> ret;
+ foreach(QMdiSubWindow* w, subWindowList())
+ {
+ if (w->isMinimized() || w->isHidden()) { //not usable for us
+ continue;
+ }
+ ret.append( w );
+ }
+ return ret;
+}
+
+void CMDIArea::slotClientActivated(QMdiSubWindow* client) {
+ if (!client || !updatesEnabled()) {
+ return;
+ }
+ emit sigSetToplevelCaption( client->windowTitle().trimmed() );
+}
+
+//resize event of the MDI area itself, update layout if necessary
+void CMDIArea::resizeEvent(QResizeEvent* /*e*/) {
+ //do not call QMdiArea::resizeEvent(e), this would mess up our layout
+ if (updatesEnabled()) triggerWindowUpdate();
+}
+
+//handle events of the client windows to update layout if necessary
+bool CMDIArea::eventFilter(QObject *o, QEvent *e) {
+ QMdiSubWindow* w = dynamic_cast<QMdiSubWindow*>(o);
+ if (!w) return false; //let the event be handled by other filters too
+
+ if (e->type() == QEvent::WindowStateChange) {
+ Qt::WindowStates newState = w->windowState();
+ Qt::WindowStates oldState = ((QWindowStateChangeEvent*)e)->oldState();
+
+ //Do not handle window activation or deactivation here, it will produce wrong
+ //results because this event is handled too early. Let slotClientActivated() handle this.
+
+ bool needsLayoutUpdate = false;
+ //Window was maximized or un-maximized
+ if ((newState ^ oldState) & Qt::WindowMaximized) needsLayoutUpdate = true;
+ //Window was minimized or de-minimized
+ if ((newState ^ oldState) & Qt::WindowMinimized) needsLayoutUpdate = true;
+ //update Layout?
+ if (needsLayoutUpdate) triggerWindowUpdate();
+ }
+ if (e->type() == QEvent::Close) {
+ triggerWindowUpdate();
+ }
+ return false; //let the event be handled by other filters too
+}
+
+void CMDIArea::triggerWindowUpdate() {
+ if (updatesEnabled()) {
+ switch (m_mdiArrangementMode) {
+ case ArrangementModeTileVertical:
+ QTimer::singleShot(0, this, SLOT(myTileVertical()));
+ break;
+ case ArrangementModeTileHorizontal:
+ QTimer::singleShot(0, this, SLOT(myTileHorizontal()));
+ break;
+ case ArrangementModeCascade:
+ QTimer::singleShot(0, this, SLOT(myCascade()));
+ break;
+ default:
+ break;
+ }
+ }
+}
diff --git a/src/frontend/cmdiarea.h b/src/frontend/cmdiarea.h
new file mode 100644
index 0000000..682ca12
--- /dev/null
+++ b/src/frontend/cmdiarea.h
@@ -0,0 +1,116 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CMDIAREA_H
+#define CMDIAREA_H
+
+//Qt includes
+#include <QMdiArea>
+#include <QList>
+
+class CSwordModuleInfo;
+class QEvent;
+class QResizeEvent;
+class QMdiSubWindow;
+
+/** The MDI widget we use in BibleTime.
+ * Enhances QMdiArea.
+ */
+class CMDIArea : public QMdiArea {
+ Q_OBJECT
+ Q_PROPERTY(MDIArrangementMode m_mdiArrangementMode READ getMDIArrangementMode WRITE setMDIArrangementMode)
+
+public:
+ /**
+ * The options you can set for this widget.
+ */
+ enum MDIArrangementMode {
+ ArrangementModeTileVertical = 1,
+ ArrangementModeTileHorizontal = 2,
+ ArrangementModeCascade = 3,
+ ArrangementModeManual = 4,
+ MDIArrangementModeMIN = ArrangementModeTileVertical,
+ MDIArrangementModeMAX = ArrangementModeManual
+ };
+ CMDIArea(QWidget *parent);
+ /** Reimplementation
+ */
+ virtual QMdiSubWindow* addSubWindow(QWidget* widget, Qt::WindowFlags windowFlags = 0);
+ /**
+ */
+ void setMDIArrangementMode( const MDIArrangementMode );
+ /** */
+ MDIArrangementMode getMDIArrangementMode(void) const;
+ /**
+ */
+ void emitWindowCaptionChanged();
+ /**
+ * Forces an update of the currently chosen window arrangement.
+ */
+ void triggerWindowUpdate();
+ /** Lists all subWindows which are not minimized or hidden
+ */
+ QList<QMdiSubWindow*> usableWindowList();
+
+public slots:
+ /**
+ * Called whan a client window was activated
+ */
+ void slotClientActivated(QMdiSubWindow* client);
+ /**
+ * Deletes all the presenters in the MDI area.
+ */
+ void deleteAll();
+ /** Our own cascade version which, if only one window is left, shows this maximized.
+ * Also necessary for autoCasacde feature
+ */
+ void myCascade();
+ /** Our own cascade version which, if only one window is left, shows this maximized.
+ * Also necessary for autoTile feature
+ */
+ void myTileVertical();
+ /** Horizontal tile function
+ * This function was taken from Qt's MDI example.
+ */
+ void myTileHorizontal();
+ /**
+ * Emits the signal to create a new display window in the MDI area.
+ */
+ inline void emitCreateDisplayWindow(QList<CSwordModuleInfo*> modules, const QString keyName);
+
+signals: // Signals
+ /**
+ * Emits a signal to set the acption of the toplevel widget.
+ */
+ void sigSetToplevelCaption(const QString&);
+ /**
+ */
+ void createReadDisplayWindow(QList<CSwordModuleInfo*> modules, const QString& keyName);
+
+private:
+ /**
+ * Reimplementation
+ */
+ virtual void resizeEvent(QResizeEvent* e);
+ /**
+ * Used to handle Events of MDI windows
+ * */
+ bool eventFilter( QObject *o, QEvent *e );
+ /**
+ */
+ MDIArrangementMode m_mdiArrangementMode;
+};
+
+/** Emits the signal to create a new display window in the MDI area. */
+inline void CMDIArea::emitCreateDisplayWindow(QList<CSwordModuleInfo*> modules, const QString keyName) {
+ emit createReadDisplayWindow(modules, keyName);
+}
+
+
+#endif
diff --git a/src/frontend/cmodulechooserdialog.cpp b/src/frontend/cmodulechooserdialog.cpp
new file mode 100644
index 0000000..e7b96c8
--- /dev/null
+++ b/src/frontend/cmodulechooserdialog.cpp
@@ -0,0 +1,156 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cmodulechooserdialog.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/managers/cswordbackend.h"
+#include "backend/btmoduletreeitem.h"
+
+#include "util/cpointers.h"
+#include "util/cresmgr.h"
+#include "util/ctoolclass.h"
+#include "util/dialogutil.h"
+#include "util/directoryutil.h"
+#include "backend/config/cbtconfig.h"
+
+#include <QDialog>
+#include <QButtonGroup>
+#include <QDialogButtonBox>
+#include <QHBoxLayout>
+#include <QSpacerItem>
+#include <QTreeWidget>
+#include <QVBoxLayout>
+#include <QStringList>
+#include <QDebug>
+#include <QHeaderView>
+#include <QLabel>
+
+
+CModuleChooserDialog::CModuleChooserDialog( QWidget* parent, QString title, QString label, QList<CSwordModuleInfo*>* allModules)
+ : QDialog(parent),
+ m_title(title),
+ m_labelText(label)
+{
+ m_grouping = (BTModuleTreeItem::Grouping)CBTConfig::get(CBTConfig::bookshelfGrouping);
+ m_filters = QList<BTModuleTreeItem::Filter*>();
+ if (!allModules) {
+ m_moduleList = CPointers::backend()->moduleList();
+ }
+ else m_moduleList = *allModules;
+}
+
+/**
+* Call init() after the constructor, either in the end of your own constructor or from outside.
+*/
+void CModuleChooserDialog::init()
+{
+ //Set the flag to destroy when closed - otherwise eats memory
+ setAttribute(Qt::WA_DeleteOnClose);
+ setWindowTitle(m_title);
+ initView();
+ initTree();
+}
+
+/** Initializes the view of this dialog */
+void CModuleChooserDialog::initView()
+{
+ //TODO: choose the button text?
+
+ QVBoxLayout *vboxLayout;
+ QHBoxLayout *hboxLayout;
+ QSpacerItem *spacerItem;
+
+ vboxLayout = new QVBoxLayout(this);
+
+ QLabel* label = CToolClass::explanationLabel(this, QString::null, m_labelText);
+ vboxLayout->addWidget(label);
+
+ m_moduleChooser = new QTreeWidget(this);
+ m_moduleChooser->header()->hide();
+
+ vboxLayout->addWidget(m_moduleChooser);
+
+ hboxLayout = new QHBoxLayout();
+
+ spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
+ hboxLayout->addItem(spacerItem);
+
+ m_buttonBox = new QDialogButtonBox(this);
+ m_buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
+ util::prepareDialogBox(m_buttonBox);
+ hboxLayout->addWidget(m_buttonBox);
+
+ vboxLayout->addLayout(hboxLayout);
+
+ QObject::connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(slotOk()) );
+ //The QDialog doc is a bit unclear but calling reject also destroys the dialog
+ // in this situation.
+ QObject::connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()) );
+}
+
+
+void CModuleChooserDialog::initTree()
+{
+ //qDebug("CModuleChooserDialog::initTree");
+
+ // See BTModuleTreeItem documentation.
+ BTModuleTreeItem root(m_filters, m_grouping, &m_moduleList);
+ createModuleTree(&root, m_moduleChooser->invisibleRootItem());
+
+}
+
+void CModuleChooserDialog::createModuleTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem)
+{
+ foreach (BTModuleTreeItem* i, item->children()) {
+ createModuleTree(i, new QTreeWidgetItem(widgetItem));
+ }
+ if (item->type() != BTModuleTreeItem::Root) {
+ widgetItem->setText(0, item->text());
+ if (item->type() == BTModuleTreeItem::Category || item->type() == BTModuleTreeItem::Language) {
+ widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsTristate);
+ }
+ if (item->type() == BTModuleTreeItem::Module) {
+ initModuleItem(item, widgetItem);
+ }
+ }
+}
+
+
+/** Emits the signal with the list of the selected modules. */
+void CModuleChooserDialog::slotOk()
+{
+ Q_ASSERT(m_moduleChooser);
+ //create the list of selected modules
+ QList<CSwordModuleInfo*> mods;
+ QTreeWidgetItemIterator it( m_moduleChooser );
+ for ( ; *it; ++it ) {
+ //add the module to list if the box is checked
+ if ((*it)->checkState(0) == Qt::Checked) {
+ qDebug("was checked");
+ for (QList<CSwordModuleInfo*>::iterator all_iter(m_moduleList.begin()); all_iter != m_moduleList.end(); ++all_iter) {
+ if ((*all_iter)->name() == (*it)->text(0)) {
+ qDebug("append");
+ mods.append(*all_iter);
+ break;
+ }
+ }
+
+ }
+ }
+
+ // The selection is handled first, then the dialog is closed and destroyed.
+ emit modulesChanged(mods, m_moduleChooser);
+ QDialog::done(QDialog::Accepted);
+}
+
+QPushButton* CModuleChooserDialog::okButton()
+{
+ return m_buttonBox->button(QDialogButtonBox::Ok);
+}
diff --git a/src/frontend/cmodulechooserdialog.h b/src/frontend/cmodulechooserdialog.h
new file mode 100644
index 0000000..2f1e93c
--- /dev/null
+++ b/src/frontend/cmodulechooserdialog.h
@@ -0,0 +1,103 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2007 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CMODULECHOOSERDIALOG_H
+#define CMODULECHOOSERDIALOG_H
+
+class CSwordModuleInfo;
+#include "backend/btmoduletreeitem.h"
+
+#include <QDialog>
+#include <QList>
+#include <QTreeWidget>
+
+
+class QDialogButtonBox;
+
+
+/**
+* Abstract dialog which lets the user select modules with checkboxes.
+* The dialog will be destroyed after closing. Connect the modulesChanged() signal
+* to handle the selection before the dialog is destroyed.
+*/
+class CModuleChooserDialog : public QDialog
+{
+ Q_OBJECT
+public:
+
+ /**
+ * Use your own constructor to set extra members.
+ * Filters list is given to the module tree creator, see BTModuleTreeItem.
+ * For module list see BTModuleTreeItem constructor documentation.
+ * Call init() after the constructor, either in the end of your own constructor or from outside.
+ */
+ CModuleChooserDialog(QWidget* parent, QString title, QString label, QList<CSwordModuleInfo*>* allModules = 0);
+
+ virtual ~CModuleChooserDialog() {}
+
+ /** Call this after/from the constructor.*/
+ void init();
+
+ /** Set the module tree grouping.
+ * Initially it's taken from the CBTConfig so it needs to be set only if that default is not adequate.
+ * This must be called before the tree is initialized, i.e. before init().
+ */
+ void setGrouping(BTModuleTreeItem::Grouping grouping) {m_grouping = grouping;}
+
+ /** Set the module tree filters. See setGrouping() for the calling convention and
+ * BTModuleTreeItem for the filters. By default the filters list is empty.
+ */
+ void setFilters(QList<BTModuleTreeItem::Filter*> filters) {m_filters = filters;}
+
+ QTreeWidget* treeWidget() {return m_moduleChooser;}
+
+ QPushButton* okButton();
+
+signals:
+
+ /** The signal is sent when the OK button is clicked. The list includes the selected (checked) modules. The tree widget can be used through the pointer for more complicated actions. */
+ void modulesChanged(QList<CSwordModuleInfo*>, QTreeWidget*);
+
+protected:
+
+ /**
+ * Initialize one tree widget item.
+ * To be overridden. This is called for each QTreeWidgetItem when it is created.
+ * Here you can set for example the checked status of the item.
+ */
+ virtual void initModuleItem(BTModuleTreeItem* btItem, QTreeWidgetItem* widgetItem) = 0;
+
+
+
+private slots:
+
+ /** Emits the signal modulesChanged() with the list of the selected modules. */
+ void slotOk();
+
+private:
+ /** Initialize the module tree. */
+ void initTree();
+
+ /** Initializes the view of this dialog.*/
+ void initView();
+
+ /** Call this from initTree(). */
+ void createModuleTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem);
+
+ QTreeWidget *m_moduleChooser;
+ QDialogButtonBox *m_buttonBox;
+ QString m_title;
+ QString m_labelText;
+ QList<BTModuleTreeItem::Filter*> m_filters;
+ BTModuleTreeItem::Grouping m_grouping;
+ QList<CSwordModuleInfo*> m_moduleList;
+};
+
+
+#endif
diff --git a/src/frontend/cmoduleindexdialog.cpp b/src/frontend/cmoduleindexdialog.cpp
new file mode 100644
index 0000000..7edcd8c
--- /dev/null
+++ b/src/frontend/cmoduleindexdialog.cpp
@@ -0,0 +1,104 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cmoduleindexdialog.h"
+
+#include "util/cpointers.h"
+#include "backend/managers/cswordbackend.h"
+
+#include <boost/scoped_ptr.hpp>
+
+//Qt includes
+#include <QString>
+#include <QProgressDialog>
+#include <QDebug>
+#include <QApplication>
+#include <QMessageBox>
+
+CModuleIndexDialog* CModuleIndexDialog::getInstance() {
+ qDebug("CModuleIndexDialog::getInstance");
+ static CModuleIndexDialog* instance = 0;
+ if (instance == 0) {
+ instance = new CModuleIndexDialog();
+ }
+ qDebug("CModuleIndexDialog::getInstance end");
+ return instance;
+}
+
+void CModuleIndexDialog::indexAllModules( const QList<CSwordModuleInfo*>& modules )
+{
+ static bool indexing = false;
+ if (!indexing) {
+ indexing = true;
+ if (modules.count() < 1) return;
+
+ m_currentModuleIndex = 0;
+ m_progress = new QProgressDialog(QString(""), tr("Cancel"), 0, modules.count()*100);
+ m_progress->setWindowModality(Qt::WindowModal); // not useful actually, should have parent for this
+ m_progress->setWindowTitle(tr("Creating indices"));
+ m_progress->show();
+ m_progress->raise();
+
+ foreach (CSwordModuleInfo* info, modules) {
+ //TODO: how to cancel
+ //QObject::connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged()), this, SLOT(swordSetupChanged()));
+ connect(this, SIGNAL(sigCancel()), info, SLOT(cancelIndexing()) );
+ connect(m_progress, SIGNAL(canceled()), info, SLOT(cancelIndexing()));
+ connect(info, SIGNAL(indexingFinished()), this, SLOT(slotFinished()));
+ connect(info, SIGNAL(indexingProgress(int)), this, SLOT(slotModuleProgress(int)) );
+ QString modname(info->name());
+ const QString labelText = tr("Creating index for work: %1").arg(modname);
+ m_progress->setLabelText(labelText);
+ //todo: if we want to cancel indexing from
+ info->buildIndex(); //waits until this module is finished
+
+ m_currentModuleIndex++;
+ disconnect(m_progress, SIGNAL(canceled()), info, SLOT(cancelIndexing()));
+ disconnect(info, SIGNAL(indexingFinished()), this, SLOT(slotFinished()));
+ disconnect(info, SIGNAL(indexingProgress(int)), this, SLOT(slotModuleProgress(int)) );
+ if (m_progress->wasCanceled()) break;
+ }
+
+ delete m_progress;
+ m_progress = 0;
+ indexing = false;
+ }
+}
+
+void CModuleIndexDialog::indexUnindexedModules( const QList<CSwordModuleInfo*>& modules ) {
+ QList<CSwordModuleInfo*> unindexedMods;
+
+ QList<CSwordModuleInfo*>::const_iterator end_it = modules.end();
+ for( QList<CSwordModuleInfo*>::const_iterator it = modules.begin(); it != end_it; ++it) {
+ if ((*it)->hasIndex()) {
+ continue;
+ }
+
+ unindexedMods << (*it);
+ }
+ indexAllModules(unindexedMods);
+}
+
+void CModuleIndexDialog::slotModuleProgress( int percentage ) {
+ m_progress->setValue(m_currentModuleIndex * 100 + percentage);
+ qApp->processEvents();
+}
+
+void CModuleIndexDialog::slotFinished( ) {
+ m_progress->setValue(m_currentModuleIndex * 100 + 100);
+ qApp->processEvents();
+}
+
+// Modules may be removed
+void CModuleIndexDialog::slotSwordSetupChanged()
+{
+ qDebug("CModuleIndexDialog::slotSwordSetupChanged, TODO: cancel if modules are removed");
+ QMessageBox::information(0, tr("Indexing Is Cancelled"), tr("Indexing is cancelled because modules are removed."));
+ emit sigCancel();
+}
diff --git a/src/frontend/cmoduleindexdialog.h b/src/frontend/cmoduleindexdialog.h
new file mode 100644
index 0000000..63c14b5
--- /dev/null
+++ b/src/frontend/cmoduleindexdialog.h
@@ -0,0 +1,61 @@
+//
+// C++ Interface: cmoduleindexdialog
+//
+// Description:
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 2006-2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef CMODULEINDEXDIALOG_H
+#define CMODULEINDEXDIALOG_H
+
+class CSwordModuleInfo;
+
+//Qt includes
+#include <QObject>
+
+//forward declaration
+//class KProgressDialog;
+class QProgressDialog;
+
+/**
+ * This dialog is used to index a list of modules and to show progress for that.\
+ * While the indexing is in progress it creates a blocking, top level dialog which shows the progress
+ * while the indexing is done.
+ *
+ * @author The BibleTime team <info@bibletime.info>
+*/
+class CModuleIndexDialog : public QObject {
+ Q_OBJECT
+public:
+ /** Get the singleton instance.
+ *
+ */
+ static CModuleIndexDialog* getInstance();
+
+ /** Starts the actual indexing. It shows the dialog with progress information.
+ */
+ void indexAllModules( const QList<CSwordModuleInfo*>& modules );
+
+ /** Indexes all modules in the list which don't have an index yet.
+ */
+ void indexUnindexedModules( const QList<CSwordModuleInfo*>& modules );
+
+signals:
+ /** Indexing is cancelled programmatically. */
+ void sigCancel();
+
+private:
+ QProgressDialog* m_progress;
+ int m_currentModuleIndex;
+
+protected slots:
+ void slotModuleProgress( int percentage );
+ void slotFinished();
+ void slotSwordSetupChanged();
+};
+
+#endif
diff --git a/src/frontend/cprinter.cpp b/src/frontend/cprinter.cpp
new file mode 100644
index 0000000..92699af
--- /dev/null
+++ b/src/frontend/cprinter.cpp
@@ -0,0 +1,136 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cprinter.h"
+
+#include "backend/managers/cdisplaytemplatemgr.h"
+#include "backend/keys/cswordversekey.h"
+#include "util/cpointers.h"
+
+#include <QWebPage>
+#include <QWebFrame>
+#include <QPrinter>
+#include <QPrintDialog>
+
+namespace Printing
+{
+
+CPrinter::CPrinter(QObject*, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions)
+ : QObject(0),
+ CDisplayRendering(displayOptions, filterOptions),
+ m_htmlPage(new QWebPage())
+{
+ m_htmlPage->setParent(this);
+
+ //override the filteroptions set in the c-tor of CDisplayRendering
+ m_filterOptions.footnotes = false;
+ m_filterOptions.scriptureReferences = false;
+ m_filterOptions.strongNumbers = false;
+ m_filterOptions.morphTags = false;
+ m_filterOptions.headings = false;
+}
+
+CPrinter::~CPrinter()
+{
+ delete m_htmlPage;
+ m_htmlPage = 0;
+}
+
+void CPrinter::printKeyTree( KeyTree& tree )
+{
+ m_htmlPage->mainFrame()->setHtml(renderKeyTree(tree));
+
+ QPrinter printer;
+ QPrintDialog printDialog(&printer);
+ if (printDialog.exec() == QDialog::Accepted)
+ {
+ m_htmlPage->mainFrame()->print(&printer);
+ }
+}
+
+const QString CPrinter::entryLink(const KeyTreeItem& item, CSwordModuleInfo* module)
+{
+ Q_ASSERT(module);
+ if (module->type() == CSwordModuleInfo::Bible)
+ {
+ CSwordVerseKey vk(module);
+ vk.key(item.key());
+ switch (item.settings().keyRenderingFace)
+ {
+ case KeyTreeItem::Settings::CompleteShort:
+ return QString::fromUtf8(vk.getShortText());
+
+ case KeyTreeItem::Settings::CompleteLong:
+ return vk.key();
+
+ case KeyTreeItem::Settings::NoKey:
+ return QString::null;
+
+ case KeyTreeItem::Settings::SimpleKey: //fall through
+ default:
+ return QString::number(vk.Verse());
+ }
+ }
+ return item.key();
+}
+
+const QString CPrinter::renderEntry( const KeyTreeItem& i, CSwordKey* )
+{
+ const CPrinter::KeyTreeItem* printItem = dynamic_cast<const CPrinter::KeyTreeItem*>(&i);
+ Q_ASSERT(printItem);
+
+ if (printItem && printItem->hasAlternativeContent())
+ {
+ QString ret = QString::fromLatin1("<div class=\"entry\"><div class=\"rangeheading\">%1</div>").arg(printItem->getAlternativeContent());
+
+ if (!i.childList()->isEmpty())
+ {
+ KeyTree const * tree = i.childList();
+
+ foreach ( KeyTreeItem* c, (*tree))
+ {
+ ret.append( CDisplayRendering::renderEntry( *c ) );
+ }
+ }
+
+ ret.append("</div>");
+ return ret;
+ }
+ return CDisplayRendering::renderEntry(i);
+}
+
+const QString CPrinter::finishText(const QString& text, KeyTree& tree)
+{
+ QList<CSwordModuleInfo*> modules = collectModules(&tree);
+ Q_ASSERT(modules.count() > 0);
+
+ const CLanguageMgr::Language* const lang = modules.first()->language();
+ Q_ASSERT(lang);
+
+ CDisplayTemplateMgr::Settings settings;
+ //settings.modules = modules;
+ settings.pageCSS_ID = "printer";
+ settings.langAbbrev = ( lang && (modules.count() == 1) && lang->isValid() ) ? lang->abbrev() : "unknown";
+
+ //the previous version gave compiler error for some strange reason
+ //(well, I don't like ?: anyway, let alone nested)
+ if (modules.count() != 1)
+ {
+ settings.pageDirection = QString::null;
+ }
+ else
+ {
+ settings.pageDirection = ( modules.first()->textDirection() == CSwordModuleInfo::LeftToRight ) ? "ltr" : "rtl";
+ }
+
+ CDisplayTemplateMgr* tMgr = CPointers::displayTemplateManager();
+ return tMgr->fillTemplate(CBTConfig::get(CBTConfig::displayStyle), text, settings);
+}
+
+} //end of namespace
diff --git a/src/frontend/cprinter.h b/src/frontend/cprinter.h
new file mode 100644
index 0000000..8b85691
--- /dev/null
+++ b/src/frontend/cprinter.h
@@ -0,0 +1,45 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CPRINTER_H
+#define CPRINTER_H
+
+#include "backend/managers/cswordbackend.h"
+#include "backend/rendering/cdisplayrendering.h"
+#include "backend/config/cbtconfig.h"
+
+#include <QObject>
+
+class QWebPage;
+
+namespace Printing
+{
+
+ // The CPrinter class manages the print item queue and the printing of them to the printer.
+
+class CPrinter : public QObject, public Rendering::CDisplayRendering
+{
+ Q_OBJECT
+public:
+ CPrinter(QObject* parent, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions);
+ virtual ~CPrinter();
+ void printKeyTree( KeyTree& );
+
+protected:
+ virtual const QString entryLink(const KeyTreeItem& item, CSwordModuleInfo* const module);
+ virtual const QString renderEntry( const KeyTreeItem&, CSwordKey* = 0 );
+ virtual const QString finishText(const QString& arg1, KeyTree& tree);
+
+private:
+ QWebPage* m_htmlPage;
+};
+
+} //namespace Printing
+
+#endif
diff --git a/src/frontend/crossrefrendering.cpp b/src/frontend/crossrefrendering.cpp
new file mode 100644
index 0000000..3aa8130
--- /dev/null
+++ b/src/frontend/crossrefrendering.cpp
@@ -0,0 +1,90 @@
+//
+// C++ Implementation: crossrefrendering
+//
+// Description:
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 2004, 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+
+
+#include "crossrefrendering.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/keys/cswordversekey.h"
+#include "backend/managers/creferencemanager.h"
+
+namespace InfoDisplay {
+
+/**
+ */
+CrossRefRendering::CrossRefRendering( CSwordBackend::DisplayOptions displayOptions,
+ CSwordBackend::FilterOptions filterOptions
+ )
+ : CHTMLExportRendering(Settings(), displayOptions, filterOptions)
+{}
+
+const QString CrossRefRendering::finishText( const QString& text, KeyTree& ) {
+ // qDebug("CrossRefRendering::finishText");
+ return text;
+}
+
+const QString CrossRefRendering::entryLink( const KeyTreeItem& item, CSwordModuleInfo* module ) {
+ QString linkText;
+
+ const bool isBible = module && (module->type() == CSwordModuleInfo::Bible);
+ CSwordVerseKey vk(module); //only valid for bible modules, i.e. isBible == true
+ if (isBible) {
+ vk.key(item.key());
+ }
+
+ switch (item.settings().keyRenderingFace) {
+ case KeyTreeItem::Settings::NoKey: {
+ linkText = QString::null;
+ break; //no key is valid for all modules
+ }
+ case KeyTreeItem::Settings::CompleteShort: {
+ if (isBible) {
+ linkText = QString::fromUtf8(vk.getShortText());
+ break;
+ }
+ //fall through for non-Bible modules
+ }
+ case KeyTreeItem::Settings::CompleteLong: {
+ if (isBible) {
+ linkText = vk.key();
+ break;
+ }
+ //fall through for non-Bible modules
+ }
+ case KeyTreeItem::Settings::SimpleKey: {
+ if (isBible) {
+ linkText = QString::number(vk.Verse());
+ break;
+ }
+ //fall through for non-Bible modules
+ }
+ default: { //default behaviour to return the passed key
+ linkText = item.key();
+ break;
+ }
+ }
+
+ if (!linkText.isEmpty()) { //if we have a valid link text
+ // qWarning("rendering");
+ return QString("<a href=\"%1\">%2</a>")
+ .arg(
+ CReferenceManager::encodeHyperlink(
+ module->name(),
+ item.key(),
+ CReferenceManager::typeFromModule(module->type())
+ )
+ )
+ .arg(linkText);
+ }
+
+ return QString::null;
+}
+
+}
diff --git a/src/frontend/crossrefrendering.h b/src/frontend/crossrefrendering.h
new file mode 100644
index 0000000..99fdd7c
--- /dev/null
+++ b/src/frontend/crossrefrendering.h
@@ -0,0 +1,37 @@
+//
+// C++ Interface: crossrefrendering
+//
+// Description:
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 2004, 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+
+
+#ifndef INFODISPLAYCROSSREFRENDERING_H
+#define INFODISPLAYCROSSREFRENDERING_H
+
+//Backend includes
+#include "backend/rendering/chtmlexportrendering.h"
+
+namespace InfoDisplay {
+
+class CrossRefRendering : public Rendering::CHTMLExportRendering
+{
+protected:
+ friend class CInfoDisplay;
+
+ CrossRefRendering(
+ CSwordBackend::DisplayOptions displayOptions = CBTConfig::getDisplayOptionDefaults(),
+ CSwordBackend::FilterOptions filterOptions = CBTConfig::getFilterOptionDefaults()
+ );
+
+ virtual const QString entryLink( const KeyTreeItem& item, CSwordModuleInfo* module );
+ virtual const QString finishText( const QString&, KeyTree& tree );
+};
+
+
+}
+
+#endif
diff --git a/src/frontend/display/btcolorwidget.cpp b/src/frontend/display/btcolorwidget.cpp
new file mode 100644
index 0000000..f807b05
--- /dev/null
+++ b/src/frontend/display/btcolorwidget.cpp
@@ -0,0 +1,65 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btcolorwidget.h"
+#include <QPalette>
+#include <QColor>
+#include <QMouseEvent>
+#include <QColorDialog>
+
+BtColorWidget::BtColorWidget(QWidget* parent)
+ : QFrame(parent)
+{
+ setFrameShadow(QFrame::Sunken);
+ setFrameShape(QFrame::StyledPanel);
+ setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ setAutoFillBackground(true);
+}
+
+BtColorWidget::~BtColorWidget()
+{
+}
+
+QSize BtColorWidget::sizeHint() const
+{
+ return QSize(35,18);
+}
+
+void BtColorWidget::setColor(const QColor& color)
+{
+ QPalette p = palette();
+ p.setColor(QPalette::Normal, QPalette::Window, color);
+ setPalette(p);
+
+ if (color.isValid())
+ m_color = color;
+ else
+ m_color = QColor(0,0,0);
+ update();
+}
+
+void BtColorWidget::mouseReleaseEvent(QMouseEvent* event)
+{
+ if (event->button() == Qt::LeftButton)
+ {
+ event->accept();
+ showColorDialog();
+ return;
+ }
+}
+
+void BtColorWidget::showColorDialog()
+{
+ QColor color = QColorDialog::getColor(m_color, this);
+ if (color.isValid())
+ {
+ m_color = color;
+ emit changed(m_color);
+ }
+}
diff --git a/src/frontend/display/btcolorwidget.h b/src/frontend/display/btcolorwidget.h
new file mode 100644
index 0000000..0309832
--- /dev/null
+++ b/src/frontend/display/btcolorwidget.h
@@ -0,0 +1,44 @@
+//
+// C++ Interface: BtColorWidget
+//
+// Description: A color choosing widget for the toolbar
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 1999-2008
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef BTCOLORWIDGET_H
+#define BTCOLORWIDGET_H
+
+#include <QFrame>
+class QPaintEvent;
+
+class BtColorWidget : public QFrame
+{
+ Q_OBJECT
+
+public:
+ BtColorWidget(QWidget* parent=0);
+ ~BtColorWidget();
+ QSize sizeHint() const;
+ void setColor(const QColor& color);
+
+protected:
+// void paintEvent( QPaintEvent* );
+ void mouseReleaseEvent(QMouseEvent* event);
+
+private:
+ void showColorDialog();
+
+ QColor m_color;
+
+signals:
+ void changed(const QColor& color);
+};
+
+#endif
+
+
diff --git a/src/frontend/display/btfontsizewidget.cpp b/src/frontend/display/btfontsizewidget.cpp
new file mode 100644
index 0000000..3f03693
--- /dev/null
+++ b/src/frontend/display/btfontsizewidget.cpp
@@ -0,0 +1,51 @@
+/*********
+*
+* This file is part of BtFontSizeWidget's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BtFontSizeWidget developers.
+* The BtFontSizeWidget source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btfontsizewidget.h"
+#include <QFontDatabase>
+#include <QCompleter>
+
+BtFontSizeWidget::BtFontSizeWidget(QWidget* parent)
+ : QComboBox(parent)
+{
+ setEditable(true);
+ completer()->setCompletionMode(QCompleter::PopupCompletion);
+
+ QFontDatabase database;
+ const QList<int> sizes = database.standardSizes();
+ QStringList list;
+ for ( QList<int>::ConstIterator it = sizes.begin(); it != sizes.end(); ++it )
+ list.append( QString::number( *it ) );
+ addItems(list);
+
+ bool ok = connect(this, SIGNAL(currentIndexChanged(const QString&)),
+ this, SLOT(changed(const QString&)));
+ Q_ASSERT(ok);
+}
+
+BtFontSizeWidget::~BtFontSizeWidget()
+{
+}
+
+void BtFontSizeWidget::changed(const QString& text)
+{
+ emit fontSizeChanged(text.toInt());
+}
+
+void BtFontSizeWidget::setFontSize(int size)
+{
+ int index = findText(QString::number(size));
+ if (index >= 0)
+ setCurrentIndex(index);
+}
+
+int BtFontSizeWidget::fontSize() const
+{
+ return currentText().toInt();
+}
diff --git a/src/frontend/display/btfontsizewidget.h b/src/frontend/display/btfontsizewidget.h
new file mode 100644
index 0000000..2366744
--- /dev/null
+++ b/src/frontend/display/btfontsizewidget.h
@@ -0,0 +1,36 @@
+//
+// C++ Interface: BtFontSizeWidget
+//
+// Description: A font combobox widget for the toolbar
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 1999-2008
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef BTFONTSIZEWIDGET_H
+#define BTFONTSIZEWIDGET_H
+
+#include <QComboBox>
+
+
+class BtFontSizeWidget : public QComboBox
+{
+ Q_OBJECT
+
+public:
+ BtFontSizeWidget(QWidget* parent=0);
+ ~BtFontSizeWidget();
+ void setFontSize(int size);
+ int fontSize() const;
+
+private slots:
+ virtual void changed(const QString& text);
+
+signals:
+ void fontSizeChanged( int );
+};
+
+#endif
diff --git a/src/frontend/display/bthtml.js b/src/frontend/display/bthtml.js
new file mode 100644
index 0000000..d64215d
--- /dev/null
+++ b/src/frontend/display/bthtml.js
@@ -0,0 +1,146 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+var X = 0;
+var Y = 0;
+var attribs = [];
+var eventType = "";
+var prevNode = 0;
+var currentNode = 0;
+var timeOutId = -1;
+
+// Scroll window to html anchor
+function gotoAnchor(anchor)
+{
+ document.location=document.location + "#" + anchor;
+}
+
+// Set body editable
+function setEditable()
+{
+ var theBody = document.getElementsByTagName('body')[0];
+ theBody.setAttribute('contenteditable','true');
+}
+
+// Set body not editable
+function setNotEditable()
+{
+ var theBody = document.getElementsByTagName('body')[0];
+ theBody.setAttribute('contenteditable','false');
+}
+
+// Mouse button clicked handler
+function mouseClickHandler (mEvent)
+{
+ var mTarget = mEvent.target;
+ if (mTarget)
+ {
+ var url = "";
+ var tmpUrl = mEvent.target.getAttribute("href");
+ if (tmpUrl)
+ url = tmpUrl;
+ btHtmlJsObject.mouseClick(url);
+ }
+}
+
+// Mouse button pressed down handler
+function mouseDownHandler (mEvent)
+{
+ var node;
+ var url = "";
+ var lemma = "";
+ var mTarget = mEvent.target;
+ if (mTarget)
+ {
+ var tmpUrl = mEvent.target.getAttribute("href");
+ if (tmpUrl)
+ url = tmpUrl;
+ var tmpLemma = mEvent.target.getAttribute("lemma");
+ if (tmpLemma)
+ lemma = tmpLemma;
+ }
+
+ if (mEvent.button === 2) // Right mouse button
+ {
+ btHtmlJsObject.mouseDownRight(url, lemma);
+ }
+ if (mEvent.button === 0) // Left mouse button
+ {
+ if (!(mEvent.target === undefined))
+ {
+ var X = mEvent.clientX;
+ var Y = mEvent.clientY;
+ btHtmlJsObject.mouseDownLeft(url, X, Y);
+ }
+ }
+}
+
+// Mouse moved event handler
+function mouseMoveHandler (mEvent)
+{
+ currentNode = mEvent.target;
+ var shiftKey = mEvent.shiftKey;
+ var x = mEvent.clientX;
+ var y = mEvent.clientY;
+ var node = mEvent.target;
+ if ( node != undefined && node != prevNode )
+ {
+ prevNode = node;
+
+ if (node.attributes.length > 0)
+ {
+ attribList = getNodeAttributes(node);
+ btHtmlJsObject.mouseMoveEvent(attribList, x, y, shiftKey);
+ }
+ }
+}
+
+// Get attributes of a DOM node and put into a single string
+function getNodeAttributes(node)
+{
+ var attribList = '';
+ if (node.attributes.length > 0)
+ {
+ for (i = 0; i < node.attributes.length; i++)
+ {
+ attribList = attribList + node.attributes[i].nodeName + '=' + node.attributes[i].nodeValue + '||';
+ }
+ }
+ return attribList;
+}
+
+// Start a timer event
+function startTimer(time)
+{
+ clearTimeout(timeOutId);
+ timeOutId = setTimeout("timerEvent()",time);
+}
+
+// Handles a timer event
+function timerEvent()
+{
+ timeOutId = -1;
+ if (currentNode != 0 && currentNode == prevNode)
+ {
+ var attributes = getNodeAttributes(currentNode);
+ btHtmlJsObject.timeOutEvent(attributes);
+ }
+}
+
+document.getElementsByTagName("body")[0].addEventListener ('mousedown', function (eve) { mouseDownHandler (eve); }, true);
+document.getElementsByTagName("body")[0].addEventListener ('mousemove', function (eve) { mouseMoveHandler (eve); }, true);
+document.getElementsByTagName("body")[0].addEventListener ('click', function (eve) { mouseClickHandler (eve); }, true);
+
+btHtmlJsObject.startTimer.connect(this, this.startTimer);
+btHtmlJsObject.gotoAnchor.connect(this, this.gotoAnchor);
+btHtmlJsObject.setDocumentEditable.connect(this, this.setEditable);
+btHtmlJsObject.setDocumentNotEditable.connect(this, this.setNotEditable);
+
+;
+
diff --git a/src/frontend/display/bthtmlfindtext.cpp b/src/frontend/display/bthtmlfindtext.cpp
new file mode 100644
index 0000000..9041173
--- /dev/null
+++ b/src/frontend/display/bthtmlfindtext.cpp
@@ -0,0 +1,106 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "bthtmlfindtext.h"
+#include "bthtmlreaddisplay.h"
+#include "creaddisplay.h"
+#include "frontend/cmdiarea.h"
+#include "frontend/displaywindow/cdisplaywindow.h"
+#include <QMdiSubWindow>
+
+static BtHtmlFindText* dialog = 0;
+
+void showBtHtmlFindText(CMDIArea* mdiArea)
+{
+ if (dialog == 0)
+ dialog = new BtHtmlFindText(mdiArea, mdiArea);
+ dialog->show();
+}
+
+BtHtmlFindText::BtHtmlFindText(CMDIArea* mdiArea, QWidget *parent, Qt::WindowFlags f)
+ : QDialog(parent,f), m_mdiArea(mdiArea)
+{
+ ui.setupUi(this);
+ bool ok;
+ ok = connect(ui.nextButton,SIGNAL(clicked()), this, SLOT(findNext()));
+ Q_ASSERT(ok);
+ ok = connect(ui.previousButton,SIGNAL(clicked()), this, SLOT(findPrevious()));
+ Q_ASSERT(ok);
+}
+
+BtHtmlFindText::~BtHtmlFindText()
+{
+}
+
+void BtHtmlFindText::findNext()
+{
+ QWebView* webView = getActiveWindowWebView();
+ if (webView != 0)
+ {
+ QWebPage::FindFlags options = 0;
+ if (ui.caseBox->checkState() == Qt::Checked)
+ options |= QWebPage::FindCaseSensitively;
+ QString searchText = ui.findTextComboBox->currentText();
+ if (!searchText.isEmpty())
+ webView->findText(searchText, options);
+ }
+}
+
+void BtHtmlFindText::doHide()
+{
+ hide();
+}
+
+void BtHtmlFindText::findPrevious()
+{
+ QWebView* webView = getActiveWindowWebView();
+ if (webView != 0)
+ {
+ QWebPage::FindFlags options = QWebPage::FindBackward;
+ if (ui.caseBox->checkState() == Qt::Checked)
+ options |= QWebPage::FindCaseSensitively;
+ QString searchText = ui.findTextComboBox->currentText();
+ if (!searchText.isEmpty())
+ webView->findText(searchText,options);
+ }
+}
+
+
+QWebView* BtHtmlFindText::getActiveWindowWebView()
+{
+ QMdiSubWindow* activeSubWindow = m_mdiArea->activeSubWindow();
+ if (activeSubWindow == 0)
+ return 0;
+
+ QWidget* activeWindowWidget = activeSubWindow->widget();
+ if (activeWindowWidget == 0)
+ return 0;
+
+ CDisplayWindow* cDisplayWindow = qobject_cast<CDisplayWindow*>(activeWindowWidget);
+ if (cDisplayWindow == 0)
+ return 0;
+
+ CDisplay* cDisplay = cDisplayWindow->displayWidget();
+ if (cDisplay == 0)
+ return 0;
+
+ QWidget* textView = cDisplay->view();
+ if (textView == 0)
+ return 0;
+
+ QWebView* webView = qobject_cast<QWebView*>(textView);
+ return webView;
+}
+
+
+
+
+
+
+
diff --git a/src/frontend/display/bthtmlfindtext.h b/src/frontend/display/bthtmlfindtext.h
new file mode 100644
index 0000000..d6a1fe9
--- /dev/null
+++ b/src/frontend/display/bthtmlfindtext.h
@@ -0,0 +1,35 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTHTMLFINDTEXT_H
+#define BTHTMLFINDTEXT_H
+
+#include "ui_bthtmlfindtext.h"
+class CMDIArea;
+class QWebView;
+
+class BtHtmlFindText : public QDialog
+{
+ Q_OBJECT
+
+public:
+ BtHtmlFindText(CMDIArea* mdiArea, QWidget *parent=0, Qt::WindowFlags f=0);
+ ~BtHtmlFindText();
+public slots:
+ void findNext();
+ void findPrevious();
+ void doHide();
+private:
+ QWebView* getActiveWindowWebView();
+ Ui_findTextDialog ui;
+ CMDIArea* m_mdiArea;
+};
+
+
+#endif
diff --git a/src/frontend/display/bthtmlfindtext.ui b/src/frontend/display/bthtmlfindtext.ui
new file mode 100644
index 0000000..97c373e
--- /dev/null
+++ b/src/frontend/display/bthtmlfindtext.ui
@@ -0,0 +1,145 @@
+<ui version="4.0" >
+ <class>findTextDialog</class>
+ <widget class="QDialog" name="findTextDialog" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>227</width>
+ <height>115</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Find Text</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout" >
+ <item>
+ <widget class="QFrame" name="findFrame" >
+ <property name="frameShape" >
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow" >
+ <enum>QFrame::Raised</enum>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2" >
+ <item>
+ <spacer name="verticalSpacer" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QComboBox" name="findTextComboBox" >
+ <property name="toolTip" >
+ <string>The text you want to search for</string>
+ </property>
+ <property name="editable" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="caseBox" >
+ <property name="toolTip" >
+ <string>Seach with case sensitivity</string>
+ </property>
+ <property name="text" >
+ <string>Case &amp;sensitive</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_2" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_6" >
+ <item>
+ <spacer name="horizontalSpacer_6" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="previousButton" >
+ <property name="toolTip" >
+ <string>Find the previous location of the text</string>
+ </property>
+ <property name="text" >
+ <string>&amp;Previous</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="nextButton" >
+ <property name="toolTip" >
+ <string>Find the next location of the text</string>
+ </property>
+ <property name="text" >
+ <string>&amp;Next</string>
+ </property>
+ <property name="default" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="closeButton" >
+ <property name="toolTip" >
+ <string>Close the dialog</string>
+ </property>
+ <property name="text" >
+ <string>&amp;Close</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>closeButton</sender>
+ <signal>clicked()</signal>
+ <receiver>findTextDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>200</x>
+ <y>124</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>224</x>
+ <y>106</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/src/frontend/display/bthtmljsobject.cpp b/src/frontend/display/bthtmljsobject.cpp
new file mode 100644
index 0000000..836a6a3
--- /dev/null
+++ b/src/frontend/display/bthtmljsobject.cpp
@@ -0,0 +1,175 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+#include "bthtmljsobject.h"
+#include "bthtmlreaddisplay.h"
+#include "frontend/cinfodisplay.h"
+#include "frontend/cdragdrop.h"
+#include "backend/managers/creferencemanager.h"
+#include "backend/managers/cswordbackend.h"
+#include "backend/keys/cswordkey.h"
+#include "backend/config/cbtconfig.h"
+#include <boost/scoped_ptr.hpp>
+#include <QObject>
+
+using namespace InfoDisplay;
+
+// This class works along with the BtHtmlReadDisplay class. The BtHtmlReadDisplay class loads
+// Javascript (bthtml.js) along with the html it displays. This class is added to the Javascript model
+// so that Javascript can call this class, or this class can call Javascript.
+// Access to DOM objects is implemented in Javascript and is communicated back to c++ through this class
+
+BtHtmlJsObject::BtHtmlJsObject(BtHtmlReadDisplay* display)
+ : m_display(display)
+{
+}
+
+void BtHtmlJsObject::moveToAnchor(const QString& anchor)
+{
+ // Call gotoAnchor in Javascript
+ emit gotoAnchor(anchor);
+}
+
+void BtHtmlJsObject::setBodyEditable(bool editable)
+{
+ if (editable)
+ emit setDocumentEditable();
+ else
+ emit setDocumentNotEditable();
+}
+
+void BtHtmlJsObject::mouseDownLeft(const QString& url, const int& x, const int& y)
+{
+ m_dndData.mousePressed = true;
+ m_dndData.isDragging = false;
+ m_dndData.startPos = QPoint(x,y);
+ m_dndData.url = url;
+}
+
+void BtHtmlJsObject::mouseClick(const QString& url)
+{
+ m_dndData.mousePressed = false;
+ if (!url.isEmpty() && CReferenceManager::isHyperlink(url))
+ {
+ QString module;
+ QString key;
+ CReferenceManager::Type type;
+
+ CReferenceManager::decodeHyperlink(url, module, key, type);
+ if (module.isEmpty())
+ {
+ module = CReferenceManager::preferredModule( type );
+ }
+ m_display->connectionsProxy()->emitReferenceClicked(module,key);
+ }
+}
+
+void BtHtmlJsObject::mouseDownRight(const QString& url, const QString& lemma)
+{
+ m_display->setActiveAnchor(url);
+ if (lemma.isEmpty())
+ m_display->setLemma(QString::null);
+ else
+ m_display->setLemma(lemma);
+}
+
+void BtHtmlJsObject::mouseMoveEvent(const QString& /*attributes*/, const int& x, const int& y, const bool& shiftKey)
+{
+ if(!m_dndData.isDragging && m_dndData.mousePressed)
+ {
+ QPoint current(x,y);
+ if ((current - m_dndData.startPos).manhattanLength() > 4 /*qApp->startDragDistance()*/ )
+ {
+ QDrag* d = 0;
+ if (m_dndData.url.size() != 0 )
+ {
+ // create a new bookmark drag!
+ QString moduleName = QString::null;
+ QString keyName = QString::null;
+ CReferenceManager::Type type;
+ if ( !CReferenceManager::decodeHyperlink(m_dndData.url, moduleName, keyName, type) )
+ return;
+ d = new QDrag(m_display->view());
+ BTMimeData* mimedata = new BTMimeData(moduleName, keyName, QString::null);
+ d->setMimeData(mimedata);
+ //add real Bible text from module/key
+ if (CSwordModuleInfo* module = CPointers::backend()->findModuleByName(moduleName))
+ {
+ boost::scoped_ptr<CSwordKey> key( CSwordKey::createInstance(module) );
+ key->key( keyName );
+ mimedata->setText(key->strippedText()); // This works across applications!
+ }
+ }
+#if 0
+ else if ((m_dndData.dragType == DNDData::Text) && !m_dndData.selection.isEmpty()) {
+ d = new QDrag(KHTMLPart::view()->viewport());
+ BTMimeData* mimedata = new BTMimeData(m_dndData.selection);
+ d->setMimeData(mimedata);
+ }
+#endif
+ if (d) {
+ m_dndData.isDragging = true;
+ m_dndData.mousePressed = false;
+
+ //first make a virtual mouse click to end the selection, if it's in progress
+// QMouseEvent e(QEvent::MouseButtonRelease, QPoint(0,0), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
+// QApplication::sendEvent(view()->viewport(), &e);
+ d->exec(Qt::CopyAction, Qt::CopyAction);
+
+ }
+ }
+ }
+ else if (m_display->getMouseTracking() && !shiftKey)
+ {
+ //no mouse button pressed and tracking enabled
+ // After some millisecs the new timer activates the Mag window update, see timerEvent()
+ // QObject has simple timer
+ emit startTimer(CBTConfig::get(CBTConfig::magDelay));
+ }
+}
+
+void BtHtmlJsObject::timeOutEvent(const QString& attributes)
+{
+ CInfoDisplay::ListInfoData infoList;
+ QStringList attrList = attributes.split("||");
+ for (int i=0; i<attrList.count(); i++)
+ {
+ QString attrPair = attrList[i];
+ QStringList attr = attrPair.split("=");
+ if (attr.count() == 2)
+ {
+ QString attrName = attr[0];
+ QString attrValue= attr[1];
+ if (attrName == "note")
+ {
+ infoList.append( qMakePair(CInfoDisplay::Footnote, attrValue));
+ }
+ if (attrName == "lemma")
+ {
+ infoList.append( qMakePair(CInfoDisplay::Lemma, attrValue));
+ }
+ if (attrName == "morph")
+ {
+ infoList.append( qMakePair(CInfoDisplay::Morph, attrValue));
+ }
+ if (attrName == "expansion")
+ {
+ infoList.append( qMakePair(CInfoDisplay::Abbreviation, attrValue));
+ }
+ if (attrName == "crossrefs")
+ {
+ infoList.append( qMakePair(CInfoDisplay::CrossReference, attrValue));
+ }
+ }
+ }
+ // Update the mag if there is new content
+ if (!(infoList.isEmpty()))
+ {
+ CPointers::infoDisplay()->setInfo(infoList);
+ }
+}
diff --git a/src/frontend/display/bthtmljsobject.h b/src/frontend/display/bthtmljsobject.h
new file mode 100644
index 0000000..a124c1c
--- /dev/null
+++ b/src/frontend/display/bthtmljsobject.h
@@ -0,0 +1,60 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+#ifndef BTHTMLJSOBJECT_H
+#define BTHTMLJSOBJECT_H
+
+#include <QObject>
+#include <QPoint>
+
+class BtHtmlReadDisplay;
+
+class BtHtmlJsObject: public QObject
+{
+ Q_OBJECT
+
+public:
+ BtHtmlJsObject(BtHtmlReadDisplay* display);
+ ~BtHtmlJsObject(){}
+ void moveToAnchor(const QString& anchor);
+ void setBodyEditable(bool editable);
+
+public slots: void mouseMoveEvent(const QString& attributes, const int& x, const int& y, const bool& shiftKey);
+ void mouseClick(const QString& url);
+ void mouseDownLeft(const QString& url, const int& X, const int& Y);
+ void mouseDownRight(const QString& url, const QString& lemma);
+ void timeOutEvent(const QString& attributes);
+
+signals:
+ void startTimer(int time);
+ void mouseMoveAttribute(const QString& attrName, const QString& attrValue);
+ void gotoAnchor(const QString& anchor);
+ void selectAll();
+ void setDocumentEditable();
+ void setDocumentNotEditable();
+
+private:
+ int m_int;
+ BtHtmlReadDisplay* m_display;
+
+ struct DNDData
+ {
+ bool mousePressed;
+ bool isDragging;
+ QPoint startPos;
+ QString url;
+ enum DragType
+ {
+ Link,
+ Text
+ } dragType;
+ } m_dndData;
+
+};
+
+#endif
diff --git a/src/frontend/display/bthtmlreaddisplay.cpp b/src/frontend/display/bthtmlreaddisplay.cpp
new file mode 100644
index 0000000..7f016cd
--- /dev/null
+++ b/src/frontend/display/bthtmlreaddisplay.cpp
@@ -0,0 +1,364 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "bthtmlreaddisplay.h"
+#include "bthtmljsobject.h"
+#include "frontend/displaywindow/cdisplaywindow.h"
+#include "frontend/displaywindow/creadwindow.h"
+#include "frontend/cdragdrop.h"
+#include "frontend/cinfodisplay.h"
+#include "backend/managers/creferencemanager.h"
+#include "backend/keys/cswordkey.h"
+#include "backend/config/cbtconfig.h"
+#include "util/ctoolclass.h"
+#include "util/cpointers.h"
+#include "util/directoryutil.h"
+#include <boost/scoped_ptr.hpp>
+#include <QString>
+#include <QMenu>
+
+using namespace InfoDisplay;
+
+void showBtHtmlFindText(CMDIArea*);
+
+static const QString body = "</body>";
+static const QString jsBegin = "<script type=\"text/javascript\">";
+static const QString jsEnd = "</script>";
+static QString javascript; // Initialized from file bthtml.js
+
+
+BtHtmlReadDisplay::BtHtmlReadDisplay(CReadWindow* readWindow, QWidget* parentWidget)
+ : QWebPage(parentWidget),CReadDisplay(readWindow), m_magTimerId(0), m_view(0), m_jsObject(0)
+
+{
+ settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
+ m_view = new BtHtmlReadDisplayView(this, parentWidget ? parentWidget : readWindow);
+ m_view->setAcceptDrops(true);
+ m_view->setPage(this);
+ setParent(m_view);
+ m_view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ m_view->setHtml("");
+ initJavascript();
+ bool ok = connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished(bool)));
+ Q_ASSERT(ok);
+}
+
+BtHtmlReadDisplay::~BtHtmlReadDisplay()
+{
+ setView(0);
+}
+
+// Read javascript into memory once and create the c++ javascript object
+void BtHtmlReadDisplay::initJavascript()
+{
+ // read bthtml.js javascript file once
+ if (javascript.size() == 0)
+ {
+ QString jsFile = util::filesystem::DirectoryUtil::getJavascriptDir().canonicalPath() + "/bthtml.js";
+ QFile file(jsFile);
+ if (file.open(QFile::ReadOnly))
+ {
+ while (!file.atEnd())
+ {
+ QByteArray line = file.readLine();
+ javascript = javascript + line;
+ }
+ file.close();
+ }
+ }
+
+ // Setup BtHtmlJsObject which will be called from javascript
+ m_jsObject = new BtHtmlJsObject(this);
+ m_jsObject->setObjectName("btHtmlJsObject");
+}
+
+// When the QWebFrame is cleared, this function is called to install the
+// javascript object (BtHtmlJsObject class) into the Javascript model
+void BtHtmlReadDisplay::loadJSObject()
+{
+ mainFrame()->addToJavaScriptWindowObject(m_jsObject->objectName(), m_jsObject);
+}
+
+const QString BtHtmlReadDisplay::text( const CDisplay::TextType format, const CDisplay::TextPart part)
+{
+ switch (part)
+ {
+ case Document:
+ {
+ if (format == HTMLText)
+ {
+ return mainFrame()->toHtml();
+ }
+ else
+ {
+ CDisplayWindow* window = parentWindow();
+ CSwordKey* const key = window->key();
+ CSwordModuleInfo* module = key->module();
+ //This is never used for Bibles, so it is not implemented for
+ //them. If it should be, see CReadDisplay::print() for example
+ //code.
+ Q_ASSERT(module->type() == CSwordModuleInfo::Lexicon ||
+ module->type() == CSwordModuleInfo::Commentary ||
+ module->type() == CSwordModuleInfo::GenericBook);
+ if (module->type() == CSwordModuleInfo::Lexicon ||
+ module->type() == CSwordModuleInfo::Commentary ||
+ module->type() == CSwordModuleInfo::GenericBook){
+ //TODO: This is a BAD HACK, we have to fnd a better solution to manage the settings now
+ CSwordBackend::FilterOptions filterOptions;
+ filterOptions.footnotes = false;
+ filterOptions.strongNumbers = false;
+ filterOptions.morphTags = false;
+ filterOptions.lemmas = false;
+ filterOptions.scriptureReferences = false;
+ filterOptions.textualVariants = false;
+
+ CPointers::backend()->setFilterOptions(filterOptions);
+
+ return QString(key->strippedText()).append("\n(")
+ .append(key->key())
+ .append(", ")
+ .append(key->module()->name())
+ .append(")");
+ }
+ }
+ }
+
+ case SelectedText:
+ {
+ if (!hasSelection())
+ {
+ return QString::null;
+ }
+ else if (format == HTMLText)
+ {
+ // TODO: It does not appear this is ever called
+ }
+ else
+ { //plain text requested
+ return selectedText();
+ }
+ }
+
+ case AnchorOnly:
+ {
+ QString moduleName;
+ QString keyName;
+ CReferenceManager::Type type;
+ CReferenceManager::decodeHyperlink(activeAnchor(), moduleName, keyName, type);
+
+ return keyName;
+ }
+
+ case AnchorTextOnly:
+ {
+ QString moduleName;
+ QString keyName;
+ CReferenceManager::Type type;
+ CReferenceManager::decodeHyperlink(activeAnchor(), moduleName, keyName, type);
+
+ if (CSwordModuleInfo* module = backend()->findModuleByName(moduleName))
+ {
+ boost::scoped_ptr<CSwordKey> key( CSwordKey::createInstance(module) );
+ key->key( keyName );
+
+ return key->strippedText();
+ }
+ return QString::null;
+ }
+
+ case AnchorWithText:
+ {
+ QString moduleName;
+ QString keyName;
+ CReferenceManager::Type type;
+ CReferenceManager::decodeHyperlink(activeAnchor(), moduleName, keyName, type);
+
+ if (CSwordModuleInfo* module = backend()->findModuleByName(moduleName))
+ {
+ boost::scoped_ptr<CSwordKey> key( CSwordKey::createInstance(module) );
+ key->key( keyName );
+
+ //TODO: This is a BAD HACK, we have to fnd a better solution to manage the settings now
+ CSwordBackend::FilterOptions filterOptions;
+ filterOptions.footnotes = false;
+ filterOptions.strongNumbers = false;
+ filterOptions.morphTags = false;
+ filterOptions.lemmas = false;
+ filterOptions.scriptureReferences = false;
+ filterOptions.textualVariants = false;
+
+ CPointers::backend()->setFilterOptions(filterOptions);
+
+ return QString(key->strippedText()).append("\n(")
+ .append(key->key())
+ .append(", ")
+ .append(key->module()->name())
+ .append(")");
+ /* ("%1\n(%2, %3)")
+ .arg()
+ .arg(key->key())
+ .arg(key->module()->name());*/
+ }
+ return QString::null;
+ }
+ default:
+ return QString::null;
+ }
+ return QString();
+}
+
+// Puts html text and javascript into QWebView
+void BtHtmlReadDisplay::setText( const QString& newText )
+{
+ QString jsText = newText;
+ jsText.replace(body,jsBegin+javascript+jsEnd+body);
+
+ // Disconnect any previous connect and connect to slot that loads the javascript object
+ QWebFrame* frame = mainFrame();
+ disconnect(frame,SIGNAL(javaScriptWindowObjectCleared()),0,0);
+ bool ok = connect(frame,SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(loadJSObject()));
+ Q_ASSERT(ok);
+
+ // Send text to the html viewer
+ m_view->setHtml(jsText);
+}
+
+// See if any text is selected
+bool BtHtmlReadDisplay::hasSelection()
+{
+ if (selectedText().isEmpty())
+ return false;
+ return true;
+}
+
+// Reimplementation
+// Returns the BtHtmlReadDisplayView object
+QWidget* BtHtmlReadDisplay::view()
+{
+ return m_view;
+}
+
+// Select all text in the viewer
+void BtHtmlReadDisplay::selectAll()
+{
+ m_jsObject->setBodyEditable(true);
+ m_view->triggerPageAction( QWebPage::MoveToStartOfDocument, true );
+ m_view->triggerPageAction( QWebPage::SelectEndOfDocument, true );
+ m_jsObject->setBodyEditable(false);
+}
+
+// Scroll QWebView to the correct location as specified by the anchor
+void BtHtmlReadDisplay::moveToAnchor( const QString& anchor )
+{
+ slotGoToAnchor(anchor);
+}
+
+// Scroll the QWebView to the correct location specified by anchor
+void BtHtmlReadDisplay::slotGoToAnchor(const QString& anchor)
+{
+ m_jsObject->moveToAnchor(anchor);
+}
+
+// Save the Lemma (Strongs number) attribute
+void BtHtmlReadDisplay::setLemma(const QString& lemma)
+{
+ m_nodeInfo[ CDisplay::Lemma ] = lemma;
+}
+
+// Open the Find text dialog
+void BtHtmlReadDisplay::openFindTextDialog()
+{
+ CMDIArea* mdiArea = parentWindow()->mdi();
+ showBtHtmlFindText(mdiArea);
+}
+
+// Send "completed" signal when the text is finished loading into the viewer
+void BtHtmlReadDisplay::slotLoadFinished(bool)
+{
+ emit completed();
+}
+
+// For debugging javascript
+#if 0
+void BtHtmlReadDisplay::javaScriptConsoleMessage (const QString& message, int lineNumber, const QString& sourceID )
+{
+}
+#endif
+
+
+
+
+// ----------------- BtHtmlReadDisplayView -------------------------------------
+
+BtHtmlReadDisplayView::BtHtmlReadDisplayView(BtHtmlReadDisplay* displayWidget, QWidget* parent)
+ : QWebView(parent), m_display(displayWidget)
+{
+}
+
+BtHtmlReadDisplayView::~BtHtmlReadDisplayView()
+ {
+ setPage(0);
+ }
+
+// Create the right mouse context menus
+void BtHtmlReadDisplayView::contextMenuEvent(QContextMenuEvent* event)
+{
+ if (QMenu* popup = m_display->installedPopup())
+ {
+ popup->exec(event->globalPos());
+ }
+}
+
+// Reimplementation from QWidget
+void BtHtmlReadDisplayView::dropEvent( QDropEvent* e )
+{
+ if (e->mimeData()->hasFormat("BibleTime/Bookmark"))
+ {
+ //see docs for BTMimeData and QMimeData
+ const QMimeData* mimedata = e->mimeData();
+ if (mimedata != 0)
+ {
+ const BTMimeData* btmimedata = qobject_cast<const BTMimeData*>(mimedata);
+ if (btmimedata != 0)
+ {
+ BookmarkItem item = (qobject_cast<const BTMimeData*>(e->mimeData()))->bookmark();
+ m_display->connectionsProxy()->emitReferenceDropped(item.key());
+ e->acceptProposedAction();
+ return;
+ }
+ }
+ };
+ //don't accept the action!
+ e->ignore();
+}
+
+// Reimplementation from QWebView
+void BtHtmlReadDisplayView::dragEnterEvent( QDragEnterEvent* e )
+{
+ if (e->mimeData()->hasFormat("BibleTime/Bookmark"))
+ {
+ e->acceptProposedAction();
+ return;
+ }
+ //don't accept the action!
+ e->ignore();
+}
+
+// Reimplementation from QWebView
+void BtHtmlReadDisplayView::dragMoveEvent( QDragMoveEvent* e )
+{
+ if (e->mimeData()->hasFormat("BibleTime/Bookmark"))
+ {
+ e->acceptProposedAction();
+ return;
+ }
+ //don't accept the action!
+ e->ignore();
+}
+
diff --git a/src/frontend/display/bthtmlreaddisplay.h b/src/frontend/display/bthtmlreaddisplay.h
new file mode 100644
index 0000000..99a91cf
--- /dev/null
+++ b/src/frontend/display/bthtmlreaddisplay.h
@@ -0,0 +1,118 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef BTHTMLREADDISPLAY_H
+#define BTHTMLREADDISPLAY_H
+
+//BibleTime includes
+#include "bthtmljsobject.h"
+#include "creaddisplay.h"
+
+//Qt includes
+//Added by qt3to4:
+#include <QDragEnterEvent>
+#include <QDropEvent>
+#include <QTimerEvent>
+#include <QWebView>
+#include <QWebPage>
+#include <QWebFrame>
+#include <QPoint>
+
+class BtHtmlReadDisplayView;
+class QScrollArea;
+class QWidget;
+class QString;
+class BtHtmlReadDisplay;
+
+
+/** The implementation for the HTML read display.
+ * @author The BibleTime team
+ */
+class BtHtmlReadDisplay : public QWebPage, public CReadDisplay {
+ Q_OBJECT
+public:
+ //reimplemented functions from CDisplay
+ // Returns the right text part in the specified format.
+ virtual const QString text( const CDisplay::TextType format = CDisplay::HTMLText, const CDisplay::TextPart part = CDisplay::Document );
+
+ // Sets the new text for this display widget.
+ virtual void setText( const QString& newText );
+ virtual bool hasSelection();
+
+ // Reimplementation.
+ virtual void selectAll();
+ virtual void moveToAnchor( const QString& anchor );
+ virtual void openFindTextDialog();
+ virtual QMap<CDisplay::NodeInfoType, QString> getCurrentNodeInfo()
+ {
+ return m_nodeInfo;
+ }
+ QWidget* view();
+ void setLemma(const QString& lemma);
+
+public slots:
+ void loadJSObject();
+ void slotLoadFinished(bool);
+
+signals:
+ void completed();
+
+protected:
+ friend class CDisplay;
+ BtHtmlReadDisplay( CReadWindow* readWindow, QWidget* parent = 0 );
+ virtual ~BtHtmlReadDisplay();
+ void slotGoToAnchor(const QString& anchor);
+ struct DNDData
+ {
+ bool mousePressed;
+ bool isDragging;
+ QString selection;
+ QPoint startPos;
+ enum DragType
+ {
+ Link,
+ Text
+ } dragType;
+ }
+ m_dndData;
+
+ QMap<NodeInfoType, QString> m_nodeInfo;
+ int m_magTimerId;
+
+// For debugging javascript
+// void javaScriptConsoleMessage (const QString & message, int lineNumber, const QString & sourceID );
+
+private:
+ void initJavascript();
+ BtHtmlReadDisplayView* m_view;
+ BtHtmlJsObject* m_jsObject;
+ QString m_currentAnchorCache;
+
+};
+
+
+class BtHtmlReadDisplayView : public QWebView, public CPointers
+{
+ Q_OBJECT
+protected:
+ friend class BtHtmlReadDisplay;
+ void contextMenuEvent(QContextMenuEvent* event);
+ BtHtmlReadDisplayView(BtHtmlReadDisplay* display, QWidget* parent);
+ ~BtHtmlReadDisplayView();
+
+private:
+ BtHtmlReadDisplay* m_display;
+ void dropEvent( QDropEvent* e );
+ void dragEnterEvent( QDragEnterEvent* e );
+ void dragMoveEvent( QDragMoveEvent* e );
+};
+
+#endif
diff --git a/src/frontend/display/cdisplay.cpp b/src/frontend/display/cdisplay.cpp
new file mode 100644
index 0000000..9333bd9
--- /dev/null
+++ b/src/frontend/display/cdisplay.cpp
@@ -0,0 +1,208 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cdisplay.h"
+
+#include "bthtmlreaddisplay.h"
+typedef BtHtmlReadDisplay HTMLREADDISPLAY;
+
+#include "cplainwritedisplay.h"
+#include "chtmlwritedisplay.h"
+
+#include "backend/managers/creferencemanager.h"
+
+#include "util/ctoolclass.h"
+
+
+//Qt includes
+#include <QClipboard>
+#include <QMenu>
+#include <QTimer>
+#include <QDebug>
+#include <QApplication>
+#include <QFileDialog>
+
+//KDE includes
+
+
+CDisplayConnections::CDisplayConnections( CDisplay* display ) : m_display(display) {}
+
+void CDisplayConnections::selectAll() {
+ m_display->selectAll();
+}
+
+void CDisplayConnections::saveAsHTML() {
+ m_display->save(CDisplay::HTMLText, CDisplay::Document);
+}
+
+void CDisplayConnections::saveAsPlain() {
+ m_display->save(CDisplay::PlainText, CDisplay::Document);
+}
+
+/** Emits the signal. */
+void CDisplayConnections::emitReferenceClicked( const QString& module, const QString& key) {
+ qDebug("CDisplayConnections::emitReferenceClicked");
+ qDebug() << "Module: " << module << " key: " << key;
+ emit referenceClicked( module, key );
+}
+
+/** Emits the signal. */
+void CDisplayConnections::emitReferenceDropped( const QString& key) {
+ emit referenceDropped(key);
+}
+
+/** Emits the signal. */
+void CDisplayConnections::emitTextChanged() {
+ emit textChanged();
+}
+
+void CDisplayConnections::copyAll() {
+ m_display->copy(CDisplay::PlainText, CDisplay::Document);
+}
+
+/** No descriptions */
+void CDisplayConnections::copySelection() {
+ qWarning("copyign the selected text");
+ m_display->copy(CDisplay::PlainText, CDisplay::SelectedText);
+}
+
+void CDisplayConnections::printAll(CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions) {
+ m_display->print(CDisplay::Document, displayOptions, filterOptions);
+}
+
+void CDisplayConnections::printAnchorWithText(CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions) {
+ m_display->print(CDisplay::AnchorWithText, displayOptions, filterOptions);
+}
+
+void CDisplayConnections::copyAnchorOnly() {
+ m_display->copy(CDisplay::PlainText, CDisplay::AnchorOnly);
+}
+
+void CDisplayConnections::copyAnchorTextOnly() {
+ m_display->copy(CDisplay::PlainText, CDisplay::AnchorTextOnly);
+}
+
+void CDisplayConnections::copyAnchorWithText() {
+ m_display->copy(CDisplay::PlainText, CDisplay::AnchorWithText);
+}
+
+void CDisplayConnections::saveAnchorWithText() {
+ m_display->save(CDisplay::PlainText, CDisplay::AnchorWithText);
+}
+
+void CDisplayConnections::clear() {
+ m_display->setText(QString::null);
+}
+
+void CDisplayConnections::zoomIn() {
+ m_display->zoomIn();
+}
+
+void CDisplayConnections::zoomOut() {
+ m_display->zoomOut();
+}
+
+void CDisplayConnections::openFindTextDialog() {
+ m_display->openFindTextDialog();
+}
+
+
+/*----------------------*/
+
+CReadDisplay* CDisplay::createReadInstance( CReadWindow* readWindow, QWidget* parent )
+{
+ return new HTMLREADDISPLAY(readWindow, parent);
+}
+
+CWriteDisplay* CDisplay::createWriteInstance( CWriteWindow* writeWindow, const CWriteDisplay::WriteDisplayType& type, QWidget* parent ) {
+ // qWarning("CDisplay::createWriteInstance");
+ if (type == PlainTextDisplay) {
+ return new CPlainWriteDisplay(writeWindow, parent);
+ }
+ else {
+ return new CHTMLWriteDisplay(writeWindow, parent);
+ };
+}
+
+
+CDisplay::CDisplay(CDisplayWindow* parent) :
+m_parentWindow(parent),
+m_connections( new CDisplayConnections( this ) ),
+m_popup(0) {}
+
+CDisplay::~CDisplay() {
+ delete m_connections;
+}
+
+bool CDisplay::copy( const CDisplay::TextType format, const CDisplay::TextPart part ) {
+ QApplication::clipboard()->setText( this->text(format, part) );
+ return true;
+}
+
+bool CDisplay::save( const CDisplay::TextType format, const CDisplay::TextPart part ) {
+ // qWarning("CDisplay::save( const CDisplay::TextType format, const CDisplay::TextPart part )");
+ const QString content = text(format, part);
+ QString filter = QString::null;
+
+ switch (format) {
+ case HTMLText:
+ filter = QObject::tr("HTML files") + QString(" (*.html *.htm);;") + QObject::tr("All files") + QString(" (*.*)");
+ break;
+ case PlainText:
+ filter = QObject::tr("Text files") + QString(" (*.txt);;") + QObject::tr("All files") + QString(" (*.*)");
+ break;
+ }
+
+ const QString filename = QFileDialog::getSaveFileName(0, QObject::tr("Save document ..."), "", filter);
+
+ if (!filename.isEmpty()) {
+ CToolClass::savePlainFile(filename, content);
+ }
+ return true;
+}
+
+/** Emits the signal which used when a reference was clicked. */
+void CDisplay::emitReferenceClicked( const QString& reference ) {
+ QString module, key;
+ CReferenceManager::Type type;
+ CReferenceManager::decodeHyperlink(reference, module, key, type);
+ if (module.isEmpty()) {
+ module = CReferenceManager::preferredModule( type );
+ }
+ m_connections->emitReferenceClicked(module, key);
+}
+
+/** Used when a reference was dropped onto the widget. */
+void CDisplay::emitReferenceDropped( const QString& reference ) {
+ QString module;
+ QString key;
+ CReferenceManager::Type type;
+ CReferenceManager::decodeHyperlink(reference, module, key, type);
+ m_connections->emitReferenceDropped(key);
+}
+
+/** Returns the connections obect used for signas and slots. */
+CDisplayConnections* CDisplay::connectionsProxy() const {
+ return m_connections;
+}
+
+CDisplayWindow* CDisplay::parentWindow() const {
+ return m_parentWindow;
+}
+
+/** Installs the popup which should be opened when the right mouse button was pressed. */
+void CDisplay::installPopup( QMenu* popup ) {
+ m_popup = popup;
+}
+
+/** Returns the popup menu which was set by installPopupMenu() */
+QMenu* CDisplay::installedPopup() {
+ return m_popup;
+}
+
diff --git a/src/frontend/display/cdisplay.h b/src/frontend/display/cdisplay.h
new file mode 100644
index 0000000..59a6a37
--- /dev/null
+++ b/src/frontend/display/cdisplay.h
@@ -0,0 +1,186 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CDISPLAY_H
+#define CDISPLAY_H
+
+//BibleTime includes
+#include "util/cpointers.h"
+#include "backend/managers/cswordbackend.h"
+
+//Qt includes
+#include <QMap>
+
+
+class CDisplayConnections;
+class CReadWindow;
+class CWriteWindow;
+
+class CDisplayWindow;
+class CReadDisplay;
+class CWriteDisplay;
+
+class QMenu;
+
+/** The base class for all display widgets.
+ * @author The BibleTime team
+ */
+class CDisplay : public CPointers {
+public:
+ enum WriteDisplayType {
+ HTMLDisplay = 0,
+ PlainTextDisplay
+ };
+
+ static CReadDisplay* createReadInstance(CReadWindow* readWindow, QWidget* parent = 0);
+ static CWriteDisplay* createWriteInstance( CWriteWindow* writeWindow, const WriteDisplayType& type = PlainTextDisplay, QWidget* parent = 0 );
+
+ enum TextType {
+ HTMLText, /* Used for HTML markup */
+ PlainText /* Plain text without links etc. */
+ };
+ enum TextPart {
+ Document, /* All text */
+ SelectedText, /* Only the selected text */
+ AnchorOnly,
+ AnchorTextOnly,
+ AnchorWithText
+ };
+
+ /**
+ * Copies the given text with the specified format into the applications clipboard.
+ */
+ virtual bool copy( const CDisplay::TextType format, const CDisplay::TextPart part );
+ /**
+ * Saves the given text with the specified format into the applications clipboard.
+ */
+ virtual bool save( const CDisplay::TextType format, const CDisplay::TextPart part );
+
+ //the pure virtual methods of this base class
+
+ /** Returns the text in the given format.
+ *
+ */
+ virtual const QString text( const CDisplay::TextType format = CDisplay::HTMLText, const CDisplay::TextPart part = CDisplay::Document ) = 0;
+ /**
+ * Sets the new text for this display widget.
+ */
+ virtual void setText( const QString& newText ) = 0;
+ /**
+ * Returns true if the display widget has a selection. Otherwise false.
+ */
+ virtual bool hasSelection() = 0;
+ /**
+ * Returns the view of this display widget.
+ */
+ virtual QWidget* view() = 0;
+ /**
+ * Selects the document text.
+ */
+ virtual void selectAll() = 0;
+ /**
+ * Returns the connections obect used for signas and slots.
+ */
+ virtual CDisplayConnections* connectionsProxy() const;
+ /**
+ * Returns the parent window used for this display widget.
+ */
+ CDisplayWindow* parentWindow() const;
+ virtual void print( const CDisplay::TextPart, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions) = 0;
+ /**
+ * Installs the popup which should be opened when the right mouse button was pressed.
+ */
+ void installPopup( QMenu* popup );
+ /**
+ * Returns the popup menu which was set by installPopupMenu()
+ */
+ QMenu* installedPopup();
+
+ virtual void zoomIn() {}
+ virtual void zoomOut() {}
+ virtual void openFindTextDialog() {}
+
+ enum NodeInfoType {
+ Lemma
+ };
+
+
+ virtual QMap<NodeInfoType, QString> getCurrentNodeInfo() {
+ return QMap<NodeInfoType, QString>();
+ }
+
+protected:
+ /**
+ * Used when a reference was dropped onto the widget.
+ */
+ void emitReferenceDropped( const QString& reference );
+ /**
+ * Emits the signal which used when a reference was clicked.
+ */
+ void emitReferenceClicked( const QString& reference );
+
+protected:
+ CDisplay(CDisplayWindow* parent);
+ virtual ~CDisplay();
+
+private:
+ CDisplayWindow* m_parentWindow;
+ CDisplayConnections* m_connections;
+ QMenu* m_popup;
+};
+
+class CDisplayConnections : public QObject {
+ Q_OBJECT
+public:
+ CDisplayConnections( CDisplay* parent );
+
+public slots:
+ virtual void selectAll();
+ void emitReferenceClicked( const QString& module, const QString& key);
+ void emitReferenceDropped( const QString& key );
+ void emitTextChanged();
+
+ //stuff which works in every CDisplay
+ void saveAsPlain();
+ void saveAsHTML();
+ void saveAnchorWithText();
+
+ void printAll(CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions);
+ void printAnchorWithText(CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions);
+
+ void copySelection();
+ void copyAll();
+ void copyAnchorWithText();
+ void copyAnchorTextOnly();
+ void copyAnchorOnly();
+
+ void clear();
+
+ void zoomIn();
+ void zoomOut();
+
+ void openFindTextDialog();
+
+signals:
+ void referenceClicked(const QString& module, const QString& key);
+ void referenceDropped(const QString& key);
+ void textChanged();
+
+private:
+ CDisplay* m_display;
+
+ struct {
+ QString module;
+ QString key;
+ } m_referenceClickedCache;
+};
+
+#endif
diff --git a/src/frontend/display/chtmlwritedisplay.cpp b/src/frontend/display/chtmlwritedisplay.cpp
new file mode 100644
index 0000000..4b9246e
--- /dev/null
+++ b/src/frontend/display/chtmlwritedisplay.cpp
@@ -0,0 +1,285 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#include "chtmlwritedisplay.h"
+#include "btfontsizewidget.h"
+#include "btcolorwidget.h"
+#include "frontend/displaywindow/cwritewindow.h"
+#include "frontend/displaywindow/btactioncollection.h"
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+
+#include <QMenu>
+#include <QToolTip>
+#include <QTextEdit>
+#include <QFontComboBox>
+#include <QMenu>
+#include <QToolBar>
+
+class BtActionCollection;
+
+CHTMLWriteDisplay::CHTMLWriteDisplay(CWriteWindow* parentWindow, QWidget* parent)
+: CPlainWriteDisplay(parentWindow,parent), m_fontFamilyChooser(0),
+ m_fontSizeChooser(0), m_colorChooser(0)
+{
+ m_actions.bold = 0;
+ m_actions.italic = 0;
+ m_actions.underline = 0;
+ m_actions.selectAll = 0;
+
+ setAcceptRichText(true);
+ setAcceptDrops(true);
+ viewport()->setAcceptDrops(true);
+}
+
+CHTMLWriteDisplay::~CHTMLWriteDisplay()
+{
+}
+
+void CHTMLWriteDisplay::setText( const QString& newText )
+{
+ QTextEdit::setHtml(newText);
+}
+
+const QString CHTMLWriteDisplay::plainText()
+{
+ return QTextEdit::toPlainText();
+}
+
+void CHTMLWriteDisplay::toggleBold(bool)
+{
+ setFontWeight( m_actions.bold->isChecked() ? QFont::Bold : QFont::Normal );
+}
+
+void CHTMLWriteDisplay::toggleItalic(bool)
+{
+ setFontItalic( m_actions.italic->isChecked() );
+}
+
+void CHTMLWriteDisplay::toggleUnderline(bool)
+{
+ setFontUnderline( m_actions.underline->isChecked() );
+}
+
+
+void CHTMLWriteDisplay::alignLeft(bool set)
+{
+ if (set && (alignment() != Qt::AlignLeft))
+ {
+ setAlignment(Qt::AlignLeft);
+ slotAlignmentChanged(Qt::AlignLeft);
+ }
+}
+
+void CHTMLWriteDisplay::alignCenter(bool set)
+{
+ if (set && (alignment() != Qt::AlignHCenter))
+ {
+ setAlignment(Qt::AlignHCenter);
+ slotAlignmentChanged(Qt::AlignHCenter);
+ }
+}
+
+void CHTMLWriteDisplay::alignRight(bool set)
+{
+ if (set && (alignment() != Qt::AlignRight))
+ {
+ setAlignment(Qt::AlignRight);
+ slotAlignmentChanged(Qt::AlignRight);
+ }
+}
+
+/** The text's alignment changed. Enable the right buttons. */
+void CHTMLWriteDisplay::slotAlignmentChanged( int a )
+{
+ bool alignLeft = false;
+ bool alignCenter = false;
+ bool alignRight = false;
+
+ if (a & Qt::AlignLeft)
+ {
+ alignLeft = true;
+ }
+ else if ((a & Qt::AlignHCenter) || (a & Qt::AlignCenter))
+ {
+ alignCenter = true;
+ }
+ else if (a & Qt::AlignRight)
+ {
+ alignRight = true;
+ }
+ else
+ {
+ alignLeft = true;
+ qWarning("unknown alignment %i", a);
+ }
+
+ m_actions.alignLeft->setChecked( alignLeft );
+ m_actions.alignCenter->setChecked( alignCenter );
+ m_actions.alignRight->setChecked( alignRight );
+}
+
+void CHTMLWriteDisplay::changeFontSize(int newSize)
+{
+ setFontPointSize((qreal)newSize);
+}
+
+/** Is called when a new color was selected. */
+void CHTMLWriteDisplay::slotColorSelected( const QColor& c)
+{
+ setTextColor( c );
+}
+
+/** Is called when a text with another color was selected. */
+void CHTMLWriteDisplay::slotColorChanged(const QColor& c)
+{
+ m_colorChooser->setColor(c);
+}
+
+void CHTMLWriteDisplay::slotFontChanged( const QFont& font )
+{
+ m_fontFamilyChooser->setCurrentFont(font);
+ m_fontSizeChooser->setFontSize( font.pointSize() );
+
+ m_actions.bold->setChecked( font.bold() );
+ m_actions.italic->setChecked( font.italic() );
+ m_actions.underline->setChecked( font.underline() );
+}
+
+void CHTMLWriteDisplay::slotFontFamilyChoosen(const QFont& font)
+{
+ setFontFamily(font.family());
+}
+
+void CHTMLWriteDisplay::setupToolbar(QToolBar * bar, BtActionCollection * actions)
+{
+ //--------------------font chooser-------------------------
+ m_fontFamilyChooser = new QFontComboBox(this);
+ actions->addAction(CResMgr::displaywindows::writeWindow::fontFamily::actionName, m_fontFamilyChooser);
+ m_fontFamilyChooser->setToolTip( tr("Font") );
+ bar->addWidget(m_fontFamilyChooser);
+ bool ok = connect(m_fontFamilyChooser, SIGNAL(currentFontChanged(const QFont&)),
+ this, SLOT(slotFontFamilyChoosen(const QFont&)));
+ Q_ASSERT(ok);
+
+ //--------------------font size chooser-------------------------
+ m_fontSizeChooser = new BtFontSizeWidget(this);
+ m_fontSizeChooser->setToolTip( tr("Font size") );
+ bar->addWidget(m_fontSizeChooser);
+ ok = connect(m_fontSizeChooser, SIGNAL(fontSizeChanged(int)), this, SLOT(changeFontSize(int)));
+ Q_ASSERT(ok);
+
+ //--------------------color button-------------------------
+ m_colorChooser = new BtColorWidget();
+ m_colorChooser->setToolTip(tr("Font color"));
+ bar->addWidget(m_colorChooser);
+ ok = connect(m_colorChooser, SIGNAL(changed(const QColor&)), this, SLOT(slotColorSelected(const QColor&)));
+ Q_ASSERT(ok);
+
+ bar->addSeparator();
+
+ //--------------------bold toggle-------------------------
+ m_actions.bold = new QAction(
+ util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::boldText::icon),
+ tr("Bold"),
+ actions);
+ m_actions.bold->setCheckable(true);
+ m_actions.bold->setShortcut(CResMgr::displaywindows::writeWindow::boldText::accel);
+ actions->addAction(CResMgr::displaywindows::writeWindow::boldText::actionName, m_actions.bold);
+ m_actions.bold->setToolTip( tr("Bold") );
+ connect(m_actions.bold, SIGNAL(toggled(bool)), this, SLOT(toggleBold(bool)));
+
+ bar->addAction(m_actions.bold);
+
+ //--------------------italic toggle-------------------------
+ m_actions.italic = new QAction(
+ util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::italicText::icon),
+ tr("Italic"),
+ actions );
+ m_actions.italic->setCheckable(true);
+ m_actions.bold->setShortcut(CResMgr::displaywindows::writeWindow::italicText::accel);
+ actions->addAction(CResMgr::displaywindows::writeWindow::italicText::actionName, m_actions.italic);
+ connect(m_actions.italic, SIGNAL(toggled(bool)), this, SLOT(toggleItalic(bool)));
+ m_actions.italic->setToolTip( tr("Italic") );
+ bar->addAction(m_actions.italic);
+
+ //--------------------underline toggle-------------------------
+ m_actions.underline = new QAction(
+ util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::underlinedText::icon),
+ tr("Underline"),
+ actions );
+ m_actions.underline->setCheckable(true);
+ m_actions.underline->setShortcut(CResMgr::displaywindows::writeWindow::underlinedText::accel);
+ actions->addAction(CResMgr::displaywindows::writeWindow::underlinedText::actionName, m_actions.underline);
+ connect(m_actions.underline, SIGNAL(toggled(bool)), this, SLOT(toggleUnderline(bool)));
+ m_actions.underline->setToolTip( tr("Underline") );
+ bar->addAction(m_actions.underline);
+
+ //seperate formatting from alignment buttons
+ bar->addSeparator();
+
+ //--------------------align left toggle-------------------------
+ m_actions.alignLeft = new QAction(
+ util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::alignLeft::icon),
+ tr("Left"), actions);
+ m_actions.alignLeft->setCheckable(true);
+ m_actions.alignLeft->setShortcut(CResMgr::displaywindows::writeWindow::alignLeft::accel);
+ actions->addAction(CResMgr::displaywindows::writeWindow::alignLeft::actionName, m_actions.alignLeft);
+ connect(m_actions.alignLeft, SIGNAL(toggled(bool)), this, SLOT(alignLeft(bool)));
+ m_actions.alignLeft->setToolTip( tr("Align left") );
+ bar->addAction(m_actions.alignLeft);
+
+ //--------------------align center toggle-------------------------
+ m_actions.alignCenter = new QAction(
+ util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::alignCenter::icon),
+ tr("Center"), actions);
+ m_actions.alignCenter->setCheckable(true);
+ m_actions.alignCenter->setShortcut(CResMgr::displaywindows::writeWindow::alignCenter::accel);
+ actions->addAction(CResMgr::displaywindows::writeWindow::alignCenter::actionName, m_actions.alignCenter);
+ connect(m_actions.alignCenter, SIGNAL(toggled(bool)), this, SLOT(alignCenter(bool)));
+ m_actions.alignCenter->setToolTip( tr("Center") );
+ bar->addAction(m_actions.alignCenter);
+
+ //--------------------align right toggle-------------------------
+ m_actions.alignRight = new QAction(
+ util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::alignRight::icon),
+ tr("Right"), actions);
+ m_actions.alignRight->setCheckable(true);
+ m_actions.alignRight->setShortcut(CResMgr::displaywindows::writeWindow::alignRight::accel);
+ actions->addAction(CResMgr::displaywindows::writeWindow::alignRight::actionName, m_actions.alignRight);
+ connect(m_actions.alignRight, SIGNAL(toggled(bool)), this, SLOT(alignRight(bool)));
+ m_actions.alignRight->setToolTip( tr("Align right") );
+ bar->addAction(m_actions.alignRight);
+
+ connect(this, SIGNAL(currentFontChanged(const QFont&)), SLOT(slotFontChanged(const QFont&)));
+ connect(this, SIGNAL(currentAlignmentChanged(int)), SLOT(slotAlignmentChanged(int)));
+ connect(this, SIGNAL(currentColorChanged(const QColor&)), SLOT(slotColorChanged(const QColor&)));
+
+ //set initial values for toolbar items
+ slotFontChanged( font() );
+ slotAlignmentChanged( alignment() );
+ slotColorChanged( textColor() );
+}
+
+/** Reimplementation to show a popup menu if the right mouse button was clicked. */
+QMenu* CHTMLWriteDisplay::createPopupMenu( const QPoint& )
+{
+ if (!m_actions.selectAll)
+ {
+ m_actions.selectAll = new QAction(tr("Select all"), this);
+ connect(m_actions.selectAll, SIGNAL(triggered(bool)), SLOT(selectAll()));
+ }
+
+ QMenu* popup = new QMenu(this);
+ popup->setTitle(tr("HTML editor window"));
+ popup->addAction(m_actions.selectAll);
+ return popup;
+}
diff --git a/src/frontend/display/chtmlwritedisplay.h b/src/frontend/display/chtmlwritedisplay.h
new file mode 100644
index 0000000..155966a
--- /dev/null
+++ b/src/frontend/display/chtmlwritedisplay.h
@@ -0,0 +1,106 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CHTMLWRITEDISPLAY_H
+#define CHTMLWRITEDISPLAY_H
+
+//BibleTime includes
+#include "cplainwritedisplay.h"
+
+class CWriteWindow;
+class QMenu;
+class QWidget;
+class QToolBar;
+class QAction;
+class QFontComboBox;
+class BtFontSizeWidget;
+class BtColorWidget;
+class BtActionCollection;
+
+/** The WYSIWYG implementation of the write display interface.
+ * @author The BibleTime team
+ */
+class CHTMLWriteDisplay : public CPlainWriteDisplay
+{
+ Q_OBJECT
+public:
+ /**
+ * Sets the new text for this display widget. (CPlainWriteDisplay).
+ */
+ virtual void setText( const QString& newText );
+ /**
+ * Returns the text of this edit widget. (CPlainWriteDisplay).
+ */
+ virtual const QString plainText();
+
+ /**
+ * Creates the necessary action objects and puts them on the toolbar.
+ * (CPlainWriteDisplay)
+ */
+ virtual void setupToolbar(QToolBar * bar, BtActionCollection * actionCollection);
+
+protected:
+ friend class CDisplay;
+ CHTMLWriteDisplay(CWriteWindow* parentWindow, QWidget* parent);
+ ~CHTMLWriteDisplay();
+ /**
+ * Reimplementation to show a popup menu if the right mouse button was clicked.
+ * (CPlainWriteDisplay)
+ */
+ virtual QMenu* createPopupMenu( const QPoint& pos );
+
+protected slots:
+ void toggleBold(bool);
+ void toggleItalic(bool);
+ void toggleUnderline(bool);
+
+ void alignLeft(bool);
+ void alignCenter(bool);
+ void alignRight(bool);
+
+ void changeFontSize(int);
+
+ void slotFontChanged( const QFont& );
+ void slotFontFamilyChoosen(const QFont&);
+
+ /**
+ * The text's alignment changed. Enable the right buttons.
+ */
+ void slotAlignmentChanged( int );
+ /**
+ * Is called when a new color was selected.
+ */
+ void slotColorSelected( const QColor& );
+ /**
+ * Is called when a text with another color was selected.
+ */
+ void slotColorChanged( const QColor& );
+
+private:
+ struct
+ {
+ QAction* bold;
+ QAction* italic;
+ QAction* underline;
+
+ QAction* alignLeft;
+ QAction* alignCenter;
+ QAction* alignRight;
+
+ //popup menu
+ QAction* selectAll;
+ }
+ m_actions;
+
+ QFontComboBox* m_fontFamilyChooser;
+ BtFontSizeWidget* m_fontSizeChooser;
+ BtColorWidget* m_colorChooser;
+};
+
+#endif
diff --git a/src/frontend/display/cplainwritedisplay.cpp b/src/frontend/display/cplainwritedisplay.cpp
new file mode 100644
index 0000000..3880f35
--- /dev/null
+++ b/src/frontend/display/cplainwritedisplay.cpp
@@ -0,0 +1,160 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cplainwritedisplay.h"
+#include "frontend/displaywindow/btactioncollection.h"
+#include "frontend/cdragdrop.h"
+#include "frontend/displaywindow/cdisplaywindow.h"
+#include "frontend/displaywindow/cwritewindow.h"
+
+#include "backend/keys/cswordkey.h"
+
+#include <boost/scoped_ptr.hpp>
+
+//Qt includes
+#include <QDragEnterEvent>
+#include <QDropEvent>
+#include <QDragMoveEvent>
+#include <QMenu>
+
+
+CPlainWriteDisplay::CPlainWriteDisplay(CWriteWindow* parentWindow, QWidget* parent) : QTextEdit(parentWindow ? parentWindow : parent), CWriteDisplay(parentWindow) {
+ setAcceptRichText(false);
+ setAcceptDrops(true);
+ viewport()->setAcceptDrops(true);
+
+ connect(this, SIGNAL(textChanged()),
+ connectionsProxy(), SLOT(emitTextChanged()));
+}
+
+CPlainWriteDisplay::~CPlainWriteDisplay() {}
+
+/** Reimplementation. */
+void CPlainWriteDisplay::selectAll() {
+ QTextEdit::selectAll();
+}
+
+void CPlainWriteDisplay::setText( const QString& newText ) {
+ //make sure the text has been converted to show \n instead of <br/>
+ QString text = newText;
+// text.replace("\n<br /><!-- BT newline -->\n", "\n");
+ text.replace("<br />", "\n"); //inserted by BT or the Qt textedit widget
+
+ QTextEdit::setText(text);
+}
+
+bool CPlainWriteDisplay::hasSelection() {
+ //TODO: test this
+ return textCursor().hasSelection();
+}
+
+QWidget* CPlainWriteDisplay::view() {
+ qDebug("CPlainWriteDisplay::view()");
+ return this;
+}
+
+const QString CPlainWriteDisplay::text( const CDisplay::TextType /*format*/, const CDisplay::TextPart /*part*/) {
+ return QString::null;
+}
+
+void CPlainWriteDisplay::print( const CDisplay::TextPart, CSwordBackend::DisplayOptions, CSwordBackend::FilterOptions) {
+}
+
+/** Sets the current status of the edit widget. */
+void CPlainWriteDisplay::setModified( const bool modified ) {
+ document()->setModified(modified);
+}
+
+/** Reimplementation. */
+bool CPlainWriteDisplay::isModified() const {
+ return document()->isModified();
+}
+
+
+/** Returns the text of this edit widget. */
+const QString CPlainWriteDisplay::plainText() {
+ QString ret = QTextEdit::toPlainText();
+
+ //in plain text mode the text just contains newlines, convert them into <br/> before we return the text for display in a HTML widget
+ ret.replace("\n", "<br />");
+
+ return ret;
+}
+
+/** Reimplementation from QTextEdit. Provides an popup menu for the given position. */
+QMenu* CPlainWriteDisplay::createPopupMenu( const QPoint& /*pos*/ ) {
+ return installedPopup();
+}
+//
+///** Reimplementation from QTextEdit. Provides an popup menu for the given position. */
+//QMenu* CPlainWriteDisplay::createPopupMenu( ) {
+// return installedPopup();
+//}
+
+/** Creates the necessary action objects and puts them on the toolbar. */
+void CPlainWriteDisplay::setupToolbar(QToolBar*, BtActionCollection*) {}
+
+/** Reimplementation to insert the text of a dragged reference into the edit view. */
+void CPlainWriteDisplay::dragEnterEvent( QDragEnterEvent* e ) {
+ //if (CDragDropMgr::canDecode(e)) {
+ if (e->mimeData()->hasFormat("BibleTime/Bookmark") || e->mimeData()->hasFormat("text/plain")) {
+ e->acceptProposedAction();
+ }
+ else {
+ //e->accept(false);
+ e->ignore();
+ }
+}
+
+/** Reimplementation to insert the text of a dragged reference into the edit view. */
+void CPlainWriteDisplay::dragMoveEvent( QDragMoveEvent* e ) {
+ if (e->mimeData()->hasFormat("BibleTime/Bookmark") || e->mimeData()->hasFormat("text/plain")) {
+ //placeCursor(e->pos());
+ setTextCursor(cursorForPosition(e->pos()));
+ ensureCursorVisible();
+ e->acceptProposedAction();
+ }
+ else {
+ //e->accept(false);
+ e->ignore();
+ }
+}
+
+/** Reimplementation to manage drops of our drag and drop objects. */
+void CPlainWriteDisplay::dropEvent( QDropEvent* e )
+{
+ //qDebug("CPlainWriteDisplay::dropEvent");
+ const BTMimeData* mimedata = qobject_cast<const BTMimeData*>(e->mimeData());
+
+ if ( mimedata && mimedata->hasFormat("BibleTime/Bookmark") ) {
+ //qDebug("format was bookmark");
+ e->acceptProposedAction();
+
+ BTMimeData::ItemList items = mimedata->bookmarks();
+ BTMimeData::ItemList::iterator it;
+ for (it = items.begin(); it != items.end(); ++it) {
+
+ CSwordModuleInfo* module = backend()->findModuleByName((*it).module());
+ boost::scoped_ptr<CSwordKey> key( CSwordKey::createInstance(module) );
+ key->key( (*it).key() );
+ QString moduleText = key->strippedText();
+
+ const QString text = QString::fromLatin1("%1\n(%2, %3)\n").arg(moduleText).arg((*it).key()).arg((*it).module());
+
+ setTextCursor(cursorForPosition(e->pos()));
+ textCursor().insertText( text );
+ }
+ }
+ else if ( e->mimeData()->hasFormat("text/plain")) {
+ //qDebug("format was plain text");
+ e->acceptProposedAction();
+ setTextCursor(cursorForPosition(e->pos()));
+ textCursor().insertText( e->mimeData()->text() );
+ }
+}
diff --git a/src/frontend/display/cplainwritedisplay.h b/src/frontend/display/cplainwritedisplay.h
new file mode 100644
index 0000000..eca0a3a
--- /dev/null
+++ b/src/frontend/display/cplainwritedisplay.h
@@ -0,0 +1,100 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CPLAINWRITEDISPLAY_H
+#define CPLAINWRITEDISPLAY_H
+
+//Bibletime include files
+#include "cwritedisplay.h"
+
+//Qt includes
+#include <QTextEdit>
+
+
+class CHTMLWriteDisplay;
+
+class QWidget;
+class QMenu;
+class QDragMoveEvent;
+class QDropEvent;
+class QDragEnterEvent;
+class BtActionCollection;
+
+/** The write display implementation for plain source code editing.
+ * @author The BibleTime team
+ */
+class CPlainWriteDisplay : public QTextEdit, public CWriteDisplay {
+public:
+ /**
+ * Reimplementation.
+ */
+ virtual void selectAll();
+ /**
+ * Sets the new text for this display widget.
+ */
+ virtual void setText( const QString& newText );
+ /**
+ * Returns true if the display widget has a selection. Otherwise false.
+ */
+ virtual bool hasSelection();
+ /**
+ * Returns the view of this display widget.
+ */
+ virtual QWidget* view();
+ virtual const QString text( const CDisplay::TextType format = CDisplay::HTMLText, const CDisplay::TextPart part = CDisplay::Document );
+ virtual void print( const CDisplay::TextPart, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions );
+ /**
+ * Reimplementation (CWriteDisplay).
+ */
+ virtual bool isModified() const;
+ /**
+ * Sets the current status of the edit widget (CWriteDisplay).
+ */
+ virtual void setModified( const bool modified );
+ /**
+ * Returns the text of this edit widget (CWriteDisplay).
+ */
+ virtual const QString plainText();
+ /**
+ * Creates the necessary action objects and puts them on the toolbar (CWriteDisplay).
+ */
+ virtual void setupToolbar(QToolBar*, BtActionCollection*);
+
+protected:
+ friend class CDisplay;
+ friend class CHTMLWriteDisplay;
+
+ CPlainWriteDisplay(CWriteWindow* parentWindow, QWidget* parent);
+ virtual ~CPlainWriteDisplay();
+ /**
+ * Reimplementation from QTextEdit. Provides an popup menu for the given position.
+ */
+ virtual QMenu* createPopupMenu( const QPoint& pos );
+// /**
+// * Reimplementation from QTextEdit. Provides an popup menu.
+// */
+// virtual QMenu* createPopupMenu();
+ /**
+ * Reimplementation from QTextEdit to manage drops of our drag and drop objects.
+ */
+ virtual void dropEvent( QDropEvent* e );
+ /**
+ * Reimplementation from QTextEdit to insert the text of a dragged reference into the edit view.
+ */
+ virtual void dragEnterEvent( QDragEnterEvent* e );
+ /**
+ * Reimplementation from QTextEdit to insert the text of a dragged reference into the edit view.
+ */
+ virtual void dragMoveEvent( QDragMoveEvent* e );
+
+};
+
+#endif
diff --git a/src/frontend/display/creaddisplay.cpp b/src/frontend/display/creaddisplay.cpp
new file mode 100644
index 0000000..383d332
--- /dev/null
+++ b/src/frontend/display/creaddisplay.cpp
@@ -0,0 +1,112 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+//BibleTime includes
+#include "creaddisplay.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/drivers/cswordbiblemoduleinfo.h"
+#include "backend/drivers/cswordlexiconmoduleinfo.h"
+#include "backend/drivers/cswordbookmoduleinfo.h"
+#include "backend/keys/cswordkey.h"
+#include "backend/keys/cswordversekey.h"
+#include "backend/keys/cswordtreekey.h"
+#include "backend/keys/cswordldkey.h"
+
+#include "frontend/displaywindow/cdisplaywindow.h"
+#include "frontend/displaywindow/creadwindow.h"
+
+#include "frontend/cexportmanager.h"
+
+#include <boost/scoped_ptr.hpp>
+
+//KDE includes
+
+
+CReadDisplay::CReadDisplay(CReadWindow* readWindow) :
+CDisplay(readWindow),
+m_activeAnchor(QString::null),
+m_useMouseTracking(true) {}
+
+CReadDisplay::~CReadDisplay() {}
+
+/** Returns the current active anchor. */
+const QString& CReadDisplay::activeAnchor() {
+ return m_activeAnchor;
+}
+
+/** Sets the current anchor to the parameter. */
+void CReadDisplay::setActiveAnchor( const QString& anchor ) {
+ m_activeAnchor = anchor;
+}
+
+
+/** Returns true if the display has an active anchor. */
+bool CReadDisplay::hasActiveAnchor() {
+ return !activeAnchor().isEmpty();
+}
+
+
+void CReadDisplay::print(const CDisplay::TextPart type, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions) {
+ CDisplayWindow* window = parentWindow();
+ CSwordKey* const key = window->key();
+ CSwordModuleInfo* module = key->module();
+
+
+ CExportManager mgr(QObject::tr("Print keys"),false, QString::null, parentWindow()->filterOptions(), parentWindow()->displayOptions());
+
+ switch (type) {
+ case Document: {
+ if (module->type() == CSwordModuleInfo::Bible) {
+ CSwordVerseKey* vk = dynamic_cast<CSwordVerseKey*>(key);
+
+ CSwordVerseKey startKey(*vk);
+ startKey.Verse(1);
+
+ CSwordVerseKey stopKey(*vk);
+
+ CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module);
+ if (bible) {
+ stopKey.Verse( bible->verseCount( bible->bookNumber(startKey.book()), startKey.Chapter() ) );
+ }
+
+ mgr.printKey(module, startKey.key(), stopKey.key(), displayOptions, filterOptions);
+ }
+ else if (module->type() == CSwordModuleInfo::Lexicon || module->type() == CSwordModuleInfo::Commentary ) {
+ mgr.printKey(module, key->key(), key->key(), displayOptions, filterOptions);
+ }
+ else if (module->type() == CSwordModuleInfo::GenericBook) {
+ CSwordTreeKey* tree = dynamic_cast<CSwordTreeKey*>(key);
+
+ CSwordTreeKey startKey(*tree);
+ // while (startKey.previousSibling()) { // go to first sibling on this level!
+ // }
+
+ CSwordTreeKey stopKey(*tree);
+ // if (CSwordBookModuleInfo* book = dynamic_cast<CSwordBookModuleInfo*>(module)) {
+ // while ( stopKey.nextSibling() ) { //go to last displayed sibling!
+ // }
+ // }
+ mgr.printKey(module, startKey.key(), stopKey.key(), displayOptions, filterOptions);
+ }
+ }
+
+ case AnchorWithText: {
+ if (hasActiveAnchor()) {
+ mgr.printByHyperlink( activeAnchor(), displayOptions, filterOptions );
+ }
+ }
+
+ default:
+ break;
+ }
+}
+
diff --git a/src/frontend/display/creaddisplay.h b/src/frontend/display/creaddisplay.h
new file mode 100644
index 0000000..f4a00c4
--- /dev/null
+++ b/src/frontend/display/creaddisplay.h
@@ -0,0 +1,73 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CREADDISPLAY_H
+#define CREADDISPLAY_H
+
+#include "cdisplay.h"
+#include "backend/managers/cswordbackend.h"
+
+#include <QString>
+
+/**The base class for all read-only widgets like KHTMLView.
+ *@author The BibleTime team
+ */
+
+class CReadDisplay : public CDisplay {
+public:
+ /**
+ * Returns true if the display has an active anchor.
+ */
+ bool hasActiveAnchor();
+ /**
+ * Returns the current active anchor.
+ */
+ const QString& activeAnchor();
+ /**
+ * Moves the widget to the given anchor.
+ */
+ virtual void moveToAnchor( const QString& ) = 0;
+ virtual void print(const CDisplay::TextPart, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions);
+
+ void setMouseTracking(const bool trackingEnabled) {
+ m_useMouseTracking = trackingEnabled;
+ };
+ bool getMouseTracking() const {
+ return m_useMouseTracking;
+ };
+
+protected: // Protected methods
+ friend class BtHtmlReadDisplay;
+ friend class BtHtmlReadDisplayView;
+ friend class BtHtmlJsObject;
+ friend class CDisplay;
+ friend class CHTMLReadDisplay;
+ friend class CHTMLReadDisplayView;
+
+ CReadDisplay( CReadWindow* readWindow );
+ ~CReadDisplay();
+
+ /**
+ * Sets the current anchor to the parameter.
+ */
+ void setActiveAnchor( const QString& );
+
+private: // Public attributes
+ /**
+ * The member which hols the current anchor.
+ */
+
+ QString m_activeAnchor;
+
+ bool m_useMouseTracking;
+};
+
+#endif
diff --git a/src/frontend/display/cwritedisplay.cpp b/src/frontend/display/cwritedisplay.cpp
new file mode 100644
index 0000000..ddd9d8f
--- /dev/null
+++ b/src/frontend/display/cwritedisplay.cpp
@@ -0,0 +1,21 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+//BibleTime includes
+#include "cwritedisplay.h"
+
+#include "frontend/displaywindow/cwritewindow.h"
+
+
+CWriteDisplay::CWriteDisplay( CWriteWindow* writeWindow ) : CDisplay(writeWindow) {}
+
+CWriteDisplay::~CWriteDisplay() {}
+
diff --git a/src/frontend/display/cwritedisplay.h b/src/frontend/display/cwritedisplay.h
new file mode 100644
index 0000000..eaa2d9d
--- /dev/null
+++ b/src/frontend/display/cwritedisplay.h
@@ -0,0 +1,51 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CWRITEDISPLAY_H
+#define CWRITEDISPLAY_H
+
+#include "cdisplay.h"
+
+class QToolBar;
+class BtActionCollection;
+
+
+/**The base class for all read/write-display classes.
+ *@author The BibleTime team
+ */
+
+class CWriteDisplay : public CDisplay {
+protected:
+ friend class CDisplay;
+ friend class CPlainWriteDisplay;
+ CWriteDisplay( CWriteWindow* writeWindow );
+ ~CWriteDisplay();
+
+public: // Public methods
+ /**
+ * Sets the current modified status of the widget.
+ */
+ virtual void setModified( const bool modified ) = 0;
+ /**
+ * Returns true if the current text was modified.
+ */
+ virtual bool isModified() const = 0;
+ /**
+ * Returns the text of this edit widget.
+ */
+ virtual const QString plainText() = 0;
+ /**
+ * Creates the necessary action objects and puts them on the toolbar.
+ */
+ virtual void setupToolbar( QToolBar* bar, BtActionCollection* actionCollection ) = 0;
+};
+
+#endif
diff --git a/src/frontend/displaywindow/btactioncollection.cpp b/src/frontend/displaywindow/btactioncollection.cpp
new file mode 100644
index 0000000..f71709a
--- /dev/null
+++ b/src/frontend/displaywindow/btactioncollection.cpp
@@ -0,0 +1,38 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btactioncollection.h"
+
+BtActionCollection::BtActionCollection(QObject* parent)
+ : QObject(parent)
+{
+}
+
+BtActionCollection::~BtActionCollection()
+{
+}
+
+QAction* BtActionCollection::action(const QString& name)
+{
+ Q_ASSERT(m_actions[name] != 0);
+ return m_actions[name];
+}
+
+void BtActionCollection::addAction(const QString& name, QAction* action)
+{
+ Q_ASSERT(action != 0);
+// Q_ASSERT(m_actions[name] == 0); // TODO - replacing actions is ok???
+ m_actions[name] = action;
+}
+
+void BtActionCollection::addAction(const QString &name, const QObject *receiver)
+{
+}
+
+
diff --git a/src/frontend/displaywindow/btactioncollection.h b/src/frontend/displaywindow/btactioncollection.h
new file mode 100644
index 0000000..23ee1cf
--- /dev/null
+++ b/src/frontend/displaywindow/btactioncollection.h
@@ -0,0 +1,32 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+#ifndef BT_ACTION_COLLECTION_S
+#define BT_ACTION_COLLECTION_S
+
+#include <QObject>
+#include <QMap>
+
+class QString;
+class QAction;
+
+class BtActionCollection : public QObject
+{
+ Q_OBJECT
+public:
+ BtActionCollection(QObject* parent);
+ ~BtActionCollection();
+ void addAction(const QString& name, QAction* action);
+ void addAction(const QString &name, const QObject *receiver);
+ QAction* action(const QString& name);
+
+private:
+ QMap<QString, QAction*> m_actions;
+};
+
+#endif
diff --git a/src/frontend/displaywindow/bttoolbarpopupaction.cpp b/src/frontend/displaywindow/bttoolbarpopupaction.cpp
new file mode 100644
index 0000000..907a779
--- /dev/null
+++ b/src/frontend/displaywindow/bttoolbarpopupaction.cpp
@@ -0,0 +1,51 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "bttoolbarpopupaction.h"
+#include <QMenu>
+#include <QToolButton>
+#include <QAction>
+
+// This class provides a toolbar widget that has a icon plus a right side down arrow
+// The icon is typically set to a back or forward arrow and the down arrow has a popup
+// menu when clicked. The menu is typicallly populated with history actions.
+BtToolBarPopupAction::BtToolBarPopupAction(const QIcon& icon, const QString& text, QObject* parent)
+ : QWidgetAction(parent), m_icon(icon), m_text(text)
+{
+ m_menu = new QMenu();
+}
+
+BtToolBarPopupAction::~BtToolBarPopupAction()
+{
+ delete m_menu;
+}
+
+QMenu* BtToolBarPopupAction::popupMenu() const
+{
+ return m_menu;
+}
+
+QWidget* BtToolBarPopupAction::createWidget(QWidget* parent)
+{
+ m_button = new QToolButton(parent);
+ setIcon(m_icon);
+ setToolTip(m_text);
+ m_button->setDefaultAction(this);
+ m_button->setPopupMode(QToolButton::MenuButtonPopup);
+ m_button->setMenu(m_menu);
+ bool ok = connect(m_button, SIGNAL(pressed()), this, SLOT(buttonPressed()));
+ Q_ASSERT(ok);;
+ return m_button;
+}
+
+void BtToolBarPopupAction::buttonPressed()
+{
+ emit triggered();
+}
+
diff --git a/src/frontend/displaywindow/bttoolbarpopupaction.h b/src/frontend/displaywindow/bttoolbarpopupaction.h
new file mode 100644
index 0000000..63ed491
--- /dev/null
+++ b/src/frontend/displaywindow/bttoolbarpopupaction.h
@@ -0,0 +1,45 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+#ifndef BT_TOOLBAR_POPUP_ACTION_H
+#define BT_TOOLBAR_POPUP_ACTION_H
+
+#include <QWidgetAction>
+
+class QMenu;
+class QString;
+class QIcon;
+class QToolButton;
+
+// This class manages the toolbar display for going forward and backward in history.
+class BtToolBarPopupAction : public QWidgetAction
+{
+ Q_OBJECT
+public:
+
+ BtToolBarPopupAction(const QIcon& icon, const QString& text, QObject* parent);
+ ~BtToolBarPopupAction();
+ QMenu* popupMenu() const;
+
+signals:
+ void triggered();
+
+protected:
+ QWidget* createWidget(QWidget* parent);
+
+private slots:
+ void buttonPressed();
+
+private:
+ QMenu* m_menu;
+ QToolButton* m_button;
+ QIcon m_icon;
+ QString m_text;
+};
+
+#endif
diff --git a/src/frontend/displaywindow/cbiblereadwindow.cpp b/src/frontend/displaywindow/cbiblereadwindow.cpp
new file mode 100644
index 0000000..15354fa
--- /dev/null
+++ b/src/frontend/displaywindow/cbiblereadwindow.cpp
@@ -0,0 +1,480 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#include "cbiblereadwindow.h"
+#include "btactioncollection.h"
+
+#include "ccommentaryreadwindow.h"
+#include "cbuttons.h"
+
+#include "backend/keys/cswordversekey.h"
+#include "backend/drivers/cswordbiblemoduleinfo.h"
+
+#include "frontend/profile/cprofilewindow.h"
+#include "frontend/cexportmanager.h"
+#include "backend/config/cbtconfig.h"
+#include "frontend/cmdiarea.h"
+#include "frontend/display/creaddisplay.h"
+#include "frontend/keychooser/ckeychooser.h"
+
+#include "util/ctoolclass.h"
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+
+#include <math.h>
+
+//Qt includes
+#include <QWidget>
+#include <QTimer>
+#include <QEvent>
+#include <QApplication>
+#include <QMenu>
+#include <QMdiSubWindow>
+#include <QAction>
+#include <QMenu>
+#include <QMenu>
+
+using namespace Profile;
+
+CBibleReadWindow::CBibleReadWindow(QList<CSwordModuleInfo*> moduleList, CMDIArea* parent)
+ : CLexiconReadWindow(moduleList, parent)
+{
+ qDebug("CBibleReadWindow::CBibleReadWindow");
+}
+
+CBibleReadWindow::~CBibleReadWindow() {}
+
+void CBibleReadWindow::applyProfileSettings( CProfileWindow* const settings ) {
+ CLexiconReadWindow::applyProfileSettings(settings);
+
+ const int count = displaySettingsButton()->menuItemCount();
+ int result = settings->windowSettings();
+ for (int i = count-1; i>=1; i--) {
+ if (result-(int)pow((double)2,i-1)>= 0) { //2^i was added before, so item with index i is set
+ result -= (int)pow((double)2,i-1);
+ displaySettingsButton()->setItemStatus(i,true);
+ }
+ else {
+ displaySettingsButton()->setItemStatus(i,false);
+ }
+ }
+ displaySettingsButton()->setChanged();
+}
+
+void CBibleReadWindow::storeProfileSettings( CProfileWindow* const settings ) {
+ CLexiconReadWindow::storeProfileSettings(settings);
+
+ const int count = displaySettingsButton()->menuItemCount();
+ int result = 0;
+ //now check every item
+ for (int i = 1; i < count; i++) { //first item is a title
+ if (displaySettingsButton()->itemStatus(i)) //item is checked
+ result += (int)pow((double)2,i-1);//add 2^i (the i. digit in binary)
+ }
+ settings->setWindowSettings(result);
+}
+
+
+/** Reimplementation. */
+void CBibleReadWindow::insertKeyboardActions( BtActionCollection* const a ) {
+
+ QAction* qaction;
+
+ qaction = new QAction(tr("Next book"), a);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextBook::accel);
+ a->addAction("nextBook", qaction);
+
+ qaction = new QAction(tr("Previous book"), a);
+ qaction->setShortcut( CResMgr::displaywindows::bibleWindow::previousBook::accel);
+ a->addAction("previousBook", qaction);
+
+ qaction = new QAction(tr("Next chapter"), a);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextChapter::accel);
+ a->addAction("nextChapter", qaction);
+
+ qaction = new QAction(tr("Previous chapter"), a);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousChapter::accel);
+ a->addAction("previousChapter", qaction);
+
+ qaction = new QAction(tr("Next verse"), a);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextVerse::accel);
+ a->addAction("nextVerse", qaction);
+
+ qaction = new QAction(tr("Previous verse"), a);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousVerse::accel);
+ a->addAction("previousVerse", qaction);
+
+
+ //popup menu items
+ // new KAction(tr("Select all"), KStdAccel::selectAll(), a, "selectAll");
+
+ //copy menu items
+ // new KAction(tr("Copy reference only"), KShortcut(0), a, "copyReferenceOnly");
+ // new KAction(tr("Text of reference"), KShortcut(0), a, "copyTextOfReference");
+ // new KAction(tr("Reference with text"), KShortcut(0), a, "copyReferenceWithText");
+ qaction = new QAction(tr("Copy chapter"), a);
+ a->addAction("copyChapter", qaction);
+ // new KAction(tr("Copy selected text"), KStdAccel::copy(), a, "copySelectedText");
+
+ //save menu
+ // new KAction(tr("Reference with text"), KShortcut(0), a, "saveReferenceWithText");
+ qaction = new QAction(tr("Save chapter as plain text"), a);
+ a->addAction("saveChapterAsPlainText", qaction);
+
+ qaction = new QAction(tr("Save chapter as HTML"), a);
+ a->addAction("saveChapterAsHTML", qaction);
+ // new KAction(tr("Reference with text"), KShortcut(0), a, "saveReferenceWithText");
+
+ //print
+ qaction = new QAction(tr("Print chapter"), a);
+ qaction->setShortcut(QKeySequence::Print);
+ a->addAction("printChapter", qaction);
+}
+
+void CBibleReadWindow::initActions() {
+ qDebug("CBibleReadWindow::initActions");
+
+ BtActionCollection* ac = actionCollection();
+ CBibleReadWindow::insertKeyboardActions(ac);
+ CLexiconReadWindow::initActions(); //make sure the predefined actions are available
+
+ //cleanup, not a clean oo-solution
+ ac->action("nextEntry")->setEnabled(false);
+ ac->action("previousEntry")->setEnabled(false);
+
+ QAction* qaction;
+
+ qaction = new QAction(tr("Next book"), ac);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextBook::accel);
+ QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextBook()) );
+ ac->addAction("nextBook", qaction);
+
+ qaction = new QAction(tr("Previous book"), ac);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousBook::accel);
+ QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousBook()) );
+ ac->addAction("previousBook", qaction);
+
+ qaction = new QAction(tr("Next chapter"), ac);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextChapter::accel);
+ QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextChapter()) );
+ ac->addAction("nextChapter", qaction);
+
+ qaction = new QAction(tr("Previous chapter"),ac);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousChapter::accel);
+ QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousChapter()) );
+ ac->addAction("previousChapter", qaction);
+
+ qaction = new QAction(tr("Next verse"), ac);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextVerse::accel);
+ QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextVerse()) );
+ ac->addAction("nextVerse", qaction);
+
+ qaction = new QAction(tr("Previous verse"), ac);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousVerse::accel);
+ QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousVerse()) );
+ ac->addAction("previousVerse", qaction);
+
+ m_actions.selectAll = qobject_cast<QAction*>(ac->action("selectAll"));
+ Q_ASSERT(m_actions.selectAll);
+
+ m_actions.findText = qobject_cast<QAction*>(ac->action("findText"));
+ Q_ASSERT(m_actions.findText);
+
+ m_actions.findStrongs = new QAction(
+// QIcon(CResMgr::displaywindows::general::findStrongs::icon),
+ tr("Strong's search"),
+ ac
+ );
+ m_actions.findStrongs->setShortcut(CResMgr::displaywindows::general::findStrongs::accel);
+ m_actions.findStrongs->setToolTip(tr("Find all occurences of the Strong number currently under the mouse cursor"));
+ QObject::connect(m_actions.findStrongs, SIGNAL(triggered()), this, SLOT(openSearchStrongsDialog()) );
+ ac->addAction(CResMgr::displaywindows::general::findStrongs::actionName, m_actions.findStrongs);
+
+ m_actions.copy.referenceOnly = new QAction(tr("Reference only"), ac );
+ QObject::connect(m_actions.copy.referenceOnly, SIGNAL(triggered()), displayWidget()->connectionsProxy(), SLOT(copyAnchorOnly()));
+ ac->addAction("copyReferenceOnly", m_actions.copy.referenceOnly);
+
+ m_actions.copy.referenceTextOnly = new QAction(tr("Text of reference"), ac);
+ QObject::connect(m_actions.copy.referenceTextOnly, SIGNAL(triggered()), displayWidget()->connectionsProxy(), SLOT(copyAnchorTextOnly()) );
+ ac->addAction("copyTextOfReference", m_actions.copy.referenceTextOnly);
+
+ m_actions.copy.referenceAndText = new QAction(tr("Reference with text"), ac);
+ QObject::connect(m_actions.copy.referenceAndText, SIGNAL(triggered()), displayWidget()->connectionsProxy(), SLOT(copyAnchorWithText()) );
+ ac->addAction( "copyReferenceWithText", m_actions.copy.referenceAndText);
+
+ m_actions.copy.chapter = new QAction(tr("Chapter"), ac);
+ QObject::connect(m_actions.copy.chapter, SIGNAL(triggered()), this, SLOT(copyDisplayedText()) );
+ ac->addAction("copyChapter", m_actions.copy.chapter);
+
+ m_actions.copy.selectedText = qobject_cast<QAction*>(ac->action("copySelectedText"));
+ Q_ASSERT(m_actions.copy.selectedText);
+
+ m_actions.save.referenceAndText = new QAction(tr("Reference with text"), ac );
+ QObject::connect(m_actions.save.referenceAndText, SIGNAL(triggered()), displayWidget()->connectionsProxy(), SLOT(saveAnchorWithText()) );
+ ac->addAction("saveReferenceWithText", m_actions.save.referenceAndText);
+
+ m_actions.save.chapterAsPlain = new QAction(tr("Chapter as plain text"), ac);
+ QObject::connect(m_actions.save.chapterAsPlain, SIGNAL(triggered()), this, SLOT(saveChapterPlain()) );
+ ac->addAction("saveChapterAsPlainText", m_actions.save.chapterAsPlain);
+
+ m_actions.save.chapterAsHTML = new QAction(tr("Chapter as HTML"), ac);
+ QObject::connect(m_actions.save.chapterAsHTML, SIGNAL(triggered()), this, SLOT(saveChapterHTML()) );
+ ac->addAction("saveChapterAsHTML", m_actions.save.chapterAsHTML);
+
+ m_actions.print.reference = new QAction(tr("Reference with text"), ac);
+ QObject::connect(m_actions.print.reference, SIGNAL(triggered()), this, SLOT(printAnchorWithText()) );
+ ac->addAction("saveReferenceWithText", m_actions.print.reference);
+
+ m_actions.print.chapter = new QAction(tr("Chapter"), ac);
+ QObject::connect(m_actions.print.chapter, SIGNAL(triggered()), this, SLOT(printAll()) );
+ ac->addAction("printChapter", m_actions.print.chapter);
+
+// CBTConfig::setupAccelSettings(CBTConfig::bibleWindow, ac);
+}
+
+void CBibleReadWindow::initConnections() {
+ CLexiconReadWindow::initConnections();
+}
+
+void CBibleReadWindow::initToolbars() {
+ CLexiconReadWindow::initToolbars();
+}
+
+void CBibleReadWindow::initView() {
+ CLexiconReadWindow::initView();
+
+ parentWidget()->installEventFilter( this );
+}
+
+/** Reimplementation. */
+void CBibleReadWindow::setupPopupMenu() {
+ popup()->setTitle(tr("Bible window"));
+ popup()->setIcon(CToolClass::getIconForModule(modules().first()) );
+ popup()->addAction(m_actions.findText);
+ popup()->addAction(m_actions.findStrongs);
+ popup()->addAction(m_actions.selectAll);
+
+ popup()->addSeparator();
+
+ m_actions.copyMenu = new QMenu(tr("Copy..."), popup());
+ m_actions.copyMenu->addAction(m_actions.copy.referenceOnly);
+ m_actions.copyMenu->addAction(m_actions.copy.referenceTextOnly);
+ m_actions.copyMenu->addAction(m_actions.copy.referenceAndText);
+ m_actions.copyMenu->addAction(m_actions.copy.chapter);
+
+ m_actions.copyMenu->addSeparator();
+
+ m_actions.copyMenu->addAction(m_actions.copy.selectedText);
+ popup()->addMenu(m_actions.copyMenu);
+
+ m_actions.saveMenu = new QMenu(tr("Save..."), popup());
+ m_actions.saveMenu->addAction(m_actions.save.referenceAndText);
+ m_actions.saveMenu->addAction(m_actions.save.chapterAsPlain);
+ m_actions.saveMenu->addAction(m_actions.save.chapterAsHTML);
+ // Save raw HTML action for debugging purposes
+ if (qApp->property("--debug").toBool()) {
+ QAction* debugAction = new QAction("Raw HTML", this);
+ QObject::connect(debugAction, SIGNAL(triggered()), this, SLOT(saveRawHTML()));
+ m_actions.saveMenu->addAction(debugAction);
+ } // end of Save Raw HTML
+ popup()->addMenu(m_actions.saveMenu);
+
+ m_actions.printMenu = new QMenu(tr("Print..."), popup());
+ m_actions.printMenu->addAction(m_actions.print.reference);
+ m_actions.printMenu->addAction(m_actions.print.chapter);
+ popup()->addMenu(m_actions.printMenu);
+}
+
+/** Reimplemented. */
+void CBibleReadWindow::updatePopupMenu() {
+ qWarning("CBibleReadWindow::updatePopupMenu()");
+
+ //enable the action depending on the supported module features
+// bool hasStrongs = false;
+// QList<CSwordModuleInfo*> mods = modules();
+// for (QList<CSwordModuleInfo*>::iterator it = mods.begin(); it != mods.end(); ++it) {
+// if ( (*it)->has( CSwordModuleInfo::strongNumbers ) ) {
+// hasStrongs = true;
+// break;
+// }
+// }
+//
+// m_actions.findStrongs->setEnabled( hasStrongs );
+ m_actions.findStrongs->setEnabled( displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma] != QString::null );
+
+
+ m_actions.copy.referenceOnly->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() );
+ m_actions.copy.referenceTextOnly->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() );
+ m_actions.copy.referenceAndText->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() );
+ m_actions.copy.selectedText->setEnabled( ((CReadDisplay*)displayWidget())->hasSelection() );
+
+ m_actions.save.referenceAndText->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() );
+
+ m_actions.print.reference->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() );
+}
+
+/** Moves to the next book. */
+void CBibleReadWindow::nextBook() {
+ if (verseKey()->next(CSwordVerseKey::UseBook)) {
+ keyChooser()->setKey(key());
+ }
+}
+
+/** Moves one book behind. */
+void CBibleReadWindow::previousBook() {
+ if (verseKey()->previous(CSwordVerseKey::UseBook)) {
+ keyChooser()->setKey(key());
+ }
+}
+
+/** Moves to the next book. */
+void CBibleReadWindow::nextChapter() {
+ if (verseKey()->next(CSwordVerseKey::UseChapter)) {
+ keyChooser()->setKey(key());
+ }
+}
+
+/** Moves one book behind. */
+void CBibleReadWindow::previousChapter() {
+ if (verseKey()->previous(CSwordVerseKey::UseChapter)) {
+ keyChooser()->setKey(key());
+ }
+}
+
+/** Moves to the next book. */
+void CBibleReadWindow::nextVerse() {
+ if (verseKey()->next(CSwordVerseKey::UseVerse)) {
+ keyChooser()->setKey(key());
+ }
+}
+
+/** Moves one book behind. */
+void CBibleReadWindow::previousVerse() {
+ if (verseKey()->previous(CSwordVerseKey::UseVerse)) {
+ keyChooser()->setKey(key());
+ }
+}
+
+/** rapper around key() to return the right type of key. */
+CSwordVerseKey* CBibleReadWindow::verseKey() {
+ CSwordVerseKey* k = dynamic_cast<CSwordVerseKey*>(CDisplayWindow::key());
+ Q_ASSERT(k);
+
+ return k;
+}
+
+/** Copies the current chapter into the clipboard. */
+void CBibleReadWindow::copyDisplayedText() {
+ CSwordVerseKey dummy(*verseKey());
+ dummy.Verse(1);
+
+ CSwordVerseKey vk(*verseKey());
+ vk.LowerBound(dummy);
+
+ CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(modules().first());
+ dummy.Verse(bible->verseCount(dummy.book(), dummy.Chapter()));
+ vk.UpperBound(dummy);
+
+ CExportManager mgr(tr("Copy chapter to clipboard ..."), false, tr("Copying"), filterOptions(), displayOptions());
+ mgr.copyKey(&vk, CExportManager::Text, true);
+}
+
+/** Saves the chapter as valid HTML page. */
+void CBibleReadWindow::saveChapterHTML() {
+ //saves the complete chapter to disk
+ CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(modules().first());
+ Q_ASSERT(bible);
+ if (!bible) //shouldn't happen
+ return;
+
+ CSwordVerseKey dummy(*verseKey());
+ dummy.Verse(1);
+
+ CSwordVerseKey vk(*verseKey());
+ vk.LowerBound(dummy);
+
+ dummy.Verse(bible->verseCount(dummy.book(), dummy.Chapter()));
+ vk.UpperBound(dummy);
+
+ CExportManager mgr(tr("Saving chapter ..."), true, tr("Saving"), filterOptions(), displayOptions());
+ mgr.saveKey(&vk, CExportManager::HTML, true);
+}
+
+/** Saves the chapter as valid HTML page. */
+void CBibleReadWindow::saveChapterPlain() {
+ //saves the complete chapter to disk
+
+ CSwordVerseKey vk(*verseKey());
+ CSwordVerseKey dummy(*verseKey());
+
+ dummy.Verse(1);
+ vk.LowerBound(dummy);
+
+ CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(modules().first());
+ dummy.Verse(bible->verseCount(dummy.book(), dummy.Chapter()));
+ vk.UpperBound(dummy);
+
+ CExportManager mgr(tr("Saving chapter ..."), true, tr("Saving"), filterOptions(),displayOptions());
+ mgr.saveKey(&vk, CExportManager::Text, true);
+}
+
+void CBibleReadWindow::reload(CSwordBackend::SetupChangedReason reason) {
+ CLexiconReadWindow::reload(reason);
+
+ if (m_modules.count() == 0) {
+ close();
+ return;
+ }
+
+ //refresh the book lists
+// qDebug("lang is %s",backend()->booknameLanguage().latin1());
+ verseKey()->setLocale( backend()->booknameLanguage().toLatin1() );
+ keyChooser()->refreshContent();
+
+// CBTConfig::setupAccelSettings(CBTConfig::readWindow, actionCollection()); //setup the predefined actions
+// CBTConfig::setupAccelSettings(CBTConfig::bibleWindow, actionCollection());
+}
+
+/** No descriptions */
+bool CBibleReadWindow::eventFilter( QObject* o, QEvent* e) {
+ const bool ret = CLexiconReadWindow::eventFilter(o,e);
+
+ // Q_ASSERT(o->inherits("CDisplayWindow"));
+ // qWarning("class: %s", o->className());
+ if (e && (e->type() == QEvent::FocusIn)) { //sync other windows to this active
+
+ /* This is a hack to work around a KHTML problem (similair to the Drag&Drop problem we had):
+ * If new HTML content is loaded from inside a kHTML event handler
+ * the widget's state will be confused, i.e. it's scrolling without having
+ * the mousebutton clicked.
+ *
+ * This is not really in a KHTML event handler but works anyway.
+ * Sometime KDE/Qt is hard to use ...
+ */
+ QTimer::singleShot(0, this, SLOT(syncWindows()));
+ }
+
+ return ret;
+}
+
+void CBibleReadWindow::lookupSwordKey( CSwordKey* newKey ) {
+ CLexiconReadWindow::lookupSwordKey(newKey);
+ syncWindows();
+}
+
+void CBibleReadWindow::syncWindows() {
+ foreach (QMdiSubWindow* subWindow, mdi()->subWindowList()) {
+ CDisplayWindow* w = dynamic_cast<CDisplayWindow*>(subWindow->widget());
+ if (w && w->syncAllowed()) {
+ w->lookupKey( key()->key() );
+ }
+ }
+}
diff --git a/src/frontend/displaywindow/cbiblereadwindow.h b/src/frontend/displaywindow/cbiblereadwindow.h
new file mode 100644
index 0000000..e044463
--- /dev/null
+++ b/src/frontend/displaywindow/cbiblereadwindow.h
@@ -0,0 +1,144 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CBIBLEREADWINDOW_H
+#define CBIBLEREADWINDOW_H
+
+//BibleTime includes
+#include "clexiconreadwindow.h"
+
+
+
+class CTransliterationButton;
+class CSwordKey;
+class CSwordVerseKey;
+
+class BtActionCollection;
+class QAction;
+class QMenu;
+
+class QObject;
+class QEvent;
+
+
+
+/**The read display window for Bibles.
+ *@author The BibleTime team
+ */
+
+class CBibleReadWindow : public CLexiconReadWindow {
+ Q_OBJECT
+public:
+ CBibleReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent);
+ virtual ~CBibleReadWindow();
+ /**
+ * Store the settings of this window in the given CProfileWindow object.
+ */
+ virtual void storeProfileSettings( Profile::CProfileWindow* const settings );
+ /**
+ * Store the settings of this window in the given profile window.
+ */
+ virtual void applyProfileSettings( Profile::CProfileWindow* const settings );
+ /**
+ * Reimplementation.
+ */
+ static void insertKeyboardActions( BtActionCollection* const a );
+
+protected:
+ virtual void initActions();
+ virtual void initToolbars();
+ virtual void initConnections();
+ virtual void initView();
+ /**
+ * Reimplementation.
+ */
+ virtual void setupPopupMenu();
+ /**
+ * Reimplemented.
+ */
+ virtual void updatePopupMenu();
+ /** Event filter.
+ * Reimplementation of the event filter to filter out events like focus in.
+ */
+ virtual bool eventFilter( QObject* o, QEvent* e);
+
+ struct {
+ QAction* selectAll;
+ QAction* findText;
+ QAction* findStrongs;
+
+ QMenu* copyMenu;
+ struct {
+ QAction* referenceOnly;
+ QAction* referenceTextOnly;
+ QAction* referenceAndText;
+ QAction* chapter;
+ QAction* selectedText;
+ }
+ copy;
+
+ QMenu* saveMenu;
+ struct {
+ QAction* referenceAndText;
+ QAction* chapterAsPlain;
+ QAction* chapterAsHTML;
+ }
+ save;
+
+ QMenu* printMenu;
+ struct {
+ QAction* reference;
+ QAction* chapter;
+ }
+ print;
+ }
+ m_actions;
+
+
+public slots:
+ void nextBook();
+ void previousBook();
+ void nextChapter();
+ void previousChapter();
+ void nextVerse();
+ void previousVerse();
+ /**
+ * Refreshes the content of this display window and the content of the keychooser.
+ */
+ virtual void reload(CSwordBackend::SetupChangedReason reason);
+
+protected slots: // Protected slots
+ /**
+ * Copies the current chapter into the clipboard.
+ */
+ void copyDisplayedText();
+ /**
+ * Saves the chapter as valid HTML page.
+ */
+ void saveChapterHTML();
+ /**
+ * Saves the chapter as valid HTML page.
+ */
+ void saveChapterPlain();
+ virtual void lookupSwordKey( CSwordKey* newKey );
+ void syncWindows();
+
+private:
+ friend class CCommentaryReadWindow;
+ /**
+ * Wrapper around key() to return the right type of key.
+ */
+ CSwordVerseKey* verseKey();
+
+ // CTransliterationButton* m_transliterationButton;
+};
+
+#endif
diff --git a/src/frontend/displaywindow/cbookreadwindow.cpp b/src/frontend/displaywindow/cbookreadwindow.cpp
new file mode 100644
index 0000000..657238f
--- /dev/null
+++ b/src/frontend/displaywindow/cbookreadwindow.cpp
@@ -0,0 +1,195 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#include "cbookreadwindow.h"
+#include "bttoolbarpopupaction.h"
+#include "btactioncollection.h"
+
+#include "cmodulechooserbar.h"
+#include "cbuttons.h"
+
+#include "backend/keys/cswordtreekey.h"
+
+#include "frontend/display/cdisplay.h"
+#include "frontend/keychooser/cbooktreechooser.h"
+#include "frontend/profile/cprofilewindow.h"
+#include "backend/config/cbtconfig.h"
+
+#include "util/ctoolclass.h"
+#include "util/cresmgr.h"
+
+#include <QSplitter>
+#include <QToolBar>
+#include <QMenu>
+#include <QAction>
+
+using namespace Profile;
+
+CBookReadWindow::CBookReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent) : CLexiconReadWindow(modules, parent) {}
+
+CBookReadWindow::~CBookReadWindow() {}
+
+void CBookReadWindow::applyProfileSettings( CProfileWindow* profileWindow )
+{
+ CLexiconReadWindow::applyProfileSettings(profileWindow);
+
+ const bool enable = static_cast<bool>( profileWindow->windowSettings() );
+ if (enable) {
+ m_treeAction->activate(QAction::Trigger);
+ }
+}
+
+void CBookReadWindow::storeProfileSettings( CProfileWindow* profileWindow )
+{
+ CLexiconReadWindow::storeProfileSettings(profileWindow);
+
+ //store information about our show tree structure button
+ profileWindow->setWindowSettings( static_cast<int>( m_treeAction->isChecked() ) );
+}
+
+void CBookReadWindow::initActions()
+{
+ CLexiconReadWindow::initActions();
+ BtActionCollection* ac = actionCollection();
+ //cleanup, not a clean oo-solution
+ Q_ASSERT(ac->action("nextEntry"));
+ Q_ASSERT(ac->action("previousEntry"));
+ ac->action("nextEntry")->setEnabled(false);
+ ac->action("previousEntry")->setEnabled(false);
+
+ m_treeAction = new QAction(
+ QIcon(CResMgr::displaywindows::bookWindow::toggleTree::icon),
+ tr("Toggle tree view"),
+ ac
+ );
+ m_treeAction->setCheckable(true);
+ m_treeAction->setShortcut(CResMgr::displaywindows::bookWindow::toggleTree::accel);
+ QObject::connect(m_treeAction, SIGNAL(triggered()), this, SLOT(treeToggled()) );
+ ac->addAction("toggleTree", m_treeAction);
+
+// CBTConfig::setupAccelSettings(CBTConfig::bookWindow, ac);
+}
+
+void CBookReadWindow::insertKeyboardActions( BtActionCollection* const a )
+{
+ QAction* qaction;
+
+ qaction = new QAction(
+ QIcon(CResMgr::displaywindows::bookWindow::toggleTree::icon),
+ tr("Toggle tree view"),
+ a
+ );
+ qaction->setCheckable(true);
+ qaction->setShortcut(CResMgr::displaywindows::bookWindow::toggleTree::accel);
+ a->addAction("toggleTree", qaction);
+
+ // new QAction(tr("Copy reference only"), KShortcut(0), a, "copyReferenceOnly");
+ qaction = new QAction(tr("Copy entry with text"), a);
+ a->addAction("copyEntryWithText", qaction);
+ // new QAction(tr("Copy selected text"), KShortcut(0), a, "copySelectedText");
+ qaction = new QAction(tr("Save entry as plain text"), a);
+ a->addAction("saveEntryAsPlainText", qaction);
+ qaction = new QAction(tr("Save entry as HTML"),a);
+ a->addAction("saveEntryAsHTML", qaction);
+ // new QAction(tr("Print reference only"), KShortcut(0), a, "printReferenceOnly");
+ qaction = new QAction(tr("Print entry with text"), a);
+ a->addAction("printEntryWithText", qaction);
+
+}
+
+/** No descriptions */
+void CBookReadWindow::initConnections()
+{
+ CLexiconReadWindow::initConnections();
+
+ connect(m_treeChooser, SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*)));
+ connect(m_treeChooser, SIGNAL(keyChanged(CSwordKey*)), keyChooser(), SLOT(updateKey(CSwordKey*)));
+ connect(keyChooser(), SIGNAL(keyChanged(CSwordKey*)), m_treeChooser, SLOT(updateKey(CSwordKey*)));
+}
+
+/** Init the view */
+void CBookReadWindow::initView()
+{
+ QSplitter* splitter = new QSplitter(this);
+
+ setMainToolBar( new QToolBar(this) );
+ addToolBar(mainToolBar());
+ //addDockWindow(mainToolBar());
+
+ m_treeChooser = new CBookTreeChooser(modules(), key(), splitter);
+ setDisplayWidget( CDisplay::createReadInstance(this, splitter) );
+
+ setKeyChooser( CKeyChooser::createInstance(modules(), key(), mainToolBar()) );
+
+ setModuleChooserBar( new CModuleChooserBar(modules(), modules().first()->type(), this) );
+ moduleChooserBar()->setButtonLimit(1);
+ addToolBar(moduleChooserBar());
+ //addDockWindow( moduleChooserBar() );
+
+ setButtonsToolBar( new QToolBar(this) );
+ //addDockWindow( buttonsToolBar() );
+ setDisplaySettingsButton( new CDisplaySettingsButton( &displayOptions(), &filterOptions(), modules(), buttonsToolBar()) );
+ addToolBar(buttonsToolBar());
+ m_treeChooser->hide();
+
+ //splitter->setResizeMode(m_treeChooser, QSplitter::Stretch);
+ setCentralWidget( splitter );
+ setWindowIcon(CToolClass::getIconForModule(modules().first()));
+}
+
+void CBookReadWindow::initToolbars()
+{
+ Q_ASSERT(m_treeAction);
+ Q_ASSERT(m_actions.backInHistory);
+
+ mainToolBar()->addAction(m_actions.backInHistory);
+ mainToolBar()->addAction(m_actions.forwardInHistory);
+
+ mainToolBar()->addWidget(keyChooser());
+
+ buttonsToolBar()->addAction(m_treeAction);
+ m_treeAction->setChecked(false);
+
+ buttonsToolBar()->addWidget(displaySettingsButton());
+
+ QAction* action = qobject_cast<QAction*>(actionCollection()->action(
+ CResMgr::displaywindows::general::search::actionName ));
+ if (action) {
+ buttonsToolBar()->addAction(action);
+ }
+
+ //#if KDE_VERSION_MINOR < 1
+ //action->plugAccel( accel() );
+ //#endif
+}
+
+/** Is called when the action was executed to toggle the tree view. */
+void CBookReadWindow::treeToggled()
+{
+ if (m_treeAction->isChecked()) {
+ m_treeChooser->show();
+ }
+ else {
+ m_treeChooser->hide();
+ }
+}
+
+/** Reimplementation to take care of the tree chooser. */
+void CBookReadWindow::modulesChanged()
+{
+ CLexiconReadWindow::modulesChanged();
+ m_treeChooser->setModules(modules());
+}
+
+void CBookReadWindow::setupPopupMenu()
+{
+ CLexiconReadWindow::setupPopupMenu();
+}
diff --git a/src/frontend/displaywindow/cbookreadwindow.h b/src/frontend/displaywindow/cbookreadwindow.h
new file mode 100644
index 0000000..eaa0c15
--- /dev/null
+++ b/src/frontend/displaywindow/cbookreadwindow.h
@@ -0,0 +1,69 @@
+/*********
+*
+* This file is part of BibleTime's BtActionCollection code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime BtActionCollection code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CBOOKREADWINDOW_H
+#define CBOOKREADWINDOW_H
+
+//BibleTime includes
+#include "clexiconreadwindow.h"
+
+
+class QAction;
+class CBookTreeChooser;
+class BtActionCollection;
+
+
+/**
+ * @author The BibleTime team
+ */
+class CBookReadWindow : public CLexiconReadWindow {
+ Q_OBJECT
+public:
+ static void insertKeyboardActions( BtActionCollection* const a );
+
+ CBookReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent);
+
+ virtual ~CBookReadWindow();
+ /**
+ * Store the settings of this window in the given CProfileWindow object.
+ */
+ virtual void storeProfileSettings( Profile::CProfileWindow* profileWindow );
+ /**
+ * Store the settings of this window in the given profile window.
+ */
+ virtual void applyProfileSettings( Profile::CProfileWindow* profileWindow );
+
+protected:
+ virtual void initActions();
+ virtual void initToolbars();
+ virtual void initConnections();
+ virtual void initView();
+
+ virtual void setupPopupMenu();
+
+ protected slots: // Protected slots
+ /**
+ * Reimplementation to take care of the tree chooser.
+ */
+ virtual void modulesChanged();
+
+private:
+ QAction* m_treeAction;
+ CBookTreeChooser* m_treeChooser;
+
+private slots: // Private slots
+ /**
+ * Is called when the action was executed to toggle the tree view.
+ */
+ void treeToggled();
+};
+
+#endif
diff --git a/src/frontend/displaywindow/cbuttons.cpp b/src/frontend/displaywindow/cbuttons.cpp
new file mode 100644
index 0000000..582e5de
--- /dev/null
+++ b/src/frontend/displaywindow/cbuttons.cpp
@@ -0,0 +1,191 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//BibleTime includes
+#include "cbuttons.h"
+
+#include "util/cresmgr.h"
+#include "util/cpointers.h"
+#include "util/directoryutil.h"
+
+//Qt includes
+#include <QString>
+#include <QToolTip>
+#include <QToolButton>
+#include <QHash>
+#include <QMenu>
+
+//KDE includes
+
+
+
+
+CDisplaySettingsButton::CDisplaySettingsButton(CSwordBackend::DisplayOptions *displaySettings, CSwordBackend::FilterOptions *moduleSettings, const QList<CSwordModuleInfo*>& useModules,QWidget *parent )
+: QToolButton(parent) {
+ // qWarning("CDisplaySettingsButton::CDisplaySettingsButton");
+ QToolButton::setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::displaySettings::icon));
+
+ m_displaySettings = displaySettings;
+ m_moduleSettings = moduleSettings;
+ m_modules = useModules;
+
+ m_popup = new QMenu(this);
+ setMenu(m_popup);
+ setPopupMode(QToolButton::InstantPopup);
+ setToolTip(tr("Display options"));
+
+ connect(m_popup, SIGNAL(triggered(QAction*)), this, SLOT(optionToggled(QAction*)));
+ populateMenu();
+}
+
+void CDisplaySettingsButton::reset(const QList<CSwordModuleInfo*>& useModules) {
+ m_modules = useModules;
+ populateMenu();
+ //disable the settings button if no options are available
+ if (!populateMenu()) {
+ setEnabled(false);
+ setToolTip(tr("Display settings: No options available"));
+ }
+ else {
+ setEnabled(true);
+ setToolTip(tr("Display settings"));
+ }
+}
+
+
+void CDisplaySettingsButton::optionToggled(QAction* /*action*/) {
+ qDebug("display settings option toggled");
+ //Take each Action and set the corresponding setting.
+ //Using QAction (QObject) property and OptionType enum is a dirty way to do this.
+ //See populateMenu().
+ foreach (QAction* act, m_popup->actions()) {
+ int optionType = act->property("OptionType").toInt();
+ bool checked = act->isChecked();
+ switch(optionType) {
+ case Linebreak:
+ m_displaySettings->lineBreaks = checked;
+ break;
+ case Versenum:
+ m_displaySettings->verseNumbers = checked;
+ break;
+ case Variant:
+ m_moduleSettings->textualVariants = checked;
+ break;
+ case Vowel:
+ m_moduleSettings->hebrewPoints = checked;
+ break;
+ case Accents:
+ m_moduleSettings->greekAccents = checked;
+ break;
+ case Cantillation:
+ m_moduleSettings->hebrewCantillation = checked;
+ break;
+ case Headings:
+ m_moduleSettings->headings = checked;
+ break;
+ case Morphseg:
+ m_moduleSettings->morphSegmentation = checked;
+ break;
+ case Xref:
+ m_moduleSettings->scriptureReferences = checked;
+ break;
+ case WordsofJ:
+ m_moduleSettings->redLetterWords = checked;
+ break;
+ }
+ }
+
+ emit sigChanged();
+}
+
+/** No descriptions */
+int CDisplaySettingsButton::populateMenu() {
+ int ret = 0;
+
+ m_popup->clear();
+
+ // See also optionToggled()
+
+ ret += addMenuEntry(tr("Use linebreaks after each verse"), Linebreak, &m_displaySettings->lineBreaks, (m_modules.first()->type() == CSwordModuleInfo::Bible));
+
+ //show the verse numbers option only for bible modules
+ ret += addMenuEntry(tr("Show verse numbers"), Versenum, &m_displaySettings->verseNumbers, (m_modules.first()->type() == CSwordModuleInfo::Bible));
+
+ ret += addMenuEntry(tr("Show headings"), Headings, &m_moduleSettings->headings,
+ isOptionAvailable(CSwordModuleInfo::headings));
+
+ ret += addMenuEntry(tr("Highlight words of Jesus"), WordsofJ, &m_moduleSettings->redLetterWords,
+ isOptionAvailable(CSwordModuleInfo::redLetterWords ));
+
+ ret += addMenuEntry(tr("Show Hebrew vowel points"), Vowel, &m_moduleSettings->hebrewPoints,
+ isOptionAvailable(CSwordModuleInfo::hebrewPoints ));
+
+ ret += addMenuEntry(tr("Show Hebrew cantillation marks"), Cantillation, &m_moduleSettings->hebrewCantillation,
+ isOptionAvailable(CSwordModuleInfo::hebrewCantillation ));
+
+ ret += addMenuEntry(tr("Show Greek accents"), Accents, &m_moduleSettings->greekAccents,
+ isOptionAvailable(CSwordModuleInfo::greekAccents ));
+
+ ret += addMenuEntry(tr("Use alternative textual variant"), Variant, &m_moduleSettings->textualVariants,
+ isOptionAvailable(CSwordModuleInfo::textualVariants ));
+
+ ret += addMenuEntry(tr("Show scripture cross-references"), Xref, &m_moduleSettings->scriptureReferences,
+ isOptionAvailable(CSwordModuleInfo::scriptureReferences ));
+
+ ret += addMenuEntry(tr("Show morph segmentation"), Morphseg, &m_moduleSettings->morphSegmentation,
+ isOptionAvailable(CSwordModuleInfo::morphSegmentation ));
+
+ return ret;
+}
+
+/** Adds an entry to m_popup. */
+int CDisplaySettingsButton::addMenuEntry( const QString name, OptionType type, const int* option, const bool available) {
+ int ret = 0;
+
+ if (available) {
+ QAction* a = m_popup->addAction(name);
+ //see optionToggled()
+ a->setProperty("OptionType", type);
+ a->setCheckable(true);
+ a->setChecked(*option);
+ ret = 1;
+ }
+
+ return ret;
+}
+
+bool CDisplaySettingsButton::isOptionAvailable( const CSwordModuleInfo::FilterTypes option ) {
+ bool ret = false;
+ QList<CSwordModuleInfo*>::iterator end_it = m_modules.end();
+ for (QList<CSwordModuleInfo*>::iterator it(m_modules.begin()); it != end_it; ++it) {
+ ret = ret || (*it)->has(option);
+ }
+ return ret;
+}
+
+/** Returns the number of usable menu items in the settings menu. */
+int CDisplaySettingsButton::menuItemCount() {
+ return m_popup->actions().count();
+}
+
+/** Sets the item at position pos to the state given as 2nd paramter. */
+void CDisplaySettingsButton::setItemStatus( const int index, const bool checked ) {
+ QAction* action = m_popup->actions().at(index);
+ action->setChecked(checked);
+}
+
+/** Returns the status of the item at position "index" */
+bool CDisplaySettingsButton::itemStatus( const int index ) {
+ return m_popup->actions().at(index)->isChecked();
+}
+
+/** Sets the status to changed. The signal changed will be emitted. */
+void CDisplaySettingsButton::setChanged() {
+ emit sigChanged();
+}
diff --git a/src/frontend/displaywindow/cbuttons.h b/src/frontend/displaywindow/cbuttons.h
new file mode 100644
index 0000000..6d94c53
--- /dev/null
+++ b/src/frontend/displaywindow/cbuttons.h
@@ -0,0 +1,77 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CBUTTONS_H
+#define CBUTTONS_H
+
+//BibleTime includes
+#include "backend/managers/cswordbackend.h"
+class CSwordModuleInfo;
+
+//QT includes
+#include <QHash>
+#include <QToolButton>
+
+class QMenu;
+
+/** This class manages the display options of the selected modules.
+ * @author The BibleTime team
+ */
+class CDisplaySettingsButton : public QToolButton {
+ Q_OBJECT
+public:
+
+ CDisplaySettingsButton(CSwordBackend::DisplayOptions *displaySettings, CSwordBackend::FilterOptions *settings, const QList<CSwordModuleInfo*>& useModules, QWidget *parent=0);
+ void reset(const QList<CSwordModuleInfo*>& useModules);
+ /**
+ * Sets the item at position pos to the satet given as 2nd paramter.
+ */
+ void setItemStatus( const int pos, const bool checked );
+ /**
+ * Returns the number of usable menu items in the setttings menu.
+ */
+ int menuItemCount();
+ /**
+ * Returns the status of the item at position "index"
+ */
+ bool itemStatus( const int index );
+ /**
+ * Sets the status to changed. The signal changed will be emitted.
+ */
+ void setChanged();
+
+signals:
+ void sigChanged(void);
+
+protected slots:
+ void optionToggled(QAction* action);
+
+protected:
+
+ /** This enum marks the option types for a display. Used internally.*/
+ enum OptionType {Linebreak, Versenum, Headings, WordsofJ, Vowel, Cantillation, Accents,
+ Variant, Xref, Morphseg};
+
+ CSwordBackend::FilterOptions* m_moduleSettings;
+ CSwordBackend::DisplayOptions* m_displaySettings;
+ CSwordBackend::FilterOptions m_available;
+ QList<CSwordModuleInfo*> m_modules;
+
+ QHash<QString, int> m_dict;
+
+ QMenu* m_popup;
+
+ int populateMenu();
+ bool isOptionAvailable( const CSwordModuleInfo::FilterTypes option);
+ int addMenuEntry( const QString name, OptionType type, const int* option, const bool available);
+};
+
+#endif
diff --git a/src/frontend/displaywindow/ccommentaryreadwindow.cpp b/src/frontend/displaywindow/ccommentaryreadwindow.cpp
new file mode 100644
index 0000000..9228c2d
--- /dev/null
+++ b/src/frontend/displaywindow/ccommentaryreadwindow.cpp
@@ -0,0 +1,198 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//BibleTime includes
+#include "ccommentaryreadwindow.h"
+#include "btactioncollection.h"
+
+#include "frontend/profile/cprofilewindow.h"
+#include "backend/config/cbtconfig.h"
+#include "frontend/keychooser/ckeychooser.h"
+#include "frontend/display/cdisplay.h"
+#include "frontend/display/creaddisplay.h"
+
+#include "backend/keys/cswordversekey.h"
+
+#include "util/ctoolclass.h"
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+
+#include <QMenu>
+#include <QAction>
+#include <QIcon>
+#include <QToolBar>
+
+using namespace Profile;
+
+CCommentaryReadWindow::CCommentaryReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent) : CLexiconReadWindow(modules, parent) {}
+
+void CCommentaryReadWindow::insertKeyboardActions( BtActionCollection* const a ) {
+
+ QAction* qaction;
+
+ qaction = new QAction(tr("Next book"), a);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextBook::accel);
+ a->addAction("nextBook", qaction);
+
+ qaction = new QAction(tr("Previous book"), a);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousBook::accel);
+ a->addAction( "previousBook", qaction);
+
+ qaction = new QAction(tr("Next chapter"), a);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextChapter::accel);
+ a->addAction("nextChapter", qaction);
+
+ qaction = new QAction(tr("Previous chapter"), a);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousChapter::accel);
+ a->addAction("previousChapter", qaction);
+
+ qaction = new QAction(tr("Next verse"), a);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextVerse::accel);
+ a->addAction("nextVerse", qaction);
+
+ qaction = new QAction(tr("Previous verse"), a);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousVerse::accel);
+ a->addAction("previousVerse", qaction);
+
+}
+
+void CCommentaryReadWindow::applyProfileSettings( CProfileWindow* profileWindow ) {
+ CLexiconReadWindow::applyProfileSettings(profileWindow);
+ if (profileWindow->windowSettings()) {
+ m_syncButton->setChecked(true);
+ }
+}
+
+void CCommentaryReadWindow::storeProfileSettings( CProfileWindow* profileWindow ) {
+ CLexiconReadWindow::storeProfileSettings(profileWindow);
+ profileWindow->setWindowSettings( m_syncButton->isChecked() );
+}
+
+void CCommentaryReadWindow::initToolbars() {
+ CLexiconReadWindow::initToolbars();
+
+ m_syncButton = new QAction(
+ QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::commentaryWindow::syncWindow::icon)),
+ tr("Synchronize"),
+ actionCollection()
+ );
+ m_syncButton->setCheckable(true);
+ m_syncButton->setShortcut(CResMgr::displaywindows::commentaryWindow::syncWindow::accel);
+ m_syncButton->setToolTip(tr("Synchronize the displayed entry of this work with the active Bible window"));
+ actionCollection()->addAction(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName, m_syncButton);
+ buttonsToolBar()->addAction(m_syncButton);
+}
+
+/** Reimplementation to handle the keychooser refresh. */
+void CCommentaryReadWindow::reload(CSwordBackend::SetupChangedReason reason) {
+ CLexiconReadWindow::reload(reason);
+
+ //refresh the book lists
+ verseKey()->setLocale( backend()->booknameLanguage().toLatin1() );
+ keyChooser()->refreshContent();
+}
+
+/** rapper around key() to return the right type of key. */
+CSwordVerseKey* CCommentaryReadWindow::verseKey() {
+ CSwordVerseKey* k = dynamic_cast<CSwordVerseKey*>(CDisplayWindow::key());
+ Q_ASSERT(k);
+ return k;
+}
+
+void CCommentaryReadWindow::initActions() {
+ CLexiconReadWindow::initActions(); //make sure the predefined actions are available
+
+ BtActionCollection* ac = actionCollection();
+
+ //cleanup, not a clean oo-solution
+ ac->action("nextEntry")->setEnabled(false);
+ ac->action("previousEntry")->setEnabled(false);
+
+ QAction* qaction;
+
+ qaction = new QAction(tr("Next book"), ac);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextBook::accel);
+ QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextBook()) );
+ ac->addAction("nextBook", qaction);
+
+ qaction = new QAction(tr("Previous book"), ac);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousBook::accel);
+ QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousBook()) );
+ ac->addAction("previousBook", qaction);
+
+ qaction = new QAction(tr("Next chapter"), ac);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextChapter::accel);
+ QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextChapter()) );
+ ac->addAction("nextChapter", qaction);
+
+ qaction = new QAction(tr("Previous chapter"), ac);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousChapter::accel);
+ QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousChapter()) );
+ ac->addAction("previousChapter", qaction);
+
+ qaction = new QAction(tr("Next verse"), ac);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextVerse::accel);
+ QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextVerse()) );
+ ac->addAction("nextVerse", qaction);
+
+ qaction = new QAction(tr("Previous verse"), ac);
+ qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousVerse::accel);
+ QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousVerse()) );
+ ac->addAction("previousVerse", qaction);
+
+// CBTConfig::setupAccelSettings(CBTConfig::commentaryWindow, actionCollection());
+}
+
+/** Moves to the next book. */
+void CCommentaryReadWindow::nextBook() {
+ if (verseKey()->next(CSwordVerseKey::UseBook))
+ keyChooser()->setKey(key());
+}
+
+/** Moves one book behind. */
+void CCommentaryReadWindow::previousBook() {
+ if (verseKey()->previous(CSwordVerseKey::UseBook))
+ keyChooser()->setKey(key());
+}
+
+/** Moves to the next book. */
+void CCommentaryReadWindow::nextChapter() {
+ if (verseKey()->next(CSwordVerseKey::UseChapter))
+ keyChooser()->setKey(key());
+}
+
+/** Moves one book behind. */
+void CCommentaryReadWindow::previousChapter() {
+ if (verseKey()->previous(CSwordVerseKey::UseChapter))
+ keyChooser()->setKey(key());
+}
+
+/** Moves to the next book. */
+void CCommentaryReadWindow::nextVerse() {
+ if (verseKey()->next(CSwordVerseKey::UseVerse))
+ keyChooser()->setKey(key());
+}
+
+/** Moves one book behind. */
+void CCommentaryReadWindow::previousVerse() {
+ if (verseKey()->previous(CSwordVerseKey::UseVerse))
+ keyChooser()->setKey(key());
+}
+
+bool CCommentaryReadWindow::syncAllowed() const {
+ return m_syncButton->isChecked();
+}
+
+
+/*!
+ \fn CCommentaryReadWindow::setupPopupMenu()
+ */
+void CCommentaryReadWindow::setupPopupMenu() {
+ CLexiconReadWindow::setupPopupMenu();
+}
diff --git a/src/frontend/displaywindow/ccommentaryreadwindow.h b/src/frontend/displaywindow/ccommentaryreadwindow.h
new file mode 100644
index 0000000..1bac735
--- /dev/null
+++ b/src/frontend/displaywindow/ccommentaryreadwindow.h
@@ -0,0 +1,72 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CCOMMENTARYREADWINDOW_H
+#define CCOMMENTARYREADWINDOW_H
+
+//BibleTime includes
+#include "cbiblereadwindow.h"
+
+//Qt includes
+//#include <qwidget.h>
+
+
+class QAction;
+class CSwordVerseKey;
+class BtActionCollection;
+
+/**
+ *@author The BibleTime team
+ */
+
+class CCommentaryReadWindow : public CLexiconReadWindow {
+ Q_OBJECT
+public:
+ /**
+ * Reimplementation.
+ */
+ static void insertKeyboardActions( BtActionCollection* const a );
+
+ CCommentaryReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent);
+ /**
+ * Store the settings of this window in the given CProfileWindow object.
+ */
+ virtual void storeProfileSettings( Profile::CProfileWindow* profileWindow );
+ /**
+ * Store the settings of this window in the given profile window.
+ */
+ virtual void applyProfileSettings( Profile::CProfileWindow* profileWindow );
+ virtual bool syncAllowed() const;
+
+public slots: // Public slots
+ void nextBook();
+ void previousBook();
+ void nextChapter();
+ void previousChapter();
+ void nextVerse();
+ void previousVerse();
+ /**
+ * Reimplementation to handle the keychooser refresh.
+ */
+ virtual void reload(CSwordBackend::SetupChangedReason);
+
+protected:
+ virtual void initActions();
+ virtual void initToolbars();
+
+private:
+ QAction* m_syncButton;
+ CSwordVerseKey* verseKey();
+protected:
+ virtual void setupPopupMenu();
+};
+
+#endif
diff --git a/src/frontend/displaywindow/cdisplaywindow.cpp b/src/frontend/displaywindow/cdisplaywindow.cpp
new file mode 100644
index 0000000..59fccab
--- /dev/null
+++ b/src/frontend/displaywindow/cdisplaywindow.cpp
@@ -0,0 +1,497 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cdisplaywindow.h"
+#include "bttoolbarpopupaction.h"
+#include "btactioncollection.h"
+
+#include "cmodulechooserbar.h"
+#include "cbuttons.h"
+#include "backend/keys/cswordkey.h"
+#include "frontend/keychooser/ckeychooser.h"
+#include "frontend/keychooser/bthistory.h"
+#include "frontend/display/cdisplay.h"
+#include "frontend/cmdiarea.h"
+#include "frontend/profile/cprofilewindow.h"
+#include "backend/config/cbtconfig.h"
+#include "frontend/searchdialog/csearchdialog.h"
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+
+#include <QWidget>
+#include <QCloseEvent>
+#include <QStringList>
+#include <QDebug>
+#include <QMenu>
+
+using namespace Profile;
+
+CDisplayWindow::CDisplayWindow(QList<CSwordModuleInfo*> modules, CMDIArea *parent)
+ : QMainWindow(parent),
+ m_mdi(parent),
+ m_filterOptions(),
+ m_displayOptions(),
+ m_displaySettingsButton(0),
+ m_keyChooser(0),
+ m_swordKey(0),
+ m_isReady(false),
+ m_moduleChooserBar(0),
+ m_mainToolBar(0),
+ m_popupMenu(0),
+ m_displayWidget(0)
+{
+ qDebug("CDisplayWindow::CDisplayWindow");
+ setAttribute(Qt::WA_DeleteOnClose); //we want to destroy this window when it is closed
+ parent->addSubWindow(this);
+ m_actionCollection = new BtActionCollection(this);
+ setModules(modules);
+
+ // Connect this to the backend module list changes
+ connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), SLOT(reload(CSwordBackend::SetupChangedReason)));
+ //KMainWindow::setAttribute(Qt::WA_DeleteOnClose); //what about QMdiSubWindow?
+}
+
+CDisplayWindow::~CDisplayWindow() {
+ delete m_swordKey;
+ m_swordKey = 0;
+}
+
+CMDIArea* CDisplayWindow::mdi() const {
+ return m_mdi;
+}
+
+/** Returns the right window caption. */
+const QString CDisplayWindow::windowCaption() {
+ if (!m_modules.count()) {
+ return QString::null;
+ }
+
+ return QString(key()->key()).append(" (").append(m_modules.join(" | ")).append(")");
+}
+
+/** Returns the used modules as a QPtrList */
+QList<CSwordModuleInfo*> CDisplayWindow::modules() {
+ QList<CSwordModuleInfo*> mods;
+
+ for (QStringList::iterator it = m_modules.begin(); it != m_modules.end(); ++it) {
+ Q_ASSERT(backend()->findModuleByName(*it));
+ if (CSwordModuleInfo* m = backend()->findModuleByName(*it)) {
+ mods.append(m);
+ }
+ }
+
+ return mods;
+}
+
+/** Set the window caption. */
+void CDisplayWindow::setCaption( const QString& ) {
+ QWidget::setWindowTitle( windowCaption() );
+ m_mdi->emitWindowCaptionChanged();
+}
+
+void CDisplayWindow::insertKeyboardActions( BtActionCollection* a ) {
+ qDebug() << "CDisplayWindow::insertKeyboardActions: ac: " << a;
+
+ QAction* actn = new QAction(QIcon(), tr("Zoom in"), 0);
+ actn->setShortcut(QKeySequence::ZoomIn);
+ a->addAction("zoomIn", actn);
+ //a->addAction(KStandardAction::ZoomIn, "zoomIn", 0, 0);
+ actn = new QAction(QIcon(), tr("Zoom out"), 0);
+ actn->setShortcut(QKeySequence::ZoomOut);
+ a->addAction("zoomIn", actn);
+ //a->addAction(KStandardAction::ZoomOut, "zoomOut", 0, 0);
+ actn = new QAction(QIcon(), tr("Close"), 0);
+ actn->setShortcut(QKeySequence::Close);
+ a->addAction("closeWindow", actn);
+ //a->addAction(KStandardAction::Close, "closeWindow", 0, 0);
+ actn = new QAction(QIcon(), tr("Select all"), 0);
+ actn->setShortcut(QKeySequence::SelectAll);
+ a->addAction("selectAll", actn);
+ //a->addAction(KStandardAction::SelectAll, "selectAll", 0, 0);
+ actn = new QAction(QIcon(), tr("Copy"), 0);
+ actn->setShortcut(QKeySequence::Copy);
+ a->addAction("copySelectedText", actn);
+ //a->addAction(KStandardAction::Copy, "copySelectedText", 0, 0);
+ actn = new QAction(QIcon(), tr("Find..."), 0);
+ actn->setShortcut(QKeySequence::Find);
+ a->addAction("findText", actn);
+ //a->addAction(KStandardAction::Find, "findText", 0, 0);
+
+ BtToolBarPopupAction* action = new BtToolBarPopupAction(
+ QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::general::backInHistory::icon)),
+ tr("Back in history"),
+ a
+ );
+ action->setShortcut(CResMgr::displaywindows::general::backInHistory::accel);
+ a->addAction(CResMgr::displaywindows::general::backInHistory::actionName, action);
+
+ action = new BtToolBarPopupAction(
+ QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::general::forwardInHistory::icon)),
+ tr("Forward in history"),
+ a
+ );
+ action->setShortcut(CResMgr::displaywindows::general::forwardInHistory::accel);
+ a->addAction(CResMgr::displaywindows::general::forwardInHistory::actionName, action);
+}
+
+void CDisplayWindow::initActions()
+{
+ qDebug("CDisplayWindow::initActions");
+
+ BtActionCollection* ac = actionCollection();
+
+ QAction* kaction = new QAction(
+ QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::general::search::icon)),
+ tr("Open the search dialog with the works of this window"),
+ ac
+ );
+ kaction->setShortcut(CResMgr::displaywindows::general::search::accel);
+ QObject::connect(kaction, SIGNAL(triggered()), this, SLOT(slotSearchInModules()));
+ ac->addAction(CResMgr::displaywindows::general::search::actionName, kaction);
+
+ CDisplayConnections* conn = displayWidget()->connectionsProxy();
+
+ QAction* actn = new QAction(QIcon(), tr("Zoom in"), ac);
+ actn->setShortcut(QKeySequence::ZoomIn);
+ QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(zoomIn()));
+ ac->addAction("zoomIn", actn);
+ addAction(actn);
+ //a->addAction(KStandardAction::ZoomIn, "zoomIn", 0, 0);
+ actn = new QAction(QIcon(), tr("Zoom out"), ac);
+ actn->setShortcut(QKeySequence::ZoomOut);
+ QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(zoomOut()));
+ ac->addAction("zoomOut", actn);
+ addAction(actn);
+ //a->addAction(KStandardAction::ZoomOut, "zoomOut", 0, 0);
+ actn = new QAction(QIcon(), tr("Close"), ac);
+ actn->setShortcut(QKeySequence::Close);
+ QObject::connect(actn, SIGNAL(triggered()), this, SLOT(close()));
+ ac->addAction("closeWindow", actn);
+ addAction(actn);
+ //a->addAction(KStandardAction::Close, "closeWindow", 0, 0);
+ actn = new QAction(QIcon(), tr("Select all"), ac);
+ actn->setShortcut(QKeySequence::SelectAll);
+ QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(selectAll()));
+ ac->addAction("selectAll", actn);
+ addAction(actn);
+ //a->addAction(KStandardAction::SelectAll, "selectAll", 0, 0);
+ actn = new QAction(QIcon(), tr("Copy"), ac);
+ actn->setShortcut(QKeySequence::Copy);
+ QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(copySelection()));
+ ac->addAction("copySelectedText", actn);
+ addAction(actn);
+ //a->addAction(KStandardAction::Copy, "copySelectedText", 0, 0);
+ actn = new QAction(QIcon(), tr("Find..."), ac);
+ actn->setShortcut(QKeySequence::Find);
+ QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(openFindTextDialog()));
+ ac->addAction("findText", actn);
+ addAction(actn);
+ //a->addAction(KStandardAction::Find, "findText", 0, 0);
+
+ BtToolBarPopupAction* popupaction = new BtToolBarPopupAction(
+ QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::general::backInHistory::icon)),
+ tr("Back in history"),
+ ac
+ );
+ bool ok = QObject::connect(popupaction, SIGNAL(triggered()), keyChooser()->history(), SLOT(back()));
+ Q_ASSERT(ok);
+ ac->addAction(CResMgr::displaywindows::general::backInHistory::actionName, popupaction);
+
+ popupaction = new BtToolBarPopupAction(
+ QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::general::forwardInHistory::icon)),
+ tr("Forward in history"),
+ ac
+ );
+ ok = QObject::connect(popupaction, SIGNAL(triggered()), keyChooser()->history(), SLOT(fw()) );
+ Q_ASSERT(ok);
+ ac->addAction(CResMgr::displaywindows::general::forwardInHistory::actionName, popupaction);
+
+}
+
+/** Refresh the settings of this window. */
+void CDisplayWindow::reload(CSwordBackend::SetupChangedReason) {
+ //first make sure all used Sword modules are still present
+ QMutableStringListIterator it(m_modules);
+ while (it.hasNext()) {
+ if (!backend()->findModuleByName(it.next())) {
+ it.remove();
+ }
+ }
+
+ if (m_modules.count() == 0){
+ close();
+ return;
+ }
+
+ if (keyChooser()) keyChooser()->setModules( modules(), false );
+
+ if (m_moduleChooserBar) { //necessary for edit windows which have now chooser bar
+ m_moduleChooserBar->setModules(modules());
+ }
+ modulesChanged();
+ lookup();
+}
+
+/** Returns the filter options used by this window. */
+CSwordBackend::FilterOptions& CDisplayWindow::filterOptions() {
+ return m_filterOptions;
+}
+
+/** Returns the display options used by this display window. */
+CSwordBackend::DisplayOptions& CDisplayWindow::displayOptions() {
+ return m_displayOptions;
+}
+
+/** Sets the new display options for this window. */
+void CDisplayWindow::setDisplayOptions( const CSwordBackend::DisplayOptions& displayOptions ) {
+ m_displayOptions = displayOptions;
+}
+
+/** Sets the new filter options of this window. */
+void CDisplayWindow::setFilterOptions( CSwordBackend::FilterOptions& filterOptions ) {
+ m_filterOptions = filterOptions;
+}
+
+/** Returns true if the widget is ready for use. */
+bool CDisplayWindow::isReady() const {
+ return m_isReady;
+}
+
+/** Set the ready status */
+void CDisplayWindow::setReady( const bool& ready ) {
+ m_isReady = ready;
+}
+
+/** Returns true if the window may be closed. */
+bool CDisplayWindow::queryClose() {
+ return true;
+}
+
+/** Returns the keychooser widget of this display window. */
+CKeyChooser* CDisplayWindow::keyChooser() const {
+ return m_keyChooser;
+}
+
+/** Sets the keychooser widget for this display window. */
+void CDisplayWindow::setKeyChooser( CKeyChooser* ck ) {
+ m_keyChooser = ck;
+}
+
+/** Returns the key of this display window. */
+CSwordKey* CDisplayWindow::key() const {
+ Q_ASSERT( m_swordKey );
+ return m_swordKey;
+}
+
+/** Sets the new sword key. */
+void CDisplayWindow::setKey( CSwordKey* key ) {
+ Q_ASSERT( key );
+ m_swordKey = key;
+}
+
+void CDisplayWindow::modulesChanged() {
+ if (moduleChooserBar()) { //necessary for write windows
+ setModules( m_moduleChooserBar->getModuleList() );
+ }
+
+ if (!modules().count()) {
+ close();
+ }
+ else {
+ if (displaySettingsButton()) {
+ displaySettingsButton()->reset(modules());
+ }
+
+ key()->module(modules().first());
+ keyChooser()->setModules(modules());
+ }
+}
+
+/** Returns the module chooser bar. */
+CModuleChooserBar* CDisplayWindow::moduleChooserBar() const {
+ return m_moduleChooserBar;
+}
+
+/** Sets the module chooser bar. */
+void CDisplayWindow::setModuleChooserBar( CModuleChooserBar* bar ) {
+ if (m_moduleChooserBar) {
+ disconnect(m_moduleChooserBar, SIGNAL(sigChanged()), this, SLOT(modulesChanged()));
+ }
+
+ //if a new bar should be set!
+ if (bar) {
+ m_moduleChooserBar = bar;
+ connect(bar, SIGNAL(sigChanged()), SLOT(modulesChanged()));
+ }
+}
+
+/** Sets the modules. */
+void CDisplayWindow::setModules( const QList<CSwordModuleInfo*>& newModules ) {
+ qDebug("CDisplayWindow::setModules");
+ m_modules.clear();
+
+ foreach (CSwordModuleInfo* mod, newModules) {
+ m_modules.append(mod->name());
+ }
+}
+
+/** Initialize the window. Call this method from the outside, because calling this in the constructor is not possible! */
+bool CDisplayWindow::init() {
+ qDebug("CDisplayWindow::init");
+ initView();
+ setMinimumSize( 100,100 );
+
+ setCaption(windowCaption());
+ //setup focus stuff.
+ setFocusPolicy(Qt::ClickFocus);
+ parentWidget()->setFocusPolicy(Qt::ClickFocus);
+ initActions();
+ initToolbars();
+ initConnections();
+ setupPopupMenu();
+
+ m_filterOptions = CBTConfig::getFilterOptionDefaults();
+ m_displayOptions = CBTConfig::getDisplayOptionDefaults();
+ if (displaySettingsButton()) {
+ displaySettingsButton()->reset(modules());
+ }
+
+ setReady(true);
+ return true;
+}
+
+/** Returns the main toolbar. */
+QToolBar* CDisplayWindow::mainToolBar() const {
+ return m_mainToolBar;
+}
+
+/** Returns the main toolbar. */
+QToolBar* CDisplayWindow::buttonsToolBar() const {
+ return m_buttonsToolBar;
+}
+
+/** Sets the main toolbar. */
+void CDisplayWindow::setMainToolBar( QToolBar* bar ) {
+ m_mainToolBar = bar;
+}
+
+/** Sets the main toolbar. */
+void CDisplayWindow::setButtonsToolBar( QToolBar* bar ) {
+ m_buttonsToolBar = bar;
+}
+
+/** Returns the display settings button */
+CDisplaySettingsButton* CDisplayWindow::displaySettingsButton() const {
+ return m_displaySettingsButton;
+}
+
+/** Sets the display settings button. */
+void CDisplayWindow::setDisplaySettingsButton( CDisplaySettingsButton* button ) {
+ if (m_displaySettingsButton)
+ disconnect(m_displaySettingsButton, SIGNAL( sigChanged() ),this, SLOT(lookup() ));
+
+ m_displaySettingsButton = button;
+ connect(m_displaySettingsButton, SIGNAL(sigChanged()),this, SLOT(lookup()));
+}
+
+/** Lookup the current key. Used to refresh the display. */
+void CDisplayWindow::lookup() {
+ lookupSwordKey( key() );
+}
+
+void CDisplayWindow::lookupModKey( const QString& moduleName, const QString& keyName ) {
+ if (!isReady()) {
+ return;
+ }
+
+ CSwordModuleInfo* m = backend()->findModuleByName(moduleName);
+ Q_ASSERT(m);
+ if (!m) {
+ return;
+ }
+
+ //ToDo: check for containsRef compat
+ if (m && modules().contains(m)) {
+ key()->key(keyName);
+ keyChooser()->setKey(key()); //the key chooser does send an update signal
+ }
+ else { //given module not displayed in this window
+ //if the module is displayed in another display window we assume a wrong drop
+ //create a new window for the given module
+ QList<CSwordModuleInfo*> mList;
+ mList.append(m);
+ mdi()->emitCreateDisplayWindow(mList, keyName);
+ }
+}
+
+void CDisplayWindow::lookupKey( const QString& keyName ) {
+ /* This function is called for example after a bookmark was dropped on this window
+ */
+ Q_ASSERT(modules().first());
+
+ //qDebug("CDisplayWindow::lookup: %s", keyName.latin1());
+ lookupModKey(modules().first()->name(), keyName);
+}
+
+/** Update the status of the popup menu entries. */
+void CDisplayWindow::updatePopupMenu() {}
+
+
+///** Returns the installed popup menu. */
+QMenu* CDisplayWindow::popup() {
+ // qWarning("CReadWindow::popup()");
+ if (!m_popupMenu) {
+ m_popupMenu = new QMenu(this);
+ connect(m_popupMenu, SIGNAL(aboutToShow()), this, SLOT(updatePopupMenu()));
+ if (displayWidget()) {
+ displayWidget()->installPopup(m_popupMenu);
+ }
+ /* else {
+ qWarning("CDisplayWindow:: can't instal popup menu");
+ }*/
+ }
+ return m_popupMenu;
+}
+
+/** Returns the display widget used by this implementation of CDisplayWindow. */
+CDisplay* CDisplayWindow::displayWidget() const {
+ Q_ASSERT(m_displayWidget);
+ return m_displayWidget;
+}
+
+/** Sets the display widget used by this display window. */
+void CDisplayWindow::setDisplayWidget( CDisplay* newDisplay ) {
+ m_displayWidget = newDisplay;
+}
+
+void CDisplayWindow::closeEvent(QCloseEvent* e) {
+ if (!queryClose()) {
+ e->ignore();
+ }
+ else {
+ e->accept();
+ }
+}
+
+void CDisplayWindow::slotSearchInModules() {
+ Search::CSearchDialog::openDialog(modules());
+}
+
+void CDisplayWindow::printAll() {
+ m_displayWidget->connectionsProxy()->printAll( m_displayOptions, m_filterOptions);
+}
+
+void CDisplayWindow::printAnchorWithText() {
+ m_displayWidget->connectionsProxy()->printAnchorWithText( m_displayOptions, m_filterOptions);
+}
+
+BtActionCollection* CDisplayWindow::actionCollection()
+{
+ return m_actionCollection;
+}
diff --git a/src/frontend/displaywindow/cdisplaywindow.h b/src/frontend/displaywindow/cdisplaywindow.h
new file mode 100644
index 0000000..1eb7d06
--- /dev/null
+++ b/src/frontend/displaywindow/cdisplaywindow.h
@@ -0,0 +1,264 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CDISPLAYWINDOW_H
+#define CDISPLAYWINDOW_H
+
+//BibleTime includes
+#include "util/cpointers.h"
+
+class CSwordModuleInfo;
+#include "backend/managers/cswordbackend.h"
+
+#include "frontend/profile/cprofilewindow.h"
+
+//Qt includes
+#include <QStringList>
+#include <QMainWindow>
+
+//Forward declarations
+class CMDIArea;
+class CReadWindow;
+class CWriteWindow;
+class CDisplaySettingsButton;
+class CDisplay;
+class CKeyChooser;
+class CModuleChooserBar;
+class QCloseEvent;
+
+class QToolBar;
+class QCloseEvent;
+class QMenu;
+class BtActionCollection;
+
+/** The base class for all display windows of BibleTime.
+ * @author The BibleTime team
+ */
+
+class CDisplayWindow : public QMainWindow, public CPointers {
+ Q_OBJECT
+public:
+ enum WriteWindowType {
+ HTMLWindow = 1,
+ PlainTextWindow = 2
+ };
+
+ /**
+ * Insert the keyboard accelerators of this window into the given KAccel object.
+ */
+ // static void insertKeyboardActions( KAccel* const accel );
+ static void insertKeyboardActions( BtActionCollection* const a );
+
+ CMDIArea* mdi() const;
+ /**
+ * Returns the right window caption.
+ */
+ const QString windowCaption();
+ /**
+ * Returns the used modules as a QPtrList
+ */
+ QList<CSwordModuleInfo*> modules();
+ /**
+ * Store the settings of this window in the given CProfileWindow object.
+ */
+ virtual void storeProfileSettings( Profile::CProfileWindow* profileWindow ) = 0;
+ /**
+ * Store the settings of this window in the given profile window.
+ */
+ virtual void applyProfileSettings( Profile::CProfileWindow* profileWindow ) = 0;
+ /**
+ * Set the window caption.
+ */
+ virtual void setCaption( const QString& );
+ /**
+ * Sets the new filter options of this window.
+ */
+ void setFilterOptions( CSwordBackend::FilterOptions& filterOptions );
+ /**
+ * Sets the new display options for this window.
+ */
+ void setDisplayOptions( const CSwordBackend::DisplayOptions& displayOptions );
+ /**
+ * Returns the display options used by this display window.
+ */
+ CSwordBackend::DisplayOptions& displayOptions();
+ /**
+ * Returns the filter options used by this window.
+ */
+ CSwordBackend::FilterOptions& filterOptions();
+ /**
+ * Set the ready status
+ */
+ void setReady( const bool& ready );
+ /**
+ * Returns true if the widget is ready for use.
+ */
+ bool isReady() const;
+ /**
+ * Returns true if the window may be closed.
+ */
+ virtual bool queryClose();
+ /**
+ * Returns the keychooser widget of this display window.
+ */
+ CKeyChooser* keyChooser() const;
+ /**
+ * Sets the new sword key.
+ */
+ void setKey( CSwordKey* key );
+ /**
+ * Returns the key of this display window.
+ */
+ CSwordKey* key() const;
+ /**
+ * Initialize the window. Call this method from the outside, because calling this in the constructor is not possible!
+ */
+ virtual bool init();
+ /**
+ * Sets the main toolbar.
+ */
+ void setMainToolBar( QToolBar* bar );
+ /**
+ * Sets the buttons toolbar.
+ */
+ void setButtonsToolBar( QToolBar* bar );
+ /**
+ * Returns the main toolbar.
+ */
+ QToolBar* mainToolBar() const;
+ /**
+ * Returns the buttons toolbar.
+ */
+ QToolBar* buttonsToolBar() const;
+ /**
+ * Initialize the toolbars
+ */
+ virtual void initToolbars() = 0;
+ /**
+ * Returns the display settings button
+ */
+ CDisplaySettingsButton* displaySettingsButton() const;
+ /**
+ * Sets the display settings button.
+ */
+ void setDisplaySettingsButton( CDisplaySettingsButton* button );
+ virtual void setupPopupMenu() = 0;
+ /**
+ * Returns the display widget used by this implementation of CDisplayWindow.
+ */
+ virtual CDisplay* displayWidget() const;
+ /**
+ * Sets the display widget used by this display window.
+ */
+ virtual void setDisplayWidget( CDisplay* newDisplay );
+
+ /** Returns whether syncs to the active window are allowed at this time for this display window
+ * @return boolean value whether sync is allowed
+ */
+ virtual bool syncAllowed() const {
+ return false;
+ };
+
+ BtActionCollection* actionCollection();
+
+public slots:
+ /**
+ * Lookup the specified key in the given module. If the module is not chosen withing
+ * this display window create a new displaywindow with the right module in it.
+ */
+ virtual void lookupModKey( const QString& module, const QString& key );
+ /**
+ * Lookup the key in the chosen modules.
+ */
+ virtual void lookupKey( const QString& key );
+ /**
+ * Refresh the settings of this window.
+ */
+ virtual void reload(CSwordBackend::SetupChangedReason reason);
+
+protected:
+ friend class CMDIArea;
+ friend class CBibleReadWindow;
+
+ CDisplayWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent);
+ virtual ~CDisplayWindow();
+ /**
+ * Initializes the intern keyboard actions.
+ */
+ virtual void initActions();
+ /**
+ * Sets the keychooser widget for this display window.
+ */
+ void setKeyChooser( CKeyChooser* ck );
+ /**
+ * Returns the module chooser bar.
+ */
+ CModuleChooserBar* moduleChooserBar() const;
+ /**
+ * Lookup the given key.
+ */
+ virtual void lookupSwordKey( CSwordKey* ) = 0;
+ /**
+ * Sets the module chooser bar.
+ */
+ void setModuleChooserBar( CModuleChooserBar* bar );
+ /**
+ * Sets the modules.
+ */
+ void setModules( const QList<CSwordModuleInfo*>& modules );
+ /**
+ * Initializes the signal / slot connections of this display window.
+ */
+ virtual void initConnections() = 0;
+ /**
+ * Initialize the view of this display window.
+ */
+ virtual void initView() = 0;
+ /**
+ * Returns the installed popup menu.
+ */
+ QMenu* popup();
+ virtual void closeEvent(QCloseEvent* e);
+
+protected slots:
+ virtual void modulesChanged();
+ /**
+ * Lookup the current key. Used to refresh the display.
+ */
+ void lookup();
+ virtual void updatePopupMenu();
+
+ void slotSearchInModules();
+
+ void printAll();
+ void printAnchorWithText();
+
+
+private:
+ BtActionCollection* m_actionCollection;
+ CMDIArea* m_mdi;
+
+ //we may only cache the module names bacause after a backend relaod the pointers are invalid!
+ QStringList m_modules;
+
+ CSwordBackend::FilterOptions m_filterOptions;
+ CSwordBackend::DisplayOptions m_displayOptions;
+
+ CDisplaySettingsButton* m_displaySettingsButton;
+ CKeyChooser* m_keyChooser;
+ CSwordKey* m_swordKey;
+ bool m_isReady;
+ CModuleChooserBar* m_moduleChooserBar;
+ QToolBar* m_mainToolBar;
+ QToolBar* m_buttonsToolBar;
+ QMenu* m_popupMenu;
+ CDisplay* m_displayWidget;
+};
+
+#endif
diff --git a/src/frontend/displaywindow/cdisplaywindowfactory.cpp b/src/frontend/displaywindow/cdisplaywindowfactory.cpp
new file mode 100644
index 0000000..d386ecf
--- /dev/null
+++ b/src/frontend/displaywindow/cdisplaywindowfactory.cpp
@@ -0,0 +1,57 @@
+//
+// C++ Implementation: cdisplaywindowfactory
+//
+// Description:
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#include "cdisplaywindowfactory.h"
+
+#include "creadwindow.h"
+#include "cbiblereadwindow.h"
+#include "ccommentaryreadwindow.h"
+#include "clexiconreadwindow.h"
+#include "cbookreadwindow.h"
+#include "cwritewindow.h"
+#include "cplainwritewindow.h"
+#include "chtmlwritewindow.h"
+
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "frontend/cmdiarea.h"
+
+
+CReadWindow* CDisplayWindowFactory::createReadInstance(QList<CSwordModuleInfo*> modules, CMDIArea* parent)
+{
+ qDebug("CDisplayWindowFactory::createReadInstance");
+ switch (modules.first()->type()) {
+ case CSwordModuleInfo::Bible:
+ return new CBibleReadWindow(modules, parent);
+ case CSwordModuleInfo::Commentary:
+ return new CCommentaryReadWindow(modules, parent);
+ case CSwordModuleInfo::Lexicon:
+ return new CLexiconReadWindow(modules, parent);
+ case CSwordModuleInfo::GenericBook:
+ return new CBookReadWindow(modules, parent);
+ default:
+ qWarning("unknown module type");
+ break;
+ }
+ return 0;
+}
+
+
+CWriteWindow* CDisplayWindowFactory::createWriteInstance(QList<CSwordModuleInfo*> modules, CMDIArea* parent, const CDisplayWindow::WriteWindowType type)
+{
+ if (type == CDisplayWindow::HTMLWindow) {
+ return new CHTMLWriteWindow(modules, parent);
+ }
+ else {
+ return new CPlainWriteWindow(modules, parent);
+ }
+ return 0;
+}
diff --git a/src/frontend/displaywindow/cdisplaywindowfactory.h b/src/frontend/displaywindow/cdisplaywindowfactory.h
new file mode 100644
index 0000000..4bc4372
--- /dev/null
+++ b/src/frontend/displaywindow/cdisplaywindowfactory.h
@@ -0,0 +1,34 @@
+//
+// C++ Interface: cdisplaywindowfactory
+//
+// Description:
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef CDISPLAYWINDOWFACTORY_H
+#define CDISPLAYWINDOWFACTORY_H
+
+#include "cdisplaywindow.h"
+
+class CSwordModuleInfo;
+
+
+class CReadWindow;
+class CWriteWindow;
+class CMDIArea;
+
+class CDisplayWindowFactory
+{
+public:
+ static CReadWindow* createReadInstance(QList<CSwordModuleInfo*> modules, CMDIArea* parent);
+ static CWriteWindow* createWriteInstance(QList<CSwordModuleInfo*> modules, CMDIArea* parent, const CDisplayWindow::WriteWindowType type = CDisplayWindow::HTMLWindow);
+
+private:
+ CDisplayWindowFactory();
+};
+
+#endif
diff --git a/src/frontend/displaywindow/chtmlwritewindow.cpp b/src/frontend/displaywindow/chtmlwritewindow.cpp
new file mode 100644
index 0000000..7e97aa6
--- /dev/null
+++ b/src/frontend/displaywindow/chtmlwritewindow.cpp
@@ -0,0 +1,163 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#include "chtmlwritewindow.h"
+#include "btactioncollection.h"
+
+//frontend includes
+#include "frontend/keychooser/ckeychooser.h"
+#include "frontend/profile/cprofilewindow.h"
+#include "frontend/display/cwritedisplay.h"
+#include "frontend/display/chtmlwritedisplay.h"
+
+#include "backend/keys/cswordkey.h"
+
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+
+//Qt includes
+#include <QToolBar>
+#include <QMessageBox>
+#include <QAction>
+
+using namespace Profile;
+
+CHTMLWriteWindow::CHTMLWriteWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent)
+: CPlainWriteWindow(modules, parent) {}
+
+CHTMLWriteWindow::~CHTMLWriteWindow() {}
+
+void CHTMLWriteWindow::initView() {
+ CWriteDisplay* writeDisplay = CDisplay::createWriteInstance(this, CDisplay::HTMLDisplay);
+ Q_ASSERT(writeDisplay);
+ setDisplayWidget( writeDisplay );
+ setCentralWidget( displayWidget()->view() );
+
+ setMainToolBar( new QToolBar(this) );
+ addToolBar(mainToolBar());
+
+ setKeyChooser( CKeyChooser::createInstance(modules(), key(), mainToolBar()) );
+ mainToolBar()->addWidget(keyChooser());
+}
+
+void CHTMLWriteWindow::initConnections() {
+ CWriteWindow::initConnections();
+
+ connect(keyChooser(), SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*)));
+ connect(displayWidget()->connectionsProxy(), SIGNAL(textChanged()), this, SLOT(textChanged()) );
+}
+
+void CHTMLWriteWindow::initToolbars() {
+ //setup the main toolbar
+ m_actions.syncWindow = new QAction(
+ util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::commentaryWindow::syncWindow::icon),
+ tr("Sync with active Bible"),
+ actionCollection()
+ );
+ m_actions.syncWindow->setCheckable(true);
+ m_actions.syncWindow->setShortcut(CResMgr::displaywindows::commentaryWindow::syncWindow::accel);
+ m_actions.syncWindow->setToolTip(tr("Synchronize (show the same verse) with the active Bible window"));
+ actionCollection()->addAction(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName, m_actions.syncWindow);
+ mainToolBar()->addAction(m_actions.syncWindow);
+
+ m_actions.saveText = new QAction(
+ util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::saveText::icon),
+ tr("Save text"),
+ actionCollection()
+ );
+ m_actions.saveText->setShortcut(CResMgr::displaywindows::writeWindow::saveText::accel);
+ m_actions.saveText->setToolTip( tr("Save text") );
+ QObject::connect(m_actions.saveText, SIGNAL(triggered()), this, SLOT( saveCurrentText() ) );
+ actionCollection()->addAction(CResMgr::displaywindows::writeWindow::saveText::actionName, m_actions.saveText);
+ mainToolBar()->addAction(m_actions.saveText);
+
+
+ m_actions.deleteEntry = new QAction(
+ util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::deleteEntry::icon),
+ tr("Delete current entry"),
+ actionCollection()
+ );
+ m_actions.deleteEntry->setShortcut(CResMgr::displaywindows::writeWindow::deleteEntry::accel);
+ m_actions.deleteEntry->setToolTip( tr("Delete current entry (no undo)") );
+ QObject::connect(m_actions.deleteEntry, SIGNAL(triggered()), this, SLOT( deleteEntry() ) );
+ actionCollection()->addAction(CResMgr::displaywindows::writeWindow::deleteEntry::actionName, m_actions.deleteEntry);
+ mainToolBar()->addAction(m_actions.deleteEntry);
+
+ m_actions.restoreText = new QAction(
+ util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::restoreText::icon),
+ tr("Restore original text"),
+ actionCollection()
+ );
+ m_actions.restoreText->setShortcut(CResMgr::displaywindows::writeWindow::restoreText::accel);
+ m_actions.restoreText->setToolTip( tr("Restore original text, new text will be lost") );
+ QObject::connect(m_actions.restoreText, SIGNAL(triggered()), this, SLOT( restoreText() ) );
+ actionCollection()->addAction(CResMgr::displaywindows::writeWindow::restoreText::actionName, m_actions.restoreText);
+ mainToolBar()->addAction(m_actions.restoreText);
+
+ //html formatting toolbar
+ QToolBar* bar = new QToolBar(this);
+ ((CWriteDisplay*)displayWidget())->setupToolbar( bar, actionCollection() );
+ addToolBar(bar);
+}
+
+void CHTMLWriteWindow::storeProfileSettings( CProfileWindow* profileWindow ) {
+ CWriteWindow::storeProfileSettings(profileWindow);
+ profileWindow->setWindowSettings( m_actions.syncWindow->isChecked() );
+}
+
+void CHTMLWriteWindow::applyProfileSettings( CProfileWindow* profileWindow ) {
+ CWriteWindow::applyProfileSettings(profileWindow);
+ if (profileWindow->windowSettings()) {
+ m_actions.syncWindow->setChecked(true);
+ }
+}
+
+/** Is called when the current text was changed. */
+void CHTMLWriteWindow::textChanged() {
+ m_actions.saveText->setEnabled( ((CWriteDisplay*)displayWidget())->isModified() );
+ m_actions.restoreText->setEnabled( ((CWriteDisplay*)displayWidget())->isModified() );
+}
+
+/** Loads the original text from the module. */
+void CHTMLWriteWindow::restoreText() {
+ lookupSwordKey(key());
+ ((CWriteDisplay*)displayWidget())->setModified(false);
+ textChanged();
+}
+
+bool CHTMLWriteWindow::syncAllowed() const {
+ return m_actions.syncWindow->isChecked();
+}
+
+/** Saves the text for the current key. Directly writes the changed text into the module. */
+void CHTMLWriteWindow::saveCurrentText( const QString& /*key*/ ) {
+ QString t = ((CHTMLWriteDisplay*)displayWidget())->toHtml();
+ //since t is a complete HTML page at the moment, strip away headers and footers of a HTML page
+ QRegExp re("(?:<html.*>.+<body.*>)", Qt::CaseInsensitive); //remove headers, case insensitive
+ re.setMinimal(true);
+ t.replace(re, "");
+ t.replace(QRegExp("</body></html>", Qt::CaseInsensitive), "");//remove footer
+
+ const QString& oldKey = this->key()->key();
+ if( modules().first()->isWritable() ) {
+ modules().first()->write(this->key(), t );
+ this->key()->key( oldKey );
+
+ ((CWriteDisplay*)displayWidget())->setModified(false);
+ textChanged();
+ }
+ else {
+ QMessageBox::critical( this, tr("Module not writable"),
+ QString::fromLatin1("<qt><b>%1</b><br />%2</qt>")
+ .arg( tr("Module is not writable.") )
+ .arg( tr("Either the module may not be edited, or you do not have write permission.") ) );
+ }
+}
diff --git a/src/frontend/displaywindow/chtmlwritewindow.h b/src/frontend/displaywindow/chtmlwritewindow.h
new file mode 100644
index 0000000..9c50957
--- /dev/null
+++ b/src/frontend/displaywindow/chtmlwritewindow.h
@@ -0,0 +1,75 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CHTMLWRITEWINDOW_H
+#define CHTMLWRITEWINDOW_H
+
+//BibleTime includes
+#include "cplainwritewindow.h"
+
+class QAction;
+
+
+/** The WYSIWYG implementation of the editor.
+ * @author The BibleTime team
+ */
+class CHTMLWriteWindow : public CPlainWriteWindow {
+ Q_OBJECT
+public:
+ CHTMLWriteWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent);
+ virtual ~CHTMLWriteWindow();
+
+ /**
+ * Store the settings of this window in the given CProfileWindow object.
+ */
+ virtual void storeProfileSettings( Profile::CProfileWindow* );
+ /**
+ * Store the settings of this window in the given profile window.
+ */
+ virtual void applyProfileSettings( Profile::CProfileWindow* );
+
+ virtual bool syncAllowed() const;
+
+protected: // Protected methods
+ /**
+ * Initialize the state of this widget.
+ */
+ virtual void initView();
+ virtual void initConnections();
+ virtual void initToolbars();
+ virtual CDisplayWindow::WriteWindowType writeWindowType() {
+ return CDisplayWindow::HTMLWindow;
+ };
+
+protected slots:
+ /**
+ * Is called when the current text was changed.
+ */
+ virtual void textChanged();
+ /**
+ * Loads the original text from the module.
+ */
+ virtual void restoreText();
+ /**
+ * Saves the text for the current key. Directly writes the changed text into the module.
+ */
+ virtual void saveCurrentText( const QString& );
+private:
+ struct {
+ QAction* saveText;
+ QAction* restoreText;
+ QAction* deleteEntry;
+ QAction* syncWindow;
+ }
+ m_actions;
+};
+
+#endif
diff --git a/src/frontend/displaywindow/clexiconreadwindow.cpp b/src/frontend/displaywindow/clexiconreadwindow.cpp
new file mode 100644
index 0000000..703e40c
--- /dev/null
+++ b/src/frontend/displaywindow/clexiconreadwindow.cpp
@@ -0,0 +1,367 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+//BibleTime includes
+#include "clexiconreadwindow.h"
+#include "btactioncollection.h"
+
+#include "cmodulechooserbar.h"
+#include "cbuttons.h"
+#include "bttoolbarpopupaction.h"
+
+#include "backend/keys/cswordkey.h"
+#include "backend/keys/cswordldkey.h"
+
+#include "backend/config/cbtconfig.h"
+#include "frontend/cexportmanager.h"
+#include "frontend/display/cdisplay.h"
+#include "frontend/display/creaddisplay.h"
+#include "frontend/display/bthtmlreaddisplay.h"
+#include "frontend/keychooser/ckeychooser.h"
+#include "frontend/keychooser/bthistory.h"
+
+#include "util/ctoolclass.h"
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+
+#include <QMenu>
+#include <QApplication>
+#include <QFile>
+#include <QFileDialog>
+#include <QAction>
+
+CLexiconReadWindow::CLexiconReadWindow(QList<CSwordModuleInfo*> moduleList, CMDIArea* parent)
+ : CReadWindow(moduleList, parent)
+{
+ qDebug("CLexiconReadWindow::CLexiconReadWindow");
+ moduleList.first();
+ setKey( CSwordKey::createInstance(moduleList.first()) );
+}
+
+CLexiconReadWindow::~CLexiconReadWindow() {}
+
+void CLexiconReadWindow::insertKeyboardActions( BtActionCollection* const a )
+{
+ qDebug("CLexiconReadWindow::insertKeyboardActions");
+ QAction* kaction;
+ kaction = new QAction( tr("Next entry"), a);
+ kaction->setShortcut(CResMgr::displaywindows::lexiconWindow::nextEntry::accel);
+ a->addAction("nextEntry", kaction);
+
+ kaction = new QAction( tr("Previous entry"), a);
+ kaction->setShortcut( CResMgr::displaywindows::lexiconWindow::previousEntry::accel);
+ a->addAction("previousEntry", kaction);
+
+ kaction = new QAction(tr("Copy reference only"), a);
+ a->addAction("copyReferenceOnly", kaction);
+
+ kaction = new QAction(tr("Copy selected text"), a);
+ a->addAction("copySelectedText", kaction);
+
+ kaction = new QAction(tr("Save entry as HTML"), a);
+ a->addAction("saveHtml", kaction);
+
+ kaction = new QAction(tr("Print reference only"), a);
+ a->addAction("printReferenceOnly", kaction);
+}
+
+void CLexiconReadWindow::initActions()
+{
+ qDebug("CLexiconReadWindow::initActions");
+
+ BtActionCollection* ac = actionCollection();
+ CLexiconReadWindow::insertKeyboardActions(ac);
+ CReadWindow::initActions();
+
+ m_actions.backInHistory = dynamic_cast<BtToolBarPopupAction*>(
+ ac->action(CResMgr::displaywindows::general::backInHistory::actionName) );
+ Q_ASSERT(m_actions.backInHistory);
+
+ m_actions.forwardInHistory = dynamic_cast<BtToolBarPopupAction*>(
+ ac->action(CResMgr::displaywindows::general::forwardInHistory::actionName) );
+ Q_ASSERT(m_actions.forwardInHistory);
+
+ QAction* kaction;
+
+ kaction = new QAction(tr("Next entry"), ac );
+ kaction->setShortcut( CResMgr::displaywindows::lexiconWindow::nextEntry::accel);
+ QObject::connect(kaction, SIGNAL(triggered()), this, SLOT( nextEntry() ) );
+ ac->addAction("nextEntry", kaction);
+
+ kaction = new QAction(tr("Previous entry"), ac );
+ kaction->setShortcut( CResMgr::displaywindows::lexiconWindow::previousEntry::accel);
+ QObject::connect(kaction, SIGNAL(triggered()), this, SLOT( previousEntry() ) );
+ ac->addAction("previousEntry", kaction);
+
+ m_actions.selectAll = qobject_cast<QAction*>(ac->action("selectAll"));
+ //TODO: Q_ASSERT(m_actions.selectAll);
+
+ m_actions.findText = qobject_cast<QAction*>(ac->action("findText"));
+ //TODO: Q_ASSERT(m_actions.findText);
+
+ m_actions.findStrongs = new QAction(
+// QIcon(CResMgr::displaywindows::general::findStrongs::icon),
+ tr("Strong's Search"),
+ ac
+ );
+ m_actions.findStrongs->setShortcut(CResMgr::displaywindows::general::findStrongs::accel);
+ QObject::connect(m_actions.findStrongs, SIGNAL(triggered()), this, SLOT(openSearchStrongsDialog()) );
+ ac->addAction(CResMgr::displaywindows::general::findStrongs::actionName, m_actions.findStrongs);
+
+ m_actions.copy.reference = new QAction(tr("Reference only"), ac );
+ QObject::connect(m_actions.copy.reference, SIGNAL(triggered()), displayWidget()->connectionsProxy(), SLOT(copyAnchorOnly()) );
+ ac->addAction("copyReferenceOnly", m_actions.copy.reference);
+
+ m_actions.copy.entry = new QAction(tr("Entry with text"), ac );
+ QObject::connect(m_actions.copy.entry, SIGNAL(triggered()), displayWidget()->connectionsProxy(), SLOT(copyAll()) );
+ ac->addAction("copyEntryWithText", m_actions.copy.entry);
+
+ Q_ASSERT(ac->action("copySelectedText"));
+ m_actions.copy.selectedText = qobject_cast<QAction*>(ac->action("copySelectedText"));
+
+ m_actions.save.entryAsPlain = new QAction(tr("Entry as plain text"), ac );
+ QObject::connect(m_actions.save.entryAsPlain, SIGNAL(triggered()), this, SLOT(saveAsPlain()) );
+ ac->addAction("saveEntryAsPlain", m_actions.save.entryAsPlain);
+
+ m_actions.save.entryAsHTML = new QAction(tr("Entry as HTML"), ac );
+ QObject::connect(m_actions.save.entryAsHTML, SIGNAL(triggered()), this, SLOT(saveAsHTML()));
+ ac->addAction("saveEntryAsHTML", m_actions.save.entryAsHTML);
+
+ m_actions.print.reference = new QAction(tr("Reference only"), ac);
+ QObject::connect(m_actions.print.reference, SIGNAL(triggered()), this, SLOT(printAnchorWithText()));
+ ac->addAction("printReferenceOnly", m_actions.print.reference);
+
+ m_actions.print.entry = new QAction(tr("Entry with text"), ac);
+ QObject::connect(m_actions.print.entry, SIGNAL(triggered()), this, SLOT(printAll()));
+ ac->addAction("printEntryWithText", m_actions.print.entry);
+
+ // init with the user defined settings
+ qDebug("call CBTConfig::setupAccelSettings(CBTConfig::lexiconWindow, ac); and end CLexiconReadWindow::initActions");
+// CBTConfig::setupAccelSettings(CBTConfig::lexiconWindow, ac);
+}
+
+/** No descriptions */
+void CLexiconReadWindow::initConnections()
+{
+ qDebug("CLexiconReadWindow::initConnections");
+ Q_ASSERT(keyChooser());
+
+ connect(keyChooser(), SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*)));
+ connect(keyChooser()->history(), SIGNAL(historyChanged(bool, bool)), this, SLOT(slotUpdateHistoryButtons(bool, bool)));
+
+ //connect the history actions to the right slots
+ bool ok = connect(
+ m_actions.backInHistory->popupMenu(), SIGNAL(aboutToShow()),
+ this, SLOT(slotFillBackHistory())
+ );
+ Q_ASSERT(ok);
+ ok = connect(
+ m_actions.backInHistory->popupMenu(), SIGNAL(triggered(QAction*)),
+ keyChooser()->history(), SLOT(move(QAction*))
+ );
+ Q_ASSERT(ok);
+ ok = connect(
+ m_actions.forwardInHistory->popupMenu(), SIGNAL(aboutToShow()),
+ this, SLOT(slotFillForwardHistory())
+ );
+ Q_ASSERT(ok);
+ ok = connect(
+ m_actions.forwardInHistory->popupMenu(), SIGNAL(triggered(QAction*)),
+ keyChooser()->history(), SLOT(move(QAction*))
+ );
+ Q_ASSERT(ok);
+
+}
+
+void CLexiconReadWindow::initView()
+{
+ qDebug("CLexiconReadWindow::initView");
+ setDisplayWidget( CDisplay::createReadInstance(this) );
+ setMainToolBar( new QToolBar(this) );
+ addToolBar(mainToolBar());
+ setKeyChooser( CKeyChooser::createInstance(modules(), key(), mainToolBar()) );
+ mainToolBar()->addWidget(keyChooser());
+ setModuleChooserBar( new CModuleChooserBar(modules(), modules().first()->type(), this) );
+ moduleChooserBar()->adjustSize();
+ addToolBar(moduleChooserBar());
+ setButtonsToolBar( new QToolBar(this) );
+ addToolBar(buttonsToolBar());
+ setWindowIcon(CToolClass::getIconForModule(modules().first()));
+ setCentralWidget( displayWidget()->view() );
+}
+
+void CLexiconReadWindow::initToolbars()
+{
+ //main toolbar
+ Q_ASSERT(m_actions.backInHistory);
+ mainToolBar()->addAction(m_actions.backInHistory); //1st button
+ mainToolBar()->addAction(m_actions.forwardInHistory); //2nd button
+
+ //buttons toolbar
+ QAction* action = qobject_cast<QAction*>(actionCollection()->action(
+ CResMgr::displaywindows::general::search::actionName));
+ Q_ASSERT( action );
+ if (action) {
+ buttonsToolBar()->addAction(action);
+ }
+ setDisplaySettingsButton( new CDisplaySettingsButton( &displayOptions(), &filterOptions(), modules(), buttonsToolBar()) );
+
+ //TODO: find the right place for the button
+ buttonsToolBar()->addWidget(displaySettingsButton());
+}
+
+void CLexiconReadWindow::setupPopupMenu()
+{
+ popup()->setTitle(tr("Lexicon window"));
+ popup()->setIcon(CToolClass::getIconForModule(modules().first()));
+ popup()->addAction(m_actions.findText);
+ popup()->addAction(m_actions.findStrongs);
+ popup()->addAction(m_actions.selectAll);
+ popup()->addSeparator();
+
+ m_actions.copyMenu = new QMenu(tr("Copy..."), popup());
+
+ m_actions.copyMenu->addAction(m_actions.copy.reference);
+ m_actions.copyMenu->addAction(m_actions.copy.entry);
+ m_actions.copyMenu->addSeparator();
+ m_actions.copyMenu->addAction(m_actions.copy.selectedText);
+ popup()->addMenu(m_actions.copyMenu);
+
+ m_actions.saveMenu = new QMenu(
+ tr("Save..."),
+ popup()
+ );
+ m_actions.saveMenu->addAction(m_actions.save.entryAsPlain);
+ m_actions.saveMenu->addAction(m_actions.save.entryAsHTML);
+
+ // Save raw HTML action for debugging purposes
+ if (qApp->property("--debug").toBool()) {
+ QAction* debugAction = new QAction("Raw HTML", this);
+ QObject::connect(debugAction, SIGNAL(triggered()), this, SLOT(saveRawHTML()));
+ m_actions.saveMenu->addAction(debugAction);
+ } // end of Save Raw HTML
+
+ popup()->addMenu(m_actions.saveMenu);
+
+ m_actions.printMenu = new QMenu(
+ tr("Print..."),
+ popup()
+ );
+ m_actions.printMenu->addAction(m_actions.print.reference);
+ m_actions.printMenu->addAction(m_actions.print.entry);
+ popup()->addMenu(m_actions.printMenu);
+}
+
+/** Reimplemented. */
+void CLexiconReadWindow::updatePopupMenu()
+{
+ //enable the action depending on the supported module features
+
+ m_actions.findStrongs->setEnabled( displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma] != QString::null );
+
+ m_actions.copy.reference->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() );
+ m_actions.copy.selectedText->setEnabled( displayWidget()->hasSelection() );
+
+ m_actions.print.reference->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() );
+}
+
+/** No descriptions */
+void CLexiconReadWindow::nextEntry()
+{
+ keyChooser()->setKey(ldKey()->NextEntry());
+}
+
+/** No descriptions */
+void CLexiconReadWindow::previousEntry()
+{
+ keyChooser()->setKey(ldKey()->PreviousEntry());
+}
+
+/** Reimplementation to return the right key. */
+CSwordLDKey* CLexiconReadWindow::ldKey()
+{
+ return dynamic_cast<CSwordLDKey*>(CDisplayWindow::key());
+}
+
+/** This function saves the entry as html using the CExportMgr class. */
+void CLexiconReadWindow::saveAsHTML() {
+ CExportManager mgr(tr("Saving entry ..."), true, tr("Saving"), filterOptions(), displayOptions());
+ mgr.saveKey(key(), CExportManager::HTML, true);
+}
+
+/** Saving the raw HTML for debugging purposes */
+void CLexiconReadWindow::saveRawHTML()
+{
+ //qDebug("CLexiconReadWindow::saveRawHTML");
+ QString savefilename = QFileDialog::getSaveFileName();
+ if (savefilename.isEmpty()) return;
+ QFile file(savefilename);
+ BtHtmlReadDisplay* disp = dynamic_cast<BtHtmlReadDisplay*>(displayWidget());
+ if (disp) {
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ qDebug("could not open file");
+ return;
+ }
+ QString source = disp->text();
+ file.write(source.toUtf8());
+ //qDebug() << "wrote" << bytes << "bytes";
+ file.close();
+ file.flush();
+ } else {
+ qDebug("No htmlreaddisplay widget!");
+ }
+
+}
+
+/** This function saves the entry as html using the CExportMgr class. */
+void CLexiconReadWindow::saveAsPlain()
+{
+ CExportManager mgr(tr("Saving entry ..."), true, tr("Saving"), filterOptions(), displayOptions());
+ mgr.saveKey(key(), CExportManager::Text, true);
+}
+
+void CLexiconReadWindow::slotFillBackHistory()
+{
+ qDebug("CLexiconReadWindow::slotFillBackHistory");
+
+ QMenu* menu = m_actions.backInHistory->popupMenu();
+ menu->clear();
+
+ //TODO: take the history list and fill the menu
+ QListIterator<QAction*> it(keyChooser()->history()->getBackList());
+ while (it.hasNext()) {
+ menu->addAction(it.next());
+ }
+}
+
+void CLexiconReadWindow::slotFillForwardHistory()
+{
+ qDebug("CLexiconReadWindow::slotFillForwardHistory");
+
+ QMenu* menu = m_actions.forwardInHistory->popupMenu();
+ menu->clear();
+ //TODO: take the history list and fill the menu using addAction
+ QListIterator<QAction*> it(keyChooser()->history()->getFwList());
+ while (it.hasNext()) {
+ menu->addAction(it.next());
+ }
+}
+
+
+void CLexiconReadWindow::slotUpdateHistoryButtons(bool backEnabled, bool fwEnabled)
+{
+ qDebug("CLexiconReadWindow::slotUpdateHistoryButtons");
+ Q_ASSERT(m_actions.backInHistory);
+ Q_ASSERT(keyChooser());
+
+ m_actions.backInHistory->setEnabled( backEnabled );
+ m_actions.forwardInHistory->setEnabled( fwEnabled );
+}
diff --git a/src/frontend/displaywindow/clexiconreadwindow.h b/src/frontend/displaywindow/clexiconreadwindow.h
new file mode 100644
index 0000000..cea9096
--- /dev/null
+++ b/src/frontend/displaywindow/clexiconreadwindow.h
@@ -0,0 +1,118 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CLEXICONREADWINDOW_H
+#define CLEXICONREADWINDOW_H
+
+//BibleTime includes
+#include "creadwindow.h"
+#include "frontend/keychooser/ckeychooser.h"
+class BtToolBarPopupAction;
+
+class CSwordKey;
+class CSwordLDKey;
+
+class KToolBarPopupAction;
+class BtActionCollection;
+class QAction;
+class QMenu;
+
+/**
+ *@author The BibleTime team
+ */
+
+class CLexiconReadWindow : public CReadWindow {
+ Q_OBJECT
+public:
+ CLexiconReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent);
+ virtual ~CLexiconReadWindow();
+ /**
+ * Store the settings of this window in the given CProfileWindow object.
+ */
+ // virtual void storeProfileSettings( CProfileWindow* profileWindow );
+ /**
+ * Store the settings of this window in the given profile window.
+ */
+ // virtual void applyProfileSettings( CProfileWindow* profileWindow );
+ /**
+ * Reimplementation.
+ */
+ // static void insertKeyboardActions( KAccel* a );
+ static void insertKeyboardActions( BtActionCollection* const a );
+
+protected:
+ virtual void initActions();
+ virtual void initToolbars();
+ virtual void initConnections();
+ virtual void initView();
+ virtual void updatePopupMenu();
+ virtual void setupPopupMenu();
+
+
+ struct ActionsStruct {
+ BtToolBarPopupAction* backInHistory;
+ BtToolBarPopupAction* forwardInHistory;
+
+ QAction* selectAll;
+ QAction* findText;
+ QAction* findStrongs;
+
+ QMenu* copyMenu;
+ struct {
+ QAction* reference;
+ QAction* entry;
+ QAction* selectedText;
+ }
+ copy;
+
+ QMenu* saveMenu;
+ struct {
+ QAction* reference;
+ QAction* entryAsPlain;
+ QAction* entryAsHTML;
+ }
+ save;
+
+ QMenu* printMenu;
+ struct {
+ QAction* reference;
+ QAction* entry;
+ }
+ print;
+ }
+ m_actions;
+
+private:
+ /**
+ * Reimplementation to return the right key.
+ */
+ CSwordLDKey* ldKey();
+
+protected slots: // Protected slots
+ void previousEntry();
+ void nextEntry();
+ /**
+ * This function saves the entry as html using the CExportMgr class.
+ */
+ void saveAsHTML();
+ /**
+ * This function saves the entry as plain text using the CExportMgr class.
+ */
+ void saveAsPlain();
+ void saveRawHTML();
+
+ void slotFillBackHistory();
+ void slotFillForwardHistory();
+
+ void slotUpdateHistoryButtons(bool backEnabled, bool fwEnabled);
+};
+
+#endif
diff --git a/src/frontend/displaywindow/cmodulechooserbar.cpp b/src/frontend/displaywindow/cmodulechooserbar.cpp
new file mode 100644
index 0000000..fc891ad
--- /dev/null
+++ b/src/frontend/displaywindow/cmodulechooserbar.cpp
@@ -0,0 +1,127 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cmodulechooserbar.h"
+
+#include "cmodulechooserbutton.h"
+
+#include <QList>
+#include <QDebug>
+#include <QAction>
+#include <QToolBar>
+
+CModuleChooserBar::CModuleChooserBar(QList<CSwordModuleInfo*> useModules, CSwordModuleInfo::ModuleType type, QWidget *parent)
+ : QToolBar(parent),
+ m_moduleType(type),
+ m_idCounter(0),
+ m_buttonLimit(-1) //-1 means no limit
+{
+ //insert buttons if useModules != 0
+ QList<CSwordModuleInfo*>::iterator end_it = useModules.end();
+ for (QList<CSwordModuleInfo*>::iterator it(useModules.begin()); it != end_it; ++it) {
+ if ((m_buttonLimit != -1) && ( m_buttonLimit <= (int)m_buttonList.count()) ) { //we reached the button limit
+ break;
+ }
+ addButton( *it );
+ }
+
+ // We can add a button to choose an additional module
+ if ( (m_buttonLimit == -1) || (m_buttonLimit > (int)m_buttonList.count()) ) {
+ addButton(0); //add a button without module set
+ }
+}
+
+CModuleChooserButton* CModuleChooserBar::addButton( CSwordModuleInfo* const module )
+{
+ CModuleChooserButton* b = new CModuleChooserButton(module, m_moduleType, ++m_idCounter, this);
+ QAction* a = addWidget(b);
+ m_buttonList.append(b);
+ connect( b, SIGNAL(sigAddButton()), this, SLOT(addButton()) );
+ connect( b, SIGNAL(sigRemoveButton(const int)), this, SLOT(removeButton(const int)) );
+ connect( b, SIGNAL(sigChanged()), SIGNAL(sigChanged()) );
+ connect( b, SIGNAL(sigChanged()), SLOT(updateMenuItems()) );
+ a->setVisible(true);
+ updateMenuItems(); //make sure the items are up to date with the newest module list
+ return b;
+}
+
+void CModuleChooserBar::addButton( ) {
+ addButton(0);
+}
+
+//change current with next and remove
+/** Removes a button from the toolbar */
+void CModuleChooserBar::removeButton( const int ID ) {
+ QMutableListIterator<CModuleChooserButton*> it(m_buttonList);
+ while (it.hasNext()) {
+ CModuleChooserButton* b = it.next();
+ if (b->getId() == ID) { //found the right button to remove
+ it.remove();
+ b->deleteLater();
+ break;
+ }
+ }
+ emit sigChanged();
+ updateMenuItems(); //make sure the items are up to date with the newest module list
+}
+
+/** Returns a list of selected modules. */
+QList<CSwordModuleInfo*> CModuleChooserBar::getModuleList() {
+ QList<CSwordModuleInfo*> list;
+ foreach (CModuleChooserButton* b, m_buttonList)
+ {
+ if (b->module()) list.append( b->module() );
+ }
+ return list;
+}
+
+//change current with remove
+/** Sets the number of the maximum count of buttons. */
+void CModuleChooserBar::setButtonLimit(const int limit) {
+ m_buttonLimit = limit;
+ if (limit == -1) //no need to delete buttons
+ return;
+
+ const int tooMuch = m_buttonList.size() - limit;
+ for (int i = 0; i < tooMuch; ++i) {
+ CModuleChooserButton* b = m_buttonList.takeLast();
+ b->deleteLater();
+ }
+
+ updateMenuItems();
+}
+
+/** Sets the modules which are chosen in this module chooser bar. */
+void CModuleChooserBar::setModules( QList<CSwordModuleInfo*> useModules ) {
+ setButtonLimit(0);
+ setButtonLimit(-1); //these two lines clear the bar
+
+ if (!useModules.count()) return;
+
+ QList<CSwordModuleInfo*>::iterator end_it = useModules.end();
+ for (QList<CSwordModuleInfo*>::iterator it(useModules.begin()); it != end_it; ++it) {
+ if ( (m_buttonLimit != -1) && (m_buttonLimit <= (int)m_buttonList.count()) ) {
+ break;
+ }
+ addButton( *it );
+ }
+
+ if ( (m_buttonLimit == -1) || (m_buttonLimit > (int)m_buttonList.count()) ) {
+ addButton(0);//add button without module set
+ }
+
+ updateMenuItems();
+}
+
+void CModuleChooserBar::updateMenuItems() {
+ resize(sizeHint());
+ update(); //seems to be neccessary to enforce display of the layout changes when a button was removed or added
+ foreach (CModuleChooserButton* b, m_buttonList)
+ b->updateMenuItems();
+}
diff --git a/src/frontend/displaywindow/cmodulechooserbar.h b/src/frontend/displaywindow/cmodulechooserbar.h
new file mode 100644
index 0000000..d21fcb9
--- /dev/null
+++ b/src/frontend/displaywindow/cmodulechooserbar.h
@@ -0,0 +1,77 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CMODULECHOOSERBAR_H
+#define CMODULECHOOSERBAR_H
+
+//BibleTime includes
+#include "backend/drivers/cswordmoduleinfo.h"
+
+#include "util/cpointers.h"
+
+//Qt includes
+#include <QList>
+#include <QToolBar>
+
+class CModuleChooserButton;
+class QWidget;
+
+/**
+ * @author The BibleTime team
+ */
+class CModuleChooserBar : public QToolBar {
+ Q_OBJECT
+public:
+ /**
+ * Default constructor
+ */
+ CModuleChooserBar(QList<CSwordModuleInfo*> useModules, CSwordModuleInfo::ModuleType type, QWidget *parent=0);
+ /**
+ * Returns a list of selected modules.
+ */
+ QList<CSwordModuleInfo*> getModuleList();
+ /**
+ * Sets the number of the maximum count of buttons.
+ */
+ void setButtonLimit( const int limit);
+ /**
+ * Sets the modules which are chosen in this module chooser bar.
+ */
+ void setModules( QList<CSwordModuleInfo*> modules );
+
+signals:
+ void sigChanged();
+
+protected:
+ /**
+ * Adds a button to the toolbar
+ */
+ CModuleChooserButton* addButton( CSwordModuleInfo* const module );
+
+protected slots: // Protected slots
+ /*
+ * This slot calls the addButton function above to add a button.
+ */
+ void addButton();
+ /**
+ * Removes a button from the toolbar
+ */
+ void removeButton( const int ID );
+ /** */
+ void updateMenuItems();
+
+private:
+ CSwordModuleInfo::ModuleType m_moduleType;
+ int m_idCounter;
+ int m_buttonLimit;
+ QList<CModuleChooserButton*> m_buttonList;
+
+};
+
+#endif
diff --git a/src/frontend/displaywindow/cmodulechooserbutton.cpp b/src/frontend/displaywindow/cmodulechooserbutton.cpp
new file mode 100644
index 0000000..dd5a9ee
--- /dev/null
+++ b/src/frontend/displaywindow/cmodulechooserbutton.cpp
@@ -0,0 +1,211 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cmodulechooserbutton.h"
+
+#include "cmodulechooserbar.h"
+
+#include "backend/managers/cswordbackend.h"
+
+#include "backend/config/cbtconfig.h"
+
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+
+//Qt includes
+#include <QString>
+#include <QToolTip>
+#include <QHash>
+#include <QToolButton>
+#include <QMenu>
+#include <QtDebug>
+
+CModuleChooserButton::CModuleChooserButton(CSwordModuleInfo* useModule,CSwordModuleInfo::ModuleType type, const int id, CModuleChooserBar *parent)
+ : QToolButton(parent),
+ m_id(id), m_popup(0), m_moduleChooserBar(parent)
+{
+ m_moduleType = type;
+ m_module = useModule;
+ m_hasModule = (m_module) ? true : false;
+
+ setIcon( util::filesystem::DirectoryUtil::getIcon(iconName()) );
+ setPopupMode(QToolButton::InstantPopup);
+
+ populateMenu();
+}
+
+CModuleChooserButton::~CModuleChooserButton() {
+ qDeleteAll(m_submenus);
+ m_submenus.clear();
+ delete m_popup; //not necessary, because has "this" as parent?
+}
+
+/** Returns the icon used for the current status. */
+const QString CModuleChooserButton::iconName() {
+ switch (m_moduleType) {
+ case CSwordModuleInfo::Bible:
+ return (m_hasModule) ? CResMgr::modules::bible::icon_unlocked : CResMgr::modules::bible::icon_add;
+ case CSwordModuleInfo::Commentary:
+ return (m_hasModule) ? CResMgr::modules::commentary::icon_unlocked : CResMgr::modules::commentary::icon_add;
+ case CSwordModuleInfo::Lexicon:
+ return m_hasModule ? CResMgr::modules::lexicon::icon_unlocked : CResMgr::modules::lexicon::icon_add;
+ case CSwordModuleInfo::GenericBook:
+ return m_hasModule ? CResMgr::modules::book::icon_unlocked : CResMgr::modules::book::icon_add;
+ default: //return as default the bible icon
+ return CResMgr::modules::bible::icon_unlocked;
+ }
+}
+
+CSwordModuleInfo* CModuleChooserButton::module() {
+ foreach (QMenu* popup, m_submenus) {
+ foreach (QAction* action, popup->actions()) {
+ if ( action->isChecked() ) { //idAt -> , isItemChecked -> QAction::isChecked
+ QString mod = action->text(); //popup->text(popup->idAt(i)); //text ->
+ mod.remove(QChar('&')); //remove hotkey indicators
+ return backend()->findModuleByName( mod.left(mod.indexOf(" ")) );
+ }
+ }
+ }
+ return 0; //"none" selected
+}
+
+/** Returns the id used for this button. */
+int CModuleChooserButton::getId() const {
+ return m_id;
+}
+
+/** Is called after a module was selected in the popup */
+void CModuleChooserButton::moduleChosen( QAction* action ) {
+
+ QListIterator<QMenu*> it(m_submenus);
+ while (it.hasNext()) {
+ QMenu* popup = it.next();
+ foreach (QAction* a, popup->actions()) {
+ a->setChecked(false);
+ }
+ action->setChecked(true);
+ }
+
+ m_noneAction->setChecked(false); //uncheck the "none" item
+ if (action->text().remove(QChar('&')) == tr("NONE")) { // note: this is for m_popup, the toplevel!
+ if (m_hasModule) {
+ emit sigRemoveButton(m_id);
+ return;
+ }
+ }
+ else {
+ if (!m_hasModule) {
+ emit sigAddButton();
+ }
+
+ m_hasModule = true;
+ m_module = module();
+
+ setIcon( util::filesystem::DirectoryUtil::getIcon(iconName()) );
+ emit sigChanged();
+
+ if (m_module) {
+ setToolTip( tr("Select a work") + " [" + m_module->name() + "]" );
+ }
+ else {
+ setToolTip( tr("Select an additional work") );
+ }
+ }
+}
+
+/** No descriptions */
+void CModuleChooserButton::populateMenu() {
+ qDeleteAll(m_submenus);
+ m_submenus.clear();
+ delete m_popup;
+ m_popup = new QMenu(this);
+
+ if (m_module) {
+ this->setToolTip( tr("Select a work") + " [" + m_module->name() + "]" );
+ }
+ else {
+ this->setToolTip( tr("Select an additional work") );
+ }
+
+ m_noneAction = m_popup->addAction(tr("NONE"));
+ m_noneAction->setCheckable(true);
+ if (!m_module) m_noneAction->setChecked(true);
+
+ m_popup->addSeparator();
+ connect(m_popup, SIGNAL(triggered(QAction*)), this, SLOT(moduleChosen(QAction*)));
+ setMenu(m_popup);
+
+
+ // ******* Add languages and modules ********
+
+ // Filters: add only non-hidden and right type
+ BTModuleTreeItem::HiddenOff hiddenFilter;
+ TypeFilter typeFilter(m_moduleType);
+ QList<BTModuleTreeItem::Filter*> filters;
+ if (!CBTConfig::get(CBTConfig::bookshelfShowHidden)) {
+ filters.append(&hiddenFilter);
+ }
+ filters.append(&typeFilter);
+ BTModuleTreeItem root(filters, BTModuleTreeItem::LangMod);
+ // add all items recursively
+ addItemToMenu(&root, m_popup);
+
+}
+
+void CModuleChooserButton::addItemToMenu(BTModuleTreeItem* item, QMenu* menu)
+{
+ foreach (BTModuleTreeItem* i, item->children()) {
+
+ if (i->type() == BTModuleTreeItem::Language) {
+ // argument menu was m_popup, create and add a new lang menu to it
+ QMenu* langMenu = new QMenu(i->text(), this);
+ menu->addMenu(langMenu);
+ m_submenus.append(langMenu);
+ connect(langMenu, SIGNAL(triggered(QAction*)), this, SLOT(moduleChosen(QAction*)));
+ // add the module items to the lang menu
+ addItemToMenu(i, langMenu);
+ }
+ else {
+ // item must be module, create and add it to the lang menu
+ QString name(i->text());
+ name.append(" ").append(i->moduleInfo()->isLocked() ? tr("[locked]") : QString::null);
+ QAction* modItem = new QAction(name, menu);
+ modItem->setCheckable(true);
+ if ( m_module && i->text() == m_module->name()) modItem->setChecked(true);
+ menu->addAction(modItem);
+ }
+ }
+}
+
+void CModuleChooserButton::updateMenuItems() {
+ QString moduleName;
+ CSwordModuleInfo* module = 0;
+ QList<CSwordModuleInfo*> chosenModules = m_moduleChooserBar->getModuleList();
+
+ //for ( QMenu* popup = m_submenus.first(); popup; popup = m_submenus.next() ) {
+ QListIterator<QMenu*> it(m_submenus);
+ while (it.hasNext()) {
+ QMenu* popup = it.next();
+ foreach (QAction* action, popup->actions()) {
+ moduleName = action->text();
+ moduleName.remove(QChar('&')); //remove Hotkey indicator
+ module = backend()->findModuleByName( moduleName.left(moduleName.lastIndexOf(" ")) );
+
+ //Q_ASSERT(module);
+ if (!module) qWarning("Can't find module with name %s", moduleName.toLatin1().data());
+
+ bool alreadyChosen = chosenModules.contains( module );
+ if (m_module) {
+ alreadyChosen = alreadyChosen && (m_module->name() != moduleName);
+ }
+ //grey it out, it was chosen already
+ action->setEnabled(!alreadyChosen);
+ }
+ }
+}
diff --git a/src/frontend/displaywindow/cmodulechooserbutton.h b/src/frontend/displaywindow/cmodulechooserbutton.h
new file mode 100644
index 0000000..7715bf3
--- /dev/null
+++ b/src/frontend/displaywindow/cmodulechooserbutton.h
@@ -0,0 +1,82 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CMODULECHOOSERBUTTON_H
+#define CMODULECHOOSERBUTTON_H
+
+//BibleTime includes
+class CSwordModuleInfo;
+#include "backend/btmoduletreeitem.h"
+#include "util/cpointers.h"
+
+//Qt includes
+#include <QToolButton>
+#include <QList>
+
+class QMenu;
+class CModuleChooserBar;
+
+/** The CModuleChooserButton displays a list of submenus sorted by language which contain the possible modules
+ * which can be displayed together with the first one.
+ * @author The BibleTime team
+ */
+class CModuleChooserButton : public QToolButton, public CPointers {
+ Q_OBJECT
+public:
+
+ /** Filter out modules of wrong type. See populateMenu() and BTModuleTreeItem. */
+ struct TypeFilter : public BTModuleTreeItem::Filter {
+ TypeFilter(CSwordModuleInfo::ModuleType t) {m_mType = t;}
+ bool filter(CSwordModuleInfo* mi) { return (mi->type() == m_mType); }
+ CSwordModuleInfo::ModuleType m_mType;
+ };
+
+ CModuleChooserButton(CSwordModuleInfo* useModule, CSwordModuleInfo::ModuleType type, const int id, CModuleChooserBar *parent);
+ ~CModuleChooserButton();
+
+ CSwordModuleInfo* module();
+ /**
+ * Returns the id used for this button.
+ */
+ int getId() const;
+ void updateMenuItems();
+
+protected:
+ /** Populates the menu with language submenus and module items. */
+ void populateMenu();
+ /** Adds items to the menu recursively. */
+ void addItemToMenu(BTModuleTreeItem* item, QMenu* menu);
+
+private:
+ /**
+ * Returns the icon used for the current status.
+ */
+ const QString iconName();
+
+ bool m_hasModule;
+ int m_id;
+ QAction* m_noneAction;
+ CSwordModuleInfo::ModuleType m_moduleType;
+ CSwordModuleInfo* m_module;
+
+ QMenu* m_popup;
+ QList<QMenu*> m_submenus;
+
+ CModuleChooserBar* m_moduleChooserBar;
+
+
+private slots:
+ void moduleChosen(QAction* action );
+
+signals:
+ void sigRemoveButton(const int ID);
+ void sigAddButton();
+ void sigChanged();
+};
+#endif
diff --git a/src/frontend/displaywindow/cplainwritewindow.cpp b/src/frontend/displaywindow/cplainwritewindow.cpp
new file mode 100644
index 0000000..9f12020
--- /dev/null
+++ b/src/frontend/displaywindow/cplainwritewindow.cpp
@@ -0,0 +1,183 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cplainwritewindow.h"
+#include "btactioncollection.h"
+
+#include "frontend/display/cwritedisplay.h"
+
+#include "frontend/keychooser/ckeychooser.h"
+#include "frontend/profile/cprofilewindow.h"
+#include "backend/config/cbtconfig.h"
+
+#include "backend/keys/cswordkey.h"
+
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+
+#include <QRegExp>
+#include <QToolBar>
+#include <QMessageBox>
+#include <QDebug>
+#include <QAction>
+
+using namespace Profile;
+
+CPlainWriteWindow::CPlainWriteWindow(QList<CSwordModuleInfo*> moduleList, CMDIArea* parent) :
+ CWriteWindow(moduleList, parent)
+{
+ setKey( CSwordKey::createInstance(moduleList.first()) );
+}
+
+
+CPlainWriteWindow::~CPlainWriteWindow() {}
+
+/** Initialize the state of this widget. */
+void CPlainWriteWindow::initView() {
+ // qWarning("CPlainWriteWindow::initView()");
+ setDisplayWidget( CDisplay::createWriteInstance(this) );
+ setCentralWidget( displayWidget()->view() );
+
+ setMainToolBar( new QToolBar(this) );
+ addToolBar(mainToolBar());
+ addToolBarBreak();
+
+ setKeyChooser( CKeyChooser::createInstance(modules(), key(), mainToolBar()) );
+ mainToolBar()->addWidget(keyChooser());
+}
+
+void CPlainWriteWindow::initToolbars() {
+ m_actions.syncWindow = new QAction(
+ //KIcon(CResMgr::displaywindows::commentaryWindow::syncWindow::icon),
+ util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::commentaryWindow::syncWindow::icon),
+ tr("Sync with active Bible"),
+ actionCollection()
+ );
+ m_actions.syncWindow->setCheckable(true);
+ m_actions.syncWindow->setShortcut(CResMgr::displaywindows::commentaryWindow::syncWindow::accel);
+ m_actions.syncWindow->setToolTip(tr("Synchronize (show the same verse) with the active Bible window"));
+ mainToolBar()->addAction(m_actions.syncWindow);
+ actionCollection()->addAction(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName, m_actions.syncWindow);
+
+
+ m_actions.saveText = new QAction(
+ //KIcon(CResMgr::displaywindows::writeWindow::saveText::icon),
+ util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::saveText::icon),
+ tr("Save text"),
+ actionCollection()
+ );
+ m_actions.saveText->setShortcut(CResMgr::displaywindows::writeWindow::saveText::accel);
+ QObject::connect(m_actions.saveText, SIGNAL(triggered()), this, SLOT(saveCurrentText()));
+ m_actions.saveText->setToolTip( tr("Save text") );
+ actionCollection()->addAction(CResMgr::displaywindows::writeWindow::saveText::actionName, m_actions.saveText);
+ mainToolBar()->addAction(m_actions.saveText);
+
+
+ m_actions.deleteEntry = new QAction(
+ //KIcon(CResMgr::displaywindows::writeWindow::deleteEntry::icon),
+ util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::deleteEntry::icon),
+ tr("Delete current entry"),
+ actionCollection()
+ );
+ m_actions.deleteEntry->setShortcut(CResMgr::displaywindows::writeWindow::deleteEntry::accel);
+ QObject::connect(m_actions.deleteEntry, SIGNAL(triggered()), this, SLOT(deleteEntry()) );
+ m_actions.deleteEntry->setToolTip( tr("Delete current entry (no undo)") );
+ actionCollection()->addAction(CResMgr::displaywindows::writeWindow::deleteEntry::actionName, m_actions.deleteEntry);
+ mainToolBar()->addAction(m_actions.deleteEntry);
+
+
+ m_actions.restoreText = new QAction(
+ //KIcon(CResMgr::displaywindows::writeWindow::restoreText::icon),
+ util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::restoreText::icon),
+ tr("Restore original text"),
+ actionCollection()
+ );
+ m_actions.restoreText->setShortcut(CResMgr::displaywindows::writeWindow::restoreText::accel);
+ QObject::connect(m_actions.restoreText, SIGNAL(triggered()), this, SLOT(restoreText()) );
+ m_actions.restoreText->setToolTip( tr("Restore original text, new text will be lost") );
+ actionCollection()->addAction(CResMgr::displaywindows::writeWindow::restoreText::actionName, m_actions.restoreText);
+ mainToolBar()->addAction(m_actions.restoreText);
+}
+
+void CPlainWriteWindow::initConnections() {
+ CWriteWindow::initConnections();
+ QObject::connect(keyChooser(), SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*)));
+ QObject::connect(displayWidget()->connectionsProxy(), SIGNAL(textChanged()), this, SLOT(textChanged()) );
+}
+
+void CPlainWriteWindow::storeProfileSettings( CProfileWindow* profileWindow ) {
+ CWriteWindow::storeProfileSettings(profileWindow);
+ profileWindow->setWindowSettings( m_actions.syncWindow->isChecked() );
+}
+
+void CPlainWriteWindow::applyProfileSettings( CProfileWindow* profileWindow ) {
+ CWriteWindow::applyProfileSettings(profileWindow);
+ if (profileWindow->windowSettings()) {
+ m_actions.syncWindow->setChecked(true);
+ }
+}
+
+/** Saves the text for the current key. Directly writes the changed text into the module. */
+void CPlainWriteWindow::saveCurrentText( const QString& /*key*/ ) {
+ QString t = ((CWriteDisplay*)displayWidget())->plainText();
+ //since t is a complete HTML page at the moment, strip away headers and footers of a HTML page
+ QRegExp re("(?:<html.*>.+<body.*>)", Qt::CaseInsensitive); //remove headers, case insensitive
+ re.setMinimal(true);
+ t.replace(re, "");
+ t.replace(QRegExp("</body></html>", Qt::CaseInsensitive), "");//remove footer
+
+ const QString& oldKey = this->key()->key();
+ if( modules().first()->isWritable() ) {
+ modules().first()->write(this->key(), t );
+ this->key()->key( oldKey );
+
+ ((CWriteDisplay*)displayWidget())->setModified(false);
+ textChanged();
+ }
+ else {
+ QMessageBox::critical( this, tr("Module not writable"),
+ QString::fromLatin1("<qt><B>%1</B><BR>%2</qt>")
+ .arg( tr("Module is not writable.") )
+ .arg( tr("Either the module may not be edited, or "
+ "you do not have write permission.") ) );
+ }
+}
+
+/** Loads the original text from the module. */
+void CPlainWriteWindow::restoreText() {
+ lookupSwordKey(key());
+ ((CWriteDisplay*)displayWidget())->setModified(false);
+ textChanged();
+}
+
+/** Is called when the current text was changed. */
+void CPlainWriteWindow::textChanged() {
+ m_actions.saveText->setEnabled( ((CWriteDisplay*)displayWidget())->isModified() );
+ m_actions.restoreText->setEnabled( ((CWriteDisplay*)displayWidget())->isModified() );
+}
+
+/** Deletes the module entry and clears the edit widget, */
+void CPlainWriteWindow::deleteEntry() {
+ modules().first()->deleteEntry( key() );
+ lookupSwordKey( key() );
+ ((CWriteDisplay*)displayWidget())->setModified(false);
+}
+
+/** Setups the popup menu of this display widget. */
+void CPlainWriteWindow::setupPopupMenu() {}
+
+bool CPlainWriteWindow::syncAllowed() const {
+ return m_actions.syncWindow->isChecked();
+}
+
+void CPlainWriteWindow::initActions() {
+}
+
+void CPlainWriteWindow::insertKeyboardActions( BtActionCollection* const ) {
+}
diff --git a/src/frontend/displaywindow/cplainwritewindow.h b/src/frontend/displaywindow/cplainwritewindow.h
new file mode 100644
index 0000000..1ed4215
--- /dev/null
+++ b/src/frontend/displaywindow/cplainwritewindow.h
@@ -0,0 +1,96 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CPLAINWRITEWINDOW_H
+#define CPLAINWRITEWINDOW_H
+
+//BibleTime includes
+#include "cwritewindow.h"
+
+
+class QAction;
+class BtActionCollection;
+
+class QString;
+
+/** The write window class which offers a plain editor for source code editing.
+ * @author The BibleTime team
+ */
+class CPlainWriteWindow : public CWriteWindow {
+ Q_OBJECT
+public:
+ CPlainWriteWindow( QList<CSwordModuleInfo*> modules, CMDIArea* parent);
+ virtual ~CPlainWriteWindow();
+
+ /**
+ * Store the settings of this window in the given CProfileWindow object.
+ */
+ virtual void storeProfileSettings( Profile::CProfileWindow* profileWindow );
+ /**
+ * Store the settings of this window in the given profile window.
+ */
+ virtual void applyProfileSettings( Profile::CProfileWindow* profileWindow );
+
+ /**
+ * Setups the popup menu of this display widget.
+ */
+ virtual void setupPopupMenu();
+ virtual bool syncAllowed() const;
+
+protected: // Protected methods
+ /**
+ * Initialize the state of this widget.
+ */
+ virtual void initView();
+ virtual void initConnections();
+ virtual void initToolbars();
+ virtual CDisplayWindow::WriteWindowType writeWindowType() {
+ return CDisplayWindow::PlainTextWindow;
+ };
+
+ /**
+ * Initializes the intern keyboard actions.
+ */
+ virtual void initActions();
+ /**
+ * Insert the keyboard accelerators of this window into the given KAccel object.
+ */
+ static void insertKeyboardActions( BtActionCollection* const a );
+
+private:
+ struct {
+ QAction* saveText;
+ QAction* deleteEntry;
+ QAction* restoreText;
+ QAction* syncWindow;
+ }
+ m_actions;
+
+protected slots: // Protected slots
+ /**
+ * Saves the text for the current key. Directly writes the changed text into the module.
+ */
+ virtual void saveCurrentText( const QString& );
+ /**
+ * Is called when the current text was changed.
+ */
+ virtual void textChanged();
+ /**
+ * Loads the original text from the module.
+ */
+ virtual void restoreText();
+ /**
+ * Deletes the module entry and clears the edit widget.
+ */
+ virtual void deleteEntry();
+};
+
+#endif
diff --git a/src/frontend/displaywindow/creadwindow.cpp b/src/frontend/displaywindow/creadwindow.cpp
new file mode 100644
index 0000000..d446d30
--- /dev/null
+++ b/src/frontend/displaywindow/creadwindow.cpp
@@ -0,0 +1,205 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//BibleTime includes
+#include "creadwindow.h"
+#include "btactioncollection.h"
+
+#include "frontend/display/bthtmlreaddisplay.h"
+typedef BtHtmlReadDisplay HTMLREADDISPLAY;
+
+#include "backend/rendering/centrydisplay.h"
+#include "backend/rendering/cdisplayrendering.h"
+#include "backend/keys/cswordkey.h"
+#include "backend/keys/cswordversekey.h"
+
+#include "frontend/cexportmanager.h"
+#include "frontend/cmdiarea.h"
+#include "frontend/profile/cprofilewindow.h"
+#include "frontend/searchdialog/csearchdialog.h"
+
+#include <QResizeEvent>
+#include <QMdiSubWindow>
+#include <QDebug>
+
+using namespace Profile;
+
+CReadWindow::CReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent)
+ : CDisplayWindow(modules,parent),
+ m_displayWidget(0)
+{
+ qDebug("CReadWindow::CReadWindow");
+ // installEventFilter(this);
+}
+
+CReadWindow::~CReadWindow() {
+ // qWarning("destructor of CReadWindow");
+}
+
+/** Sets the display widget of this display window. */
+void CReadWindow::setDisplayWidget( CDisplay* newDisplay ) {
+ Q_ASSERT(dynamic_cast<CReadDisplay*>(newDisplay));
+ CDisplayWindow::setDisplayWidget(newDisplay);
+ if (m_displayWidget) {
+ disconnect(m_displayWidget->connectionsProxy(), SIGNAL(referenceClicked(const QString&, const QString&)), this, SLOT(lookupModKey(const QString&, const QString&)));
+ disconnect(m_displayWidget->connectionsProxy(), SIGNAL(referenceDropped(const QString&)), this, SLOT(lookupKey(const QString&)));
+
+ HTMLREADDISPLAY* v = dynamic_cast<HTMLREADDISPLAY*>(m_displayWidget);
+ if (v) {
+ QObject::disconnect(v, SIGNAL(completed()), this, SLOT(slotMoveToAnchor()) );
+ }
+
+ }
+
+ m_displayWidget = (CReadDisplay*)newDisplay;
+ connect(
+ m_displayWidget->connectionsProxy(),
+ SIGNAL(referenceClicked(const QString&, const QString&)),
+ this,
+ SLOT(lookupModKey(const QString&, const QString&))
+ );
+
+ connect(
+ m_displayWidget->connectionsProxy(),
+ SIGNAL(referenceDropped(const QString&)),
+ this,
+ SLOT(lookupKey(const QString&))
+ );
+ HTMLREADDISPLAY* v = dynamic_cast<HTMLREADDISPLAY*>(m_displayWidget);
+ if (v)
+ {
+ QObject::connect(v, SIGNAL(completed()), this, SLOT(slotMoveToAnchor()) );
+ }
+}
+
+/** Lookup the given entry. */
+void CReadWindow::lookupSwordKey( CSwordKey* newKey ) {
+ qDebug() << "CReadWindow::lookup newKey" << newKey->key();
+ Q_ASSERT(newKey);
+
+ using namespace Rendering;
+
+// Q_ASSERT(isReady() && newKey && modules().first());
+ if (!isReady() || !newKey || modules().empty() || !modules().first()) {
+ return;
+ }
+
+ if (key() != newKey) {
+ key()->key(newKey->key());
+ }
+
+ //next-TODO: how about options?
+ Q_ASSERT(modules().first()->getDisplay());
+ CEntryDisplay* display = modules().first()->getDisplay();
+ if (display) { //do we have a display object?
+ displayWidget()->setText(
+ display->text(
+ modules(),
+ newKey->key(),
+ displayOptions(),
+ filterOptions()
+ )
+ );
+ }
+
+ setCaption( windowCaption() );
+
+ // moving to anchor happens in slotMoveToAnchor which catches the completed() signal from KHTMLPart
+
+ qDebug() << "CReadWindow::lookup end, key is :" << newKey->key();
+}
+
+void CReadWindow::slotMoveToAnchor()
+{
+ qDebug("CReadWindow::slotMoveToAnchor");
+ ((CReadDisplay*)displayWidget())->moveToAnchor( Rendering::CDisplayRendering::keyToHTMLAnchor(key()->key()) );
+}
+
+/** Store the settings of this window in the given CProfileWindow object. */
+void CReadWindow::storeProfileSettings(CProfileWindow * const settings) {
+ QRect rect;
+ rect.setX(parentWidget()->x());
+ rect.setY(parentWidget()->y());
+ rect.setWidth(width());
+ rect.setHeight(height());
+ settings->setGeometry(rect);
+
+ // settings->setScrollbarPositions( m_htmlWidget->view()->horizontalScrollBar()->value(), m_htmlWidget->view()->verticalScrollBar()->value() );
+ settings->setType(modules().first()->type());
+ settings->setMaximized(isMaximized() || parentWidget()->isMaximized());
+ settings->setFocus( (this == dynamic_cast<CReadWindow*>(mdi()->activeSubWindow()) ) ); //set property to true if this window is the active one.
+
+ if (key()) {
+ sword::VerseKey* vk = dynamic_cast<sword::VerseKey*>(key());
+ QString oldLang;
+ if (vk) {
+ oldLang = QString(vk->getLocale());
+ vk->setLocale("en"); //save english locale names as default!
+ }
+ settings->setKey( key()->key() );
+ if (vk) {
+ vk->setLocale(oldLang.toLatin1());
+ }
+ }
+
+ QStringList mods;
+
+ QList<CSwordModuleInfo*> allMods = modules();
+ QList<CSwordModuleInfo*>::iterator end_it = allMods.end();
+ for (QList<CSwordModuleInfo*>::iterator it(allMods.begin()); it != end_it; ++it) {
+ mods.append((*it)->name());
+ }
+ settings->setModules(mods);
+}
+
+void CReadWindow::applyProfileSettings(CProfileWindow * const settings) {
+ // parentWidget()->setUpdatesEnabled(false);
+ setUpdatesEnabled(false);
+
+ if (settings->maximized()) { //maximize this window
+ // Use parentWidget() to call showMaximized. Otherwise we'd get lot's of X11 errors
+ parentWidget()->showMaximized();
+ }
+ else {
+ const QRect rect = settings->geometry();
+ parentWidget()->resize(rect.width(), rect.height());
+ parentWidget()->move(rect.x(), rect.y());
+ }
+
+ setUpdatesEnabled(true);
+}
+
+void CReadWindow::insertKeyboardActions( BtActionCollection* const ) {}
+
+/** No descriptions */
+void CReadWindow::copyDisplayedText() {
+ CExportManager mgr(QString::null);
+ mgr.copyKey(key(), CExportManager::Text, true);
+}
+
+
+/*!
+ \fn CReadWindow::resizeEvent(QResizeEvent* e)
+ */
+void CReadWindow::resizeEvent(QResizeEvent* /*e*/) {
+ if (displayWidget()) {
+ ((CReadDisplay*)displayWidget())->moveToAnchor(Rendering::CDisplayRendering::keyToHTMLAnchor(key()->key()));
+ }
+}
+
+void CReadWindow::openSearchStrongsDialog() {
+// qWarning("looking for lemma %s", displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma].latin1() );
+ QString searchText = QString::null;
+
+ if (displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma] != QString::null) {
+ searchText.append("strong:").append(displayWidget()->getCurrentNodeInfo() [CDisplay::Lemma]);
+ }
+
+ Search::CSearchDialog::openDialog( modules(), searchText, 0 );
+}
diff --git a/src/frontend/displaywindow/creadwindow.h b/src/frontend/displaywindow/creadwindow.h
new file mode 100644
index 0000000..3630b58
--- /dev/null
+++ b/src/frontend/displaywindow/creadwindow.h
@@ -0,0 +1,79 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CREADWINDOW_H
+#define CREADWINDOW_H
+
+//BibleTime includes
+#include "cdisplaywindow.h"
+
+#include "frontend/display/cdisplay.h"
+#include "frontend/display/creaddisplay.h"
+
+
+class BtActionCollection;
+class QResizeEvent;
+
+
+/** The base class for all read-only display windows.
+ * @author The BibleTime team
+ */
+
+class CReadWindow : public CDisplayWindow {
+ Q_OBJECT
+public:
+ // static void insertKeyboardActions( KAccel* const a );
+ static void insertKeyboardActions( BtActionCollection* const a );
+
+ CReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent);
+ virtual ~CReadWindow();
+ /**
+ * Store the settings of this window in the given CProfileWindow object.
+ */
+ virtual void storeProfileSettings(Profile::CProfileWindow * const settings);
+ /**
+ * Store the settings of this window in the given CProfileWindow object.
+ */
+ virtual void applyProfileSettings(Profile::CProfileWindow * const settings);
+
+protected: // Protected methods
+ /**
+ * Sets the display widget of this display window.
+ */
+ virtual void setDisplayWidget( CDisplay* newDisplay );
+ /**
+ */
+ virtual void resizeEvent(QResizeEvent* e);
+
+protected slots:
+ /**
+ * Load the text using the key
+ */
+ virtual void lookupSwordKey( CSwordKey* );
+ /**
+ * Catch the signal when the KHTMLPart has finished the layout (anchors are not ready before that).
+ */
+ virtual void slotMoveToAnchor();
+
+ /**
+ * Update the status of the popup menu entries.
+ */
+ virtual void copyDisplayedText();
+ /** Open the search dialog with the strong info of the last clicked word.
+ *
+ */
+ void openSearchStrongsDialog();
+
+private:
+ CReadDisplay* m_displayWidget;
+};
+
+#endif
diff --git a/src/frontend/displaywindow/cwritewindow.cpp b/src/frontend/displaywindow/cwritewindow.cpp
new file mode 100644
index 0000000..0c58bf7
--- /dev/null
+++ b/src/frontend/displaywindow/cwritewindow.cpp
@@ -0,0 +1,161 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+#include "cwritewindow.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/keys/cswordversekey.h"
+
+#include "frontend/keychooser/ckeychooser.h"
+#include "frontend/profile/cprofilewindow.h"
+#include "frontend/display/cwritedisplay.h"
+
+
+#include <QMessageBox>
+
+
+using namespace Profile;
+
+CWriteWindow::CWriteWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent)
+: CDisplayWindow(modules, parent), m_writeDisplay(0) {}
+
+CWriteWindow::~CWriteWindow() {}
+
+
+void CWriteWindow::insertKeyboardActions( BtActionCollection* const ) {}
+
+void CWriteWindow::initConnections() {
+ Q_ASSERT(keyChooser());
+ QObject::connect(keyChooser(), SIGNAL(beforeKeyChange(const QString&)), this, SLOT(beforeKeyChange(const QString&)));
+}
+
+void CWriteWindow::initActions() {}
+
+
+void CWriteWindow::storeProfileSettings(CProfileWindow * const settings) {
+
+ settings->setWriteWindowType( writeWindowType() );
+
+ QRect rect;
+ rect.setX(parentWidget()->x());
+ rect.setY(parentWidget()->y());
+ rect.setWidth(width());
+ rect.setHeight(height());
+ settings->setGeometry(rect);
+
+ // settings->setScrollbarPositions( m_htmlWidget->view()->horizontalScrollBar()->value(), m_htmlWidget->view()->verticalScrollBar()->value() );
+ settings->setType(modules().first()->type());
+ settings->setMaximized(isMaximized() || parentWidget()->isMaximized());
+
+ if (key()) {
+ sword::VerseKey* vk = dynamic_cast<sword::VerseKey*>(key());
+ QString oldLang;
+ if (vk) {
+ oldLang = QString::fromLatin1(vk->getLocale());
+ vk->setLocale("en"); //save english locale names as default!
+ }
+ settings->setKey( key()->key() );
+ if (vk) {
+ vk->setLocale(oldLang.toLatin1());
+ }
+ }
+
+ QStringList mods;
+ QList<CSwordModuleInfo*> allMods = modules();
+ QList<CSwordModuleInfo*>::iterator end_it = allMods.end();
+ for (QList<CSwordModuleInfo*>::iterator it(allMods.begin()); it != end_it; ++it) {
+ mods.append((*it)->name());
+ }
+ settings->setModules(mods);
+}
+
+void CWriteWindow::applyProfileSettings(CProfileWindow * const settings) {
+ setUpdatesEnabled(false);
+
+ if (settings->maximized()) {
+ parentWidget()->showMaximized();
+ }
+ else {
+ const QRect rect = settings->geometry();
+ parentWidget()->resize(rect.width(), rect.height());
+ parentWidget()->move(rect.x(), rect.y());
+ //setGeometry( settings->geometry() );
+ }
+ // displayWidget()->view()->horizontalScrollBar()->setValue( settings->scrollbarPositions().horizontal );
+ // m_htmlWidget->view()->verticalScrollBar()->setValue( settings->scrollbarPositions().vertical );
+
+ setUpdatesEnabled(true);
+}
+
+void CWriteWindow::setDisplayWidget( CDisplay* display ) {
+ Q_ASSERT(dynamic_cast<CWriteDisplay*>(display));
+ CDisplayWindow::setDisplayWidget((CWriteDisplay*)display);
+ m_writeDisplay = (CWriteDisplay*)display;
+}
+
+void CWriteWindow::lookupSwordKey( CSwordKey* newKey ) {
+ //set the raw text to the display widget
+ if (!newKey)
+ return;
+
+ if (key() != newKey) { //set passage of newKey to key() if they're different, otherwise we'd get mixed up if we look up newkey which may have a different module set
+ key()->key(newKey->key());
+ }
+
+ if ( modules().count() ) {
+ displayWidget()->setText( key()->rawText() );
+ }
+ setCaption( windowCaption() );
+}
+
+bool CWriteWindow::queryClose() {
+ //save the text if it has changed
+ if (m_writeDisplay->isModified()) {
+ switch (QMessageBox::question( this, tr("Save Text?"), tr("Save text before closing?"), QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel, QMessageBox::Yes) ) {
+ case QMessageBox::Yes: //save and close
+ saveCurrentText();
+ m_writeDisplay->setModified( false );
+ return true;
+ case QMessageBox::No: //don't save and close
+ return true;
+ default: // cancel, don't close
+ return false;
+ }
+ }
+ return true;
+}
+
+void CWriteWindow::beforeKeyChange(const QString& key) {
+ Q_ASSERT(displayWidget());
+ Q_ASSERT(keyChooser());
+ if (!isReady()) return;
+
+ //If the text changed and we'd do a lookup ask the user if the text should be saved
+ if (modules().first() && ((CWriteDisplay*)displayWidget())->isModified()) {
+
+ switch (QMessageBox::question( this, tr("Save Text?"), tr("Save changed text?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes) ) {
+ case QMessageBox::Yes: { //save the changes
+ saveCurrentText( key );
+ break;
+ }
+ default: {// set modified to false so it won't ask again
+ ((CWriteDisplay*)displayWidget())->setModified(false);
+ break;
+ }
+ }
+ }
+}
+
+void CWriteWindow::saveCurrentText() {
+ if(key()) {
+ saveCurrentText(key()->key());
+ }
+}
+
diff --git a/src/frontend/displaywindow/cwritewindow.h b/src/frontend/displaywindow/cwritewindow.h
new file mode 100644
index 0000000..c3b47c2
--- /dev/null
+++ b/src/frontend/displaywindow/cwritewindow.h
@@ -0,0 +1,72 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CWRITEWINDOW_H
+#define CWRITEWINDOW_H
+
+//BibleTime includes
+#include "cdisplaywindow.h"
+
+
+class CWriteDisplay;
+class QString;
+class BtActionCollection;
+
+/**The base class for all write-only display windows.
+ *@author The BibleTime team
+ */
+
+class CWriteWindow : public CDisplayWindow {
+ Q_OBJECT
+public:
+ static void insertKeyboardActions( BtActionCollection* const a );
+
+ CWriteWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent);
+ virtual ~CWriteWindow();
+ /**
+ * Store the settings of this window in the given CProfileWindow object.
+ */
+ virtual void storeProfileSettings(Profile::CProfileWindow * const settings);
+ /**
+ * Store the settings of this window in the given CProfileWindow object.
+ */
+ virtual void applyProfileSettings(Profile::CProfileWindow * const settings);
+ virtual void initConnections();
+ virtual void initActions();
+
+public slots:
+ /**
+ * Look up the given key and display the text. In our case we offer to edit the text.
+ */
+ virtual void lookupSwordKey( CSwordKey* key );
+
+
+protected: // Protected methods
+ /**
+ * Saves the given text as text of the given key. Use this function
+ * as backend in each write window implementation.
+ */
+ void setDisplayWidget( CDisplay* display );
+ virtual CDisplayWindow::WriteWindowType writeWindowType() = 0;
+ virtual bool queryClose();
+ virtual void saveCurrentText( const QString& key ) = 0;
+
+protected slots:
+ /** Save text to the module
+ */
+ void saveCurrentText();
+ /**
+ */
+ virtual void beforeKeyChange(const QString&);
+
+private:
+ CWriteDisplay* m_writeDisplay;
+};
+
+#endif
diff --git a/src/frontend/htmldialogs/btaboutdialog.cpp b/src/frontend/htmldialogs/btaboutdialog.cpp
new file mode 100644
index 0000000..5e0bc91
--- /dev/null
+++ b/src/frontend/htmldialogs/btaboutdialog.cpp
@@ -0,0 +1,251 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btaboutdialog.h"
+
+#include "util/directoryutil.h"
+
+#include "swversion.h"
+
+// Forwards
+static QString make_body(const QString& content);
+static QString make_bold(const QString& content);
+static QString make_br();
+static QString make_center(const QString& content);
+static QString make_head(const QString& content);
+static QString make_html(const QString& content);
+static QString make_file_icon(const QString& icon);
+static QString make_link(const QString& link, const QString& text);
+static QString make_version();
+
+
+// Implements the Help > About dialog box
+
+BtAboutDialog::BtAboutDialog(QWidget *parent, Qt::WindowFlags wflags )
+ : BtTabHtmlDialog (tr("About BibleTime"), 5, parent, wflags)
+{
+ resize(550,340);
+ init_lic_tab();
+ init_sword_tab();
+ init_qt_tab();
+ init_contributors_tab();
+ init_bt_tab();
+}
+
+BtAboutDialog::~BtAboutDialog()
+{
+}
+
+void BtAboutDialog::init_bt_tab()
+{
+ selectTab(0);
+ setTabText("BibleTime" );
+ QString content;
+ content = make_file_icon("bibletime");
+ content += "&nbsp;&nbsp;";
+ content += make_bold("BibleTime " + make_version());
+ content = make_center(content) + make_br();
+ content += tr("BibleTime is an easy to use but powerful Bible study tool.");
+ content += make_br() + make_br();
+ content += tr("We are looking for developers and translators.");
+ content += " ";
+ content += tr("If you would like to join our team, please send an email to info@bibletime.info.");
+ content += make_br() + make_br();
+ content += tr("(c)1999-2009, The BibleTime Team");
+ content += make_br();
+ content += make_link("http://www.bibletime.info","http://www.bibletime.info");
+ QString bibletime = make_html(make_head("") + make_body(content));
+ setHtml(bibletime);
+}
+
+void BtAboutDialog::init_contributors_tab()
+{
+ selectTab(1);
+ setTabText(tr("Contributors"));
+ QString content;
+ content += make_bold(tr("The following people contributed to BibleTime:")) + make_br();
+ // sorted alphabetically (last name)
+ content += "<ul>";
+ content += "<li>Thomas Abthorpe (" + tr("documentation and translation manager") + ")</li>";
+ content += "<li>Joachim Ansorg (" + tr("project founder, developer") + ")</li>";
+ content += "<li>David Blue (" + tr("designer") + ")</li>";
+ content += "<li>Tim Brodie (" + tr("developer") + ")</li>";
+ content += "<li>Timothy R. Butler (" + tr("designer") + ")</li>";
+ content += "<li>Jim Campbell (" + tr("developer") + ")</li>";
+ content += "<li>Lee Carpenter (" + tr("developer") + ")</li>";
+ content += "<li>Jeremy Erickson (" + tr("packager") + ")</li>";
+ content += "<li>Troy A. Griffitts (" + tr("creator of The Sword Project") + ")</li>";
+ content += "<li>Martin Gruner (" + tr("project manager, developer") + ")</li>";
+ content += "<li>Thomas Hagedorn (" + tr("domain sponsor") + ")</li>";
+ content += "<li>Bob Harman (" + tr("howto") + ")</li>";
+ content += "<li>Gary Holmlund (" + tr("developer") + ")</li>";
+ content += "<li>Nikolay Igotti (" + tr("developer") + ")</li>";
+ content += "<li>Eeli Kaikkonnen (" + tr("developer") + ")</li>";
+ content += "<li>Chris Kujawa (" + tr("developer") + ")</li>";
+ content += "<li>Mark Lybarger (" + tr("developer") + ")</li>";
+ content += "<li>Luke Mauldin (" + tr("developer") + ")</li>";
+ content += "<li>James Ots (" + tr("designer") + ")</li>";
+ content += "<li>Fred Saalbach (" + tr("documentation") + ")</li>";
+ content += "<li>Gary Sims (" + tr("developer") + ")</li>";
+ content += "<li>Wolfgang Stradner (" + tr("tester, usability expert") + ")</li>";
+ content += "<li>Thorsten Uhlmann (" + tr("developer") + ")</li>";
+ content += "<li>David White (" + tr("developer") + ")</li>";
+ content += "<li>Mark Zealey (" + tr("developer") + ")</li>";
+ content += "</ul>";
+
+ content += make_bold(tr("The following people translated BibleTime into their language:")) + make_br();
+ // sorted alphabetically (last name)
+ content += "<ul>";
+ content += "<li>Horatiu Alexe</li>";
+ content += "<li>Chun-shek Chan</li>";
+ content += "<li>Ilpo Kantonen</li>";
+ content += "<li>Pavel Laukko</li>";
+ content += "<li>Piotr Markiewicz</li>";
+ content += "<li>G&eacute;za Nov&aacute;k</li>";
+ content += "<li>Gabriel P&eacute;rez</li>";
+ content += "<li>Igor Plisco</li>";
+ content += "<li>Jaak Ristioja</li>";
+ content += "<li>Igor Rykhlin</li>";
+ content += "<li>Vlad Savitsky</li>";
+ content += "<li>Johan van der Lingen</li>";
+ content += "<li>Jean Van Schaftingen</li>";
+ content += "<li>Dmitry Yurevich</li>";
+ content += "<li>Esteban Zeller</li>";
+ content += "</ul>";
+ content += make_br();
+ content += tr("Some names may be missing, please email bibletime-translations@lists.sourceforge.net if you notice errors or omissions.");
+
+ QString contributors = make_html(make_head("") + make_body(content));
+ setHtml(contributors);
+}
+
+
+void BtAboutDialog::init_sword_tab()
+{
+ selectTab(2);
+ setTabText("Sword" );
+
+ QString version( sword::SWVersion::currentVersion.getText());
+ QString content = make_br() + make_br();
+ content += make_center(make_bold(tr("SWORD library version %1").arg(version)));
+ content += make_br();
+
+ content += tr("BibleTime makes use of the SWORD Project. The SWORD Project is the CrossWire Bible Society's free Bible software project. Its purpose is to create cross-platform open-source tools-- covered by the GNU General Public License-- that allow programmers and Bible societies to write new Bible software more quickly and easily.");
+ content += make_br() + make_br();
+ content += tr("The SWORD Project") + make_br();
+ content += make_link("http://www.crosswire.org/sword/index.jsp","www.crosswire.org/sword/index.jsp");
+
+ setHtml(content);
+
+}
+
+void BtAboutDialog::init_qt_tab()
+{
+ selectTab(3);
+ setTabText("Qt");
+ QString content;
+ content += make_br() + make_br();
+ content += make_center(make_bold("Qt"));
+ content += make_br();
+ content += tr("This program uses Qt Open Source Edition version %1.").arg(qVersion());
+ //content += qVersion();
+ content += make_br() + make_br();
+ content += tr("Qt Open Source Edition is intended for the development of Open Source applications.");
+ content += " ";
+ content += tr("Qt is a C++ toolkit for cross-platform application development.");
+ content += make_br() + make_br();
+ content += tr("Please see ");
+ content += make_link("http://qtsoftware.com/company/model/","qtsoftware.com/company/model");
+ content += tr(" for an overview of Qt licensing.");
+ QString qt = make_html(make_head("") + make_body(content));
+ setHtml(qt);
+}
+
+void BtAboutDialog::init_lic_tab()
+{
+ selectTab(4);
+ setTabText(tr("License"));
+
+ QByteArray text;
+ text += tr("BibleTime is released under the GPL license.");
+ text += " ";
+ text += tr("You can download and use (but not distribute) the program for personal, private, public or commercial purposes without restrictions.");
+ text += " ";
+ text += tr("You can give away or distribute the program if you also distribute the corresponding source code.");
+ text += "<br><br>";
+ //text += tr("It is allowed to distribute software under GPL for a small fee, but it must be accompanied with the complete source code, and the fact that it is freely available with no cost must not be hidden.");
+ //text += "<br><br>";
+ text += tr("The complete legally binding license is below.");
+
+ QFile licFile(util::filesystem::DirectoryUtil::getLicenseDir().path() + "/license.html");
+ if (licFile.open(QFile::ReadOnly))
+ {
+ QByteArray html;
+ while (!licFile.atEnd())
+ {
+ QByteArray line = licFile.readLine();
+ html = html + line;
+ }
+ licFile.close();
+ html.replace("TRANSLATED TEXT", text);
+ setHtml(QString(html));
+ }
+}
+
+
+
+// Helper functions
+
+static QString make_center(const QString& content)
+{
+ return "<center>" + content + "</center>";
+}
+
+static QString make_br()
+{
+ return "<br>";
+}
+
+static QString make_bold(const QString& content)
+{
+ return "<b>" + content + "</b>";
+}
+
+static QString make_html(const QString& content)
+{
+ return "<html>" + content + "</html>";
+}
+
+static QString make_head(const QString& content)
+{
+ return "<head>" + content + "</head>";
+}
+
+static QString make_body(const QString& content)
+{
+ return "<body>" + content + "</body>";
+}
+
+static QString make_link(const QString& link, const QString& text)
+{
+ return "<a href=\"" + link + "\">" + text +"</a>";
+}
+
+static QString make_version()
+{
+// return "";
+ return BT_VERSION;
+}
+
+static QString make_file_icon(const QString& icon)
+{
+ QString dir = "<img src=file://" + util::filesystem::DirectoryUtil::getIconDir().path();
+ return dir + "/" + icon +".png >";
+}
+
diff --git a/src/frontend/htmldialogs/btaboutdialog.h b/src/frontend/htmldialogs/btaboutdialog.h
new file mode 100644
index 0000000..067cad7
--- /dev/null
+++ b/src/frontend/htmldialogs/btaboutdialog.h
@@ -0,0 +1,29 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTABOUTDIALOG_H
+#define BTABOUTDIALOG_H
+
+#include "bttabhtmldialog.h"
+
+class BtAboutDialog : public BtTabHtmlDialog
+{
+ Q_OBJECT
+
+ public:
+ BtAboutDialog(QWidget *parent=0, Qt::WindowFlags wflags = Qt::Dialog);
+ ~BtAboutDialog();
+ void init_bt_tab();
+ void init_contributors_tab();
+ void init_sword_tab();
+ void init_qt_tab();
+ void init_lic_tab();
+};
+
+#endif
diff --git a/src/frontend/htmldialogs/bttabhtmldialog.cpp b/src/frontend/htmldialogs/bttabhtmldialog.cpp
new file mode 100644
index 0000000..f8a83f7
--- /dev/null
+++ b/src/frontend/htmldialogs/bttabhtmldialog.cpp
@@ -0,0 +1,140 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "bttabhtmldialog.h" // See this file for more documentation of BtTabHtmlDialog
+#include "util/dialogutil.h"
+#include "util/directoryutil.h"
+
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QVBoxLayout>
+#include <QWebView>
+#include <QMenu>
+#include <QTabWidget>
+#include <QDesktopServices>
+#include <QContextMenuEvent>
+
+BtTabHtmlDialog::BtTabHtmlDialog
+ (const QString& title, int tabs, QWidget *parent, Qt::WindowFlags wflags )
+ : QDialog(parent, wflags), m_webView(0), m_tabWidget(0), m_tabs(tabs)
+{
+ //Set the flag to destroy when closed
+ setAttribute(Qt::WA_DeleteOnClose);
+ setWindowTitle(title);
+ resize(400, 300);
+
+ QVBoxLayout *vboxLayout = new QVBoxLayout(this);
+ if (tabs == 0)
+ {
+ m_webView = new BtWebView(this);
+ init_connections(m_webView);
+ vboxLayout->addWidget(m_webView);
+ m_webView->setHtml("Hi");
+ }
+ else
+ {
+ m_tabWidget = new QTabWidget(this);
+ vboxLayout->addWidget(m_tabWidget);
+ for (int i=0; i<tabs; i++)
+ {
+ QWebView* webView = new BtWebView(this);
+ init_connections(webView);
+ webView->setObjectName("View" + QString::number(i));
+ webView->setHtml(" ");
+ m_tabWidget->addTab(webView,"Tab" + QString::number(i));
+ m_tabWidget->show();
+ }
+ }
+
+ QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, this);
+ util::prepareDialogBox(buttonBox);
+ vboxLayout->addWidget(buttonBox);
+
+ bool ok;
+ ok = connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ Q_ASSERT(ok);
+ ok = connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+ Q_ASSERT(ok);
+}
+
+BtTabHtmlDialog::~BtTabHtmlDialog()
+{
+}
+
+void BtTabHtmlDialog::init_connections(QWebView* webView)
+{
+ webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
+ bool ok = connect(webView, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClicked(QUrl)));
+ Q_ASSERT(ok);
+}
+
+void BtTabHtmlDialog::linkClicked(const QUrl url)
+{
+ QDesktopServices::openUrl(url);
+}
+
+void BtTabHtmlDialog::selectTab(int tab)
+{
+ Q_ASSERT(tab >= 0 && tab < m_tabWidget->count());
+ m_tabWidget->setCurrentIndex(tab);
+}
+
+QWebView* BtTabHtmlDialog::webView()
+{
+ QWebView* webview = 0;
+ if (m_tabs == 0)
+ webview = m_webView;
+ else
+ {
+ QWidget* widget = m_tabWidget->currentWidget();
+ QString name = widget->objectName();
+ webview = qobject_cast<QWebView*>(widget);
+ }
+ Q_ASSERT(webview != 0);
+ return webview;
+}
+
+void BtTabHtmlDialog::setHtml(const QString& html, const QUrl& baseUrl)
+{
+ QUrl url = baseUrl;
+ if (url == QUrl())
+ {
+ QString dir = "file://" + util::filesystem::DirectoryUtil::getIconDir().path();
+ url.setUrl(dir);
+ }
+ webView()->setHtml(html,url);
+}
+
+void BtTabHtmlDialog::setUrl(const QUrl& url)
+{
+ webView()->setUrl(url);
+}
+
+void BtTabHtmlDialog::setTabText(const QString& tabName)
+{
+ Q_ASSERT(m_tabs != 0); // There are no tabs to name
+ int index = m_tabWidget->currentIndex();
+ m_tabWidget->setTabText(index,tabName);
+}
+
+// ******************* BtWebView *******************
+
+BtWebView::BtWebView(QWidget* parent)
+ : QWebView(parent), m_popup(0)
+{
+ m_popup = new QMenu(this);
+ QAction* copyAction = pageAction(QWebPage::Copy);
+ m_popup->addAction(copyAction);
+}
+
+void BtWebView::contextMenuEvent(QContextMenuEvent* event)
+{
+ m_popup->exec(event->globalPos());
+}
+
diff --git a/src/frontend/htmldialogs/bttabhtmldialog.h b/src/frontend/htmldialogs/bttabhtmldialog.h
new file mode 100644
index 0000000..2b40f12
--- /dev/null
+++ b/src/frontend/htmldialogs/bttabhtmldialog.h
@@ -0,0 +1,87 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTTABDIALOG_H
+#define BTTABDIALOG_H
+
+#include <QDialog>
+#include <QString>
+#include <QUrl>
+#include <QWebView>
+
+class QTabWidget;
+class QMenu;
+
+// This class creates a dialog with zero or more tabs. For zero tabs it is
+// just a single QWebView inside the dialog. For 1 or more tabs, each tab
+// contains a separate QWebView. Each QWebView can have either plain text or
+// html text. The class will automatically delete itself when closed.
+// The class can either be directly called or subclassed. The dialog is not modal.
+
+// Typical direct usage:
+//
+// Zero tabs
+// BtTabHtmlDialog* dlg = new BtTabHtmlDialog("My Title", 0, parent);
+// dlg->setHtml(htmlText);
+// dlg->show();
+//
+// or
+//
+// Two tabs
+// BtTabHtmlDialog* dlg = new BtTabHtmlDialog("My Title", 2, parent);
+// dlg->selectTab(0);
+// dlg->setTabText(nameOfTab0);
+// dlg->setHtml(htmlText0);
+// dlg->selectTab(1);
+// dlg->setTabText(nameOfTab1);
+// dlg->setHtml(htmlText1);
+// dlg->show();
+
+
+class BtTabHtmlDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ BtTabHtmlDialog(const QString& title, int numberTabs, QWidget *parent=0, Qt::WindowFlags wflags = Qt::Dialog);
+ ~BtTabHtmlDialog();
+ void selectTab(int tab);
+ void setTabText(const QString& tabName);
+
+// See QWebView::setHtml()
+ void setHtml(const QString& html, const QUrl& baseUrl=QUrl());
+
+// See QWebView::setUrl()
+ void setUrl(const QUrl& url);
+
+private slots:
+ void linkClicked(const QUrl url);
+
+private:
+ void init_connections(QWebView* webView);
+ QWebView* webView();
+
+ QWebView* m_webView;
+ QTabWidget* m_tabWidget;
+ int m_tabs;
+};
+
+
+class BtWebView : public QWebView
+{
+public:
+ BtWebView(QWidget* parent=0);
+
+protected:
+ void contextMenuEvent(QContextMenuEvent* event);
+
+private:
+ QMenu* m_popup;
+};
+
+#endif
diff --git a/src/frontend/keychooser/bthistory.cpp b/src/frontend/keychooser/bthistory.cpp
new file mode 100644
index 0000000..7eae47f
--- /dev/null
+++ b/src/frontend/keychooser/bthistory.cpp
@@ -0,0 +1,130 @@
+//
+// C++ Implementation: BTHistory
+//
+// Description:
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include "bthistory.h"
+
+#include "backend/keys/cswordkey.h"
+
+
+#include <QAction>
+#include <QList>
+
+#include <QDebug>
+
+
+BTHistory::BTHistory(QWidget* parent)
+ : m_historyList(),
+ m_index(-1),
+ m_inHistoryFunction(false)
+{
+ setParent(parent);
+ Q_ASSERT(class_invariant());
+}
+
+void BTHistory::add(CSwordKey* newKey) {
+ qDebug("BTHistory::add");
+ Q_ASSERT(newKey);
+ // Add new key Action after current index if we were not using the history functions,
+ // if it's not a duplicate and if it's not empty.
+ if (!m_inHistoryFunction && ((m_index < 0) || (newKey->key() != m_historyList.at(m_index)->text()) ))
+ {
+ if (!newKey->key().isEmpty()) {
+ m_historyList.insert(++m_index, new QAction(newKey->key(), this));
+ }
+ // TODO: history limit?
+ sendChangedSignal();
+ }
+ Q_ASSERT(class_invariant());
+}
+
+void BTHistory::move(QAction* historyItem)
+{
+ qDebug("BTHistory::move");
+ //Q_ASSERT(historyItem);
+ Q_ASSERT(m_historyList.count());
+
+ m_inHistoryFunction = true;
+ //find the action in the list
+ m_index = m_historyList.indexOf(historyItem);
+ //move to the selected item in the list, it will be the current item
+ QString newKey = m_historyList.at(m_index)->text();
+ emit historyMoved(newKey); // signal to "outsiders"; key has been changed
+ sendChangedSignal();
+
+ m_inHistoryFunction = false;
+ Q_ASSERT(class_invariant());
+}
+
+void BTHistory::back()
+{
+ qDebug("BTHistory::back");
+ if ( m_index >= 1) {
+ move(m_historyList.at(m_index-1));
+ }
+ Q_ASSERT(class_invariant());
+}
+
+void BTHistory::fw()
+{
+ qDebug("BTHistory::fw");
+ if (m_index < (m_historyList.size()-1)) {
+ move(m_historyList.at(m_index+1));
+ }
+ Q_ASSERT(class_invariant());
+}
+
+QList<QAction*> BTHistory::getBackList()
+{
+ qDebug("BTHistory::getBackList");
+
+ QList<QAction*> list;
+ for (int i = m_index-1; i >= 0; --i) {
+ list.append(m_historyList.at(i));
+ }
+
+ qDebug() << "return:" << list;
+ Q_ASSERT(class_invariant());
+ return list;
+}
+
+QList<QAction*> BTHistory::getFwList()
+{
+ qDebug("BTHistory::getFwList");
+
+ QList<QAction*> list;
+ //qDebug() << "historyList.size:" << m_historyList.size();
+ for (int i = m_index+1; i < m_historyList.size(); ++i) {
+ //qDebug() << "i:" << i;
+ list.append(m_historyList.at(i));
+ }
+ qDebug() << "return:" << list;
+
+ Q_ASSERT(class_invariant());
+ return list;
+}
+
+void BTHistory::sendChangedSignal()
+{
+ bool backEnabled = m_index > 0; //there are items in the back list
+ bool fwEnabled = m_historyList.size() > m_index+1; //there are items in the fw list
+ emit historyChanged(backEnabled, fwEnabled);
+ Q_ASSERT(class_invariant());
+}
+
+bool BTHistory::class_invariant()
+{
+ for (int i = 0; i < m_historyList.size(); ++i) {
+ if (!m_historyList.at(i) || m_historyList.at(i)->text().isEmpty()) return false;
+ }
+ if (!(m_index >= -1 && m_index < m_historyList.size())) return false;
+ return true;
+}
diff --git a/src/frontend/keychooser/bthistory.h b/src/frontend/keychooser/bthistory.h
new file mode 100644
index 0000000..34e5fdb
--- /dev/null
+++ b/src/frontend/keychooser/bthistory.h
@@ -0,0 +1,80 @@
+//
+// C++ Interface: BTHistory
+//
+// Description:
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef BTHISTORY_H
+#define BTHISTORY_H
+
+#include <QList>
+#include <QObject>
+
+
+class CSwordKey;
+class QAction;
+class QWidget;
+
+class BTHistory: public QObject
+{
+ Q_OBJECT
+
+public:
+ BTHistory(QWidget* parent);
+ ~BTHistory() {};
+
+ /**
+ * Return a list of Actions behind the current point, the first of the history list will be the
+ * last in the returned list and vice versa.
+ */
+ QList<QAction*> getBackList();
+ /**
+ * Return a list of Actions after the current point.
+ */
+ QList<QAction*> getFwList();
+
+public slots:
+ /**
+ * Add a new key to the history.
+ */
+ void add(CSwordKey* newKey);
+ /**
+ * Move the current point in history list.
+ */
+ void move(QAction*);
+ /**
+ * Go back one step in history.
+ */
+ void back();
+ /**
+ * Go forward one step in history.
+ */
+ void fw();
+
+signals:
+ /**
+ * Signal will be sent when the history has been changed (added, moved)
+ */
+ void historyChanged(bool backEnabled, bool fwEnabled);
+ /**
+ * Signal will be sent when the current point in history has moved
+ */
+ void historyMoved(QString& newKey);
+
+private:
+
+ void sendChangedSignal();
+ bool class_invariant();
+
+ QList<QAction*> m_historyList;
+ int m_index; //pointer to the current item; -1==empty, 0==first etc.
+ bool m_inHistoryFunction; //to prevent recursive behaviour
+};
+
+#endif
diff --git a/src/frontend/keychooser/cbookkeychooser.cpp b/src/frontend/keychooser/cbookkeychooser.cpp
new file mode 100644
index 0000000..411bf26
--- /dev/null
+++ b/src/frontend/keychooser/cbookkeychooser.cpp
@@ -0,0 +1,278 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+#include "cbookkeychooser.h"
+
+#include "bthistory.h"
+
+#include "backend/keys/cswordtreekey.h"
+#include "backend/drivers/cswordbookmoduleinfo.h"
+#include "backend/config/cbtconfig.h"
+
+//Qt includes
+#include <QWidget>
+#include <QHBoxLayout>
+#include <QList>
+#include <QDebug>
+
+QMap<QObject*, int> boxes;
+
+CBookKeyChooser::CBookKeyChooser(QList<CSwordModuleInfo*> modules, CSwordKey *key, QWidget *parent)
+ : CKeyChooser(modules, key, parent), m_layout(0)
+{
+
+ setModules(modules, false);
+ m_key = dynamic_cast<CSwordTreeKey*>(key);
+ if (!m_modules.count()) {
+ m_key = 0;
+ }
+
+ setModules(modules, true);
+ setKey(key);
+
+ adjustFont();
+ connect(this, SIGNAL(keyChanged(CSwordKey*)), history(), SLOT(add(CSwordKey*)) );
+}
+
+CBookKeyChooser::~CBookKeyChooser() {}
+
+void CBookKeyChooser::setKey(CSwordKey* newKey)
+{
+ setKey(newKey, true);
+}
+
+/** Sets a new key to this keychooser */
+void CBookKeyChooser::setKey(CSwordKey* newKey, const bool emitSignal)
+{
+ if (m_key != newKey) { //set the internal key to the new one
+ m_key = dynamic_cast<CSwordTreeKey*>(newKey);
+ }
+
+ QString oldKey = m_key->key(); //string backup of key
+
+ if (oldKey.isEmpty()) { //don't set keys equal to "/", always use a key which may have content
+ m_key->firstChild();
+ oldKey = m_key->key();
+ }
+
+ const int oldOffset = m_key->getOffset(); //backup key position
+
+ QStringList siblings; //split up key
+ if (m_key && !oldKey.isEmpty()) {
+ siblings = oldKey.split('/', QString::SkipEmptyParts);
+ }
+
+ int depth = 0;
+ int index = 0;
+
+ m_key->root(); //start iteration at root node
+
+ while( m_key->firstChild() && (depth < siblings.count()) ) {
+ QString key = m_key->key();
+ index = (depth == 0) ? -1 : 0;
+
+ bool found = false;
+
+ do { //look for matching sibling
+ ++index;
+ found = (m_key->getLocalNameUnicode() == siblings[depth]);
+ }
+ while (!found && m_key->nextSibling());
+
+ if (found)
+ key = m_key->key(); //found: change key to this level
+ else
+ m_key->key(key); //not found: restore old key
+
+ setupCombo(key, depth, index);
+
+ //last iteration: check to see if another box can be filled with child entries
+ if (depth == siblings.count()-1 && m_key->hasChildren())
+ {
+ m_key->firstChild();
+ setupCombo(m_key->key(), ++depth, 0);
+ }
+
+ depth++;
+ }
+
+ //clear the combos which were not filled
+ for (; depth < m_modules.first()->depth(); ++depth) {
+ CKeyChooserWidget* chooser = m_chooserWidgets.at(depth);
+ if (chooser) chooser->reset(0,0,false);
+ }
+
+ if (oldKey.isEmpty()) {
+ m_key->root();
+ }
+ else {
+ //m_key->key(oldKey);
+ m_key->setOffset(oldOffset);
+ }
+
+ if (emitSignal) emit keyChanged(m_key);
+}
+
+/** Returns the key of this kechooser. */
+CSwordKey* CBookKeyChooser::key()
+{
+ return m_key;
+}
+
+/** Sets another module to this keychooser */
+void CBookKeyChooser::setModules(const QList<CSwordModuleInfo*>& modules, const bool refresh)
+{
+ m_modules.clear();
+
+ // for (modules.first(); modules.current(); modules.next()) {
+ QList<CSwordModuleInfo*>::const_iterator end_it = modules.end();
+ for (QList<CSwordModuleInfo*>::const_iterator it(modules.begin()); it != end_it; ++it) {
+ if ( (*it)->type() == CSwordModuleInfo::GenericBook ) {
+ if (CSwordBookModuleInfo* book = dynamic_cast<CSwordBookModuleInfo*>(*it)) {
+ m_modules.append(book);
+ }
+ }
+ }
+
+ //refresh the number of combos
+ if (refresh && m_modules.count() && m_key) {
+ if (!m_layout) {
+ m_layout = new QHBoxLayout(this);
+ m_layout->setSpacing(0);
+ m_layout->setContentsMargins(0,0,0,0);
+ }
+
+ qDeleteAll(m_chooserWidgets);
+ m_chooserWidgets.clear();
+
+ for (int i = 0; i < m_modules.first()->depth(); ++i) {
+ // Create an empty keychooser, don't handle next/prev signals
+ CKeyChooserWidget* w = new CKeyChooserWidget(0, false, this);
+ m_chooserWidgets.append( w );
+
+ //don't allow a too high width, try to keep as narrow as possible
+ //to aid users with smaller screen resolutions
+ int totalWidth = 200; //only 1 level
+ if (m_modules.first()->depth() > 1) {
+ if (m_modules.first()->depth() > 3)
+ totalWidth = 400; //4+ levels
+ else
+ totalWidth = 300; //2-3 levels
+ }
+
+ int maxWidth = (int) ((float) totalWidth / (float) m_modules.first()->depth());
+
+ w->comboBox()->setMaximumWidth(maxWidth);
+ w->comboBox()->setCurrentIndex(0);
+
+ connect(w, SIGNAL(changed(int)), SLOT(keyChooserChanged(int)));
+ connect(w, SIGNAL(focusOut(int)), SLOT(keyChooserChanged(int)));
+
+ m_layout->addWidget(w);
+ boxes[w] = i;
+
+ w->show();
+ }
+
+ //set the tab order of the key chooser widgets
+
+ CKeyChooserWidget* chooser = 0;
+ CKeyChooserWidget* chooser_prev = 0;
+ const int count = m_chooserWidgets.count();
+ for (int i = 0; i < count; ++i) {
+ chooser = m_chooserWidgets.at(i);
+ Q_ASSERT(chooser);
+
+ if (chooser && chooser_prev) {
+ QWidget::setTabOrder(chooser_prev, chooser);
+ }
+
+ chooser_prev = chooser;
+ }
+ QWidget::setTabOrder(chooser, 0);
+
+ updateKey(m_key);
+ adjustFont(); // only when refresh is set.
+ }
+}
+
+/** No descriptions */
+void CBookKeyChooser::adjustFont()
+{
+ //Make sure the entries are displayed correctly.
+ QListIterator<CKeyChooserWidget*> it(m_chooserWidgets);
+ while (it.hasNext()) {
+ it.next()->comboBox()->setFont( CBTConfig::get( m_modules.first()->language() ).second );
+ }
+}
+
+/** Refreshes the content. */
+void CBookKeyChooser::refreshContent()
+{
+ if (m_key) {
+ updateKey( m_key ); //refresh with current key
+ }
+}
+
+void CBookKeyChooser::setupCombo(const QString key, const int depth, const int currentItem)
+{
+ CKeyChooserWidget* chooserWidget = m_chooserWidgets.at(depth);
+
+ CSwordTreeKey tmpKey(*m_key);
+ tmpKey.key(key);
+ tmpKey.parent();
+ tmpKey.firstChild();
+
+ QStringList items;
+ if (depth > 0) items << QString::null; //insert an empty item at the top
+
+ do {
+ items << tmpKey.getLocalNameUnicode();
+ }
+ while (tmpKey.nextSibling());
+
+ if (chooserWidget) chooserWidget->reset(items,currentItem,false);
+}
+
+/** A keychooser changed. Update and emit a signal if necessary. */
+void CBookKeyChooser::keyChooserChanged(int /*newIndex*/)
+{
+ const int activeID = boxes[const_cast<QObject*>(sender())]; //no so good code!
+
+ QStringList items;
+ CKeyChooserWidget* chooser;
+
+ for (int i = 0; i < m_chooserWidgets.count(); ++i) {
+ chooser = m_chooserWidgets.at(i);
+ const QString currentText = (chooser && chooser->comboBox()) ? chooser->comboBox()->currentText() : QString::null;
+
+ if (currentText.isEmpty() || i > activeID) {
+ break;
+ }
+
+ items << currentText;
+ }
+
+ QString newKey("/");
+ newKey.append(items.join("/"));
+
+ m_key->key(newKey);
+ setKey(m_key);
+}
+
+/** Updates the keychoosers for the given key but emit no signal. */
+void CBookKeyChooser::updateKey(CSwordKey* key)
+{
+ setKey(key, false);
+}
+
+void CBookKeyChooser::setKey(QString& newKey)
+{
+ m_key->key(newKey);
+ setKey(m_key);
+}
diff --git a/src/frontend/keychooser/cbookkeychooser.h b/src/frontend/keychooser/cbookkeychooser.h
new file mode 100644
index 0000000..80dd03f
--- /dev/null
+++ b/src/frontend/keychooser/cbookkeychooser.h
@@ -0,0 +1,86 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CBOOKKEYCHOOSER_H
+#define CBOOKKEYCHOOSER_H
+
+//BibleTime includes
+#include "ckeychooser.h"
+#include "ckeychooserwidget.h"
+
+#include <QList>
+
+class CSwordKey;
+class CSwordBookModuleInfo;
+class CSwordTreeKey;
+
+namespace sword {
+ class TreeKeyIdx;
+}
+
+/** The keychooser implementation for books.
+ * @author The BibleTime team
+ */
+class CBookKeyChooser : public CKeyChooser {
+ Q_OBJECT
+public:
+ CBookKeyChooser(QList<CSwordModuleInfo*> modules, CSwordKey *key=0, QWidget *parent=0);
+ ~CBookKeyChooser();
+ /**
+ * Refreshes the content.
+ */
+ virtual void refreshContent();
+ /**
+ * Sets another module to this keychooser
+ */
+ virtual void setModules(const QList<CSwordModuleInfo*>& modules, const bool refresh = false);
+ /**
+ * Returns the key of this keychooser
+ */
+ virtual CSwordKey* key();
+ /**
+ * Sets a new key to this keychooser
+ */
+ virtual void setKey(CSwordKey*);
+ /**
+ * Sets a new key to this keychooser
+ */
+ void setKey(CSwordKey*, const bool emitSignal);
+
+
+public slots: // Public slots
+ /**
+ * Updates the keychoosers for the given key but emit no signal.
+ */
+ void updateKey(CSwordKey*);
+
+protected: // Protected methods
+ /**
+ * Fills the combo given by depth with the items from the key having depth "depth".
+ * The parent sibling is given by key.
+ */
+ void setupCombo(const QString key, const int depth, const int currentItem);
+ /** No descriptions */
+ virtual void adjustFont();
+
+protected slots:
+ /**
+ * A keychooser changed. Update and emit a signal if necessary.
+ */
+ void keyChooserChanged(int);
+ virtual void setKey(QString& newKey);
+
+private:
+ QList<CKeyChooserWidget*> m_chooserWidgets;
+ QList<CSwordBookModuleInfo*> m_modules;
+ CSwordTreeKey *m_key;
+ QHBoxLayout* m_layout;
+};
+
+#endif
diff --git a/src/frontend/keychooser/cbooktreechooser.cpp b/src/frontend/keychooser/cbooktreechooser.cpp
new file mode 100644
index 0000000..7297d76
--- /dev/null
+++ b/src/frontend/keychooser/cbooktreechooser.cpp
@@ -0,0 +1,200 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+#include "cbooktreechooser.h"
+
+#include "bthistory.h"
+
+#include "backend/keys/cswordtreekey.h"
+#include "backend/drivers/cswordbookmoduleinfo.h"
+#include "backend/config/cbtconfig.h"
+
+#include <QHBoxLayout>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+#include <QHeaderView>
+#include <QApplication>
+
+#include <QDebug>
+
+CBookTreeChooser::CBookTreeChooser(QList<CSwordModuleInfo*> modules, CSwordKey *key, QWidget *parent)
+: CKeyChooser(modules, key, parent),
+m_key( dynamic_cast<CSwordTreeKey*>(key) ) {
+
+ setModules(modules, false);
+
+ //if there is no module there is no key either
+ if (!modules.count()) {
+ m_modules.clear();
+ m_key = 0;
+ }
+
+ //now setup the keychooser widgets
+ m_treeView = new QTreeWidget(this);
+
+ QHBoxLayout* layout = new QHBoxLayout(this);
+ layout->setSpacing(0);
+ layout->setContentsMargins(0,0,0,0);
+ layout->addWidget(m_treeView);
+ m_treeView->header()->hide();
+
+ //when user selects the item whe must react
+ connect(m_treeView, SIGNAL(currentItemChanged ( QTreeWidgetItem*, QTreeWidgetItem*)), SLOT(itemActivated(QTreeWidgetItem*)));
+
+ setKey(key);
+ adjustFont();
+ connect(this, SIGNAL(keyChanged(CSwordKey*)), history(), SLOT(add(CSwordKey*)) );
+}
+
+CBookTreeChooser::~CBookTreeChooser() {}
+
+/** Sets a new key to this keychooser. Inherited from ckeychooser. */
+void CBookTreeChooser::setKey(CSwordKey* key) {
+ setKey(key, false);
+}
+
+/** Sets a new key to this keychooser. Inherited from ckeychooser. */
+void CBookTreeChooser::setKey(CSwordKey* newKey, const bool emitSignal) {
+ qDebug("CBookTreeChooser::setKey");
+
+ if (m_key != newKey ) {
+ m_key = dynamic_cast<CSwordTreeKey*>(newKey);
+ }
+
+ const QString key = m_key->key(); //key as text, path
+
+ QTreeWidgetItem* matching_item = m_treeView->topLevelItem(0);
+
+ QTreeWidgetItemIterator it(m_treeView);
+ while (*it) {
+ if ((*it)->text(1) == key)
+ {
+ matching_item = (*it);
+ break;
+ }
+ ++it;
+ }
+
+ m_treeView->setCurrentItem( matching_item );
+ m_treeView->scrollToItem(matching_item);
+
+ if (emitSignal) {
+ emit keyChanged(m_key);
+ }
+}
+
+/** Returns the key of this keychooser. Inherited from ckeychooser.*/
+CSwordKey* CBookTreeChooser::key() {
+ return m_key;
+}
+
+/** Sets another module to this keychooser. Inherited from ckeychooser (therefore
+the list of modules instead of one). */
+void CBookTreeChooser::setModules(const QList<CSwordModuleInfo*>& modules, const bool refresh) {
+
+ //Add given modules into private list
+ m_modules.clear();
+ QList<CSwordModuleInfo*>::const_iterator end_it = modules.end();
+ for (QList<CSwordModuleInfo*>::const_iterator it(modules.begin()); it != end_it; ++it) {
+ if (CSwordBookModuleInfo* book = dynamic_cast<CSwordBookModuleInfo*>(*it)) {
+ m_modules.append(book);
+ }
+ }
+
+ //if there exists a module and a key, setup the visible tree
+ if (refresh && m_modules.count() && m_key) {
+ const uint offset = m_key->getOffset(); //actually unnecessary, taken care of in setupTree
+ setupTree();
+ m_key->setOffset( offset );
+
+ adjustFont(); //only when refresh is set.
+ }
+}
+
+/** From ckeychooser. */
+void CBookTreeChooser::adjustFont() {
+ //Make sure the entries are displayed correctly.
+ m_treeView->setFont( CBTConfig::get(m_modules.first()->language()).second );
+
+}
+
+
+/** Refreshes the content. Inherited from ckeychooser. */
+void CBookTreeChooser::refreshContent() {
+ if (m_key) {
+ updateKey(m_key); //refresh with current key
+ }
+}
+
+
+//TODO: itemActivated is called too many times. As tested in GDB, the function
+//is called twice with the pointer to the correct book and twice with a null
+//pointer.
+
+/** Slot for signal when item is selected by user. */
+void CBookTreeChooser::itemActivated( QTreeWidgetItem* item ) {
+ qDebug("CBookTreeChooser::itemActivated");
+ //Sometimes Qt calls this function with a null pointer.
+ if (item){
+ m_key->key(item->text(1));
+ //tell possible listeners about the change
+ emit keyChanged(m_key);
+ }
+}
+
+/** Inherited from ckeychooser */
+void CBookTreeChooser::updateKey( CSwordKey* key ) {
+ setKey(key, false);
+}
+
+/** Reimplementation to handle tree creation on show. */
+void CBookTreeChooser::show() {
+ CKeyChooser::show();
+
+ if (!m_treeView->topLevelItemCount()) {
+ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+ setupTree(); //create the tree structure
+ m_treeView->resize(m_treeView->sizeHint());
+ QApplication::restoreOverrideCursor();
+ }
+}
+
+/** Creates the tree structure in the view. */
+void CBookTreeChooser::setupTree() {
+ m_treeView->clear();
+
+ const unsigned long offset = m_key->getOffset();
+
+ m_key->root();
+ addKeyChildren(m_key, m_treeView->invisibleRootItem());
+
+ m_key->setOffset( offset );
+ setKey(m_key, false); //the module may have changed
+}
+
+/** Populates tree widget with items. */
+void CBookTreeChooser::addKeyChildren(CSwordTreeKey* key, QTreeWidgetItem* item) {
+ if (key->hasChildren()) {
+ key->firstChild();
+ do {
+ QStringList columns;
+ columns << key->getLocalNameUnicode() << key->key();
+ QTreeWidgetItem *i = new QTreeWidgetItem(item, columns, QTreeWidgetItem::Type);
+ i->setData(0, Qt::ToolTipRole, key->getLocalNameUnicode());
+ int offset = key->getOffset();
+ addKeyChildren(key, i);
+ key->setOffset(offset);
+ } while (key->nextSibling());
+ }
+}
+
+void CBookTreeChooser::setKey(QString& newKey)
+{
+ m_key->key(newKey);
+ setKey(m_key);
+}
diff --git a/src/frontend/keychooser/cbooktreechooser.h b/src/frontend/keychooser/cbooktreechooser.h
new file mode 100644
index 0000000..455ba01
--- /dev/null
+++ b/src/frontend/keychooser/cbooktreechooser.h
@@ -0,0 +1,87 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CBOOKTREECHOOSER_H
+#define CBOOKTREECHOOSER_H
+
+
+/** The treechooser implementation for books.
+ * @author The BibleTime team
+ */
+//BibleTime includes
+#include "ckeychooser.h"
+#include "ckeychooserwidget.h"
+
+
+class CSwordKey;
+class CSwordBookModuleInfo;
+class CSwordTreeKey;
+
+namespace sword {
+ class TreeKeyIdx;
+}
+
+class QTreeWidget;
+class QTreeWidgetItem;
+
+/** The keychooser implementation for books.
+ * @author The BibleTime team
+ */
+class CBookTreeChooser : public CKeyChooser {
+ Q_OBJECT
+public:
+ CBookTreeChooser(QList<CSwordModuleInfo*> modules, CSwordKey *key=0, QWidget *parent=0);
+ ~CBookTreeChooser();
+ /**
+ * Refreshes the content.
+ */
+ virtual void refreshContent();
+ /**
+ * Sets another module to this keychooser
+ */
+ virtual void setModules(const QList<CSwordModuleInfo*>& modules, const bool refresh = true);
+ /**
+ * Returns the key of this keychooser.
+ */
+ virtual CSwordKey* key();
+ /**
+ * Sets a new key to this keychooser
+ */
+ virtual void setKey(CSwordKey*);
+ void setKey(CSwordKey*, const bool emitSinal);
+
+public slots: // Public slots
+ virtual void updateKey( CSwordKey* );
+ /**
+ * Reimplementation to handle tree creation on show.
+ */
+ virtual void show();
+
+
+protected: // Protected methods
+ /**
+ * Creates the first level of the tree structure.
+ */
+ void setupTree();
+ virtual void adjustFont();
+ void addKeyChildren(CSwordTreeKey* key, QTreeWidgetItem* item);
+
+protected slots: // Protected slots
+ void itemActivated( QTreeWidgetItem* item );
+ void setKey(QString& newKey);
+
+private:
+ QList<CSwordBookModuleInfo*> m_modules;
+ CSwordTreeKey* m_key;
+ QTreeWidget* m_treeView;
+};
+
+#endif
diff --git a/src/frontend/keychooser/ckeychooser.cpp b/src/frontend/keychooser/ckeychooser.cpp
new file mode 100644
index 0000000..f0650d6
--- /dev/null
+++ b/src/frontend/keychooser/ckeychooser.cpp
@@ -0,0 +1,64 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#include "ckeychooser.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/drivers/cswordbiblemoduleinfo.h"
+#include "backend/drivers/cswordcommentarymoduleinfo.h"
+#include "backend/drivers/cswordlexiconmoduleinfo.h"
+
+#include "backend/keys/cswordkey.h"
+
+#include "bthistory.h"
+#include "clexiconkeychooser.h"
+#include "versekeychooser/cbiblekeychooser.h"
+#include "cbookkeychooser.h"
+
+#include <QAction>
+#include <QDebug>
+
+CKeyChooser::CKeyChooser(QList<CSwordModuleInfo*>, CSwordKey *, QWidget *parent)
+ : QWidget(parent),
+ m_history(0)
+{
+ //qDebug("CKeyChooser::CKeyChooser");
+ m_history = new BTHistory(this);
+ QObject::connect(history(), SIGNAL(historyMoved(QString&)), this, SLOT(setKey(QString&)));
+}
+
+CKeyChooser::~CKeyChooser() {}
+
+CKeyChooser* CKeyChooser::createInstance(QList<CSwordModuleInfo*> modules, CSwordKey *key, QWidget *parent) {
+ if (!modules.count()) {
+ return 0;
+ }
+
+ switch ( modules.first()->type() ) {
+ case CSwordModuleInfo::Commentary: //Bibles and commentaries use the same key chooser
+ case CSwordModuleInfo::Bible:
+ return new CBibleKeyChooser(modules,key,parent);
+ break;
+ case CSwordModuleInfo::Lexicon:
+ return new CLexiconKeyChooser(modules,key,parent);
+ case CSwordModuleInfo::GenericBook:
+ return new CBookKeyChooser(modules,key,parent);
+ default:
+ return 0;
+ }
+}
+
+
+BTHistory* CKeyChooser::history()
+{
+ return m_history;
+}
+
diff --git a/src/frontend/keychooser/ckeychooser.h b/src/frontend/keychooser/ckeychooser.h
new file mode 100644
index 0000000..d10a74a
--- /dev/null
+++ b/src/frontend/keychooser/ckeychooser.h
@@ -0,0 +1,115 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CKEYCHOOSER_H
+#define CKEYCHOOSER_H
+
+
+class CSwordModuleInfo;
+
+#include <QWidget>
+
+
+class CSwordKey;
+class QAction;
+
+class BTHistory;
+
+
+/**
+ * The base class for the KeyChooser.
+ * Do not use directly, create a KeyChooser with
+ * @ref #createInstance , this will create the proper one
+ * of the classes that inherit from @ref CKeyChooser
+ *
+ * @author The BibleTime team
+ */
+
+class CKeyChooser : public QWidget {
+ Q_OBJECT
+
+public:
+
+ /**
+ * Creates a proper Instance, either
+ *
+ @ref CLexiconKeyChooser or
+ * @ref CBibleKeyChooser
+ * @param info the @ref CModuleInfo to be represented by the KeyChooser
+ * @param key if not NULL, the @ref CKey the KeyChooser should be set to
+ * @param parent the parent of the widget to create
+ */
+ static CKeyChooser* createInstance(QList<CSwordModuleInfo*> modules, CSwordKey *key, QWidget *parent);
+
+
+public slots:
+ /**
+ * sets the @ref CKey
+ * @param key the key which the widget should be set to
+ */
+ virtual void setKey(CSwordKey* key) = 0;
+ /**
+ * sets the @ref CKey
+ * @param key the key which the widget should be set to
+ */
+ virtual void updateKey(CSwordKey* key) = 0;
+ /**
+ * gets the current @ref CKey
+ *
+ * @return the current @ref CKey
+ */
+ virtual CSwordKey* key() = 0;
+ /**
+ * Sets the module of this keychooser and refreshes the comboboxes
+ */
+ virtual void setModules( const QList<CSwordModuleInfo*>& modules, const bool refresh = true ) = 0;
+ /**
+ * Freshes the content of the different key chooser parts.
+ */
+ virtual void refreshContent() = 0;
+
+ /**
+ * Returns the history object of this keychooser.
+ */
+ BTHistory* history();
+
+signals:
+
+ /**
+ * is emitted if the @ref CKey was changed by the user
+ */
+ void keyChanged(CSwordKey* newKey);
+ /**
+ * Is emitted before the key is changed!
+ */
+ void beforeKeyChange(const QString& key);
+
+protected:
+
+ /**
+ * the constructor - DO NOT USE! -- use @ref #createInstance instead!
+ */
+ CKeyChooser(QList<CSwordModuleInfo*> info, CSwordKey *key=0, QWidget *parent=0);
+ virtual ~CKeyChooser();
+ /**
+ * Set the appropriate font do display the modules
+ */
+ virtual void adjustFont() = 0;
+
+protected slots:
+ virtual void setKey(QString& newKey) = 0;
+
+private:
+ BTHistory* m_history;
+
+};
+
+#endif
diff --git a/src/frontend/keychooser/ckeychooserwidget.cpp b/src/frontend/keychooser/ckeychooserwidget.cpp
new file mode 100644
index 0000000..dd8f7a5
--- /dev/null
+++ b/src/frontend/keychooser/ckeychooserwidget.cpp
@@ -0,0 +1,304 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+//BibleTime includes
+#include "ckeychooserwidget.h"
+
+#include "cscrollerwidgetset.h"
+
+//Qt includes
+#include <QString>
+#include <QWheelEvent>
+#include <QFocusEvent>
+#include <QHBoxLayout>
+#include <QComboBox>
+#include <QLineEdit>
+#include <QDebug>
+
+CKCComboBox::CKCComboBox()
+: QComboBox() {
+ setFocusPolicy(Qt::WheelFocus);
+ if (lineEdit()) {
+ installEventFilter( lineEdit() );
+ }
+}
+
+/** Reimplementation. */
+bool CKCComboBox::eventFilter( QObject *o, QEvent *e ) {
+ if (e->type() == QEvent::FocusOut) {
+ QFocusEvent* f = static_cast<QFocusEvent*>(e);
+
+ if (o == lineEdit() && f->reason() == Qt::TabFocusReason) {
+ int index = findText(currentText());
+ if (index == -1) {
+ index = 0;// return 0 if not found
+ }
+ setCurrentIndex( index );
+ emit focusOut( index );
+
+ return false;
+ }
+ else if (f->reason() == Qt::PopupFocusReason) {
+ return false;
+ }
+ else if (f->reason() == Qt::ActiveWindowFocusReason) {
+ emit activated(currentText());
+ return false;
+ }
+ else if (f->reason() == Qt::MouseFocusReason) {
+ emit activated(currentText());
+ return false;
+ }
+ else if (o == this) {
+ emit activated(currentText());
+ return false;
+ }
+ }
+
+ return QComboBox::eventFilter(o,e);
+}
+
+/** Scrolls in the list if the wheel of the mouse was used. */
+void CKCComboBox::wheelEvent( QWheelEvent* e ) {
+ return QComboBox::wheelEvent(e);
+
+ const signed int change = (int)((float)e->delta()/(float)120);
+ int current = currentIndex();
+
+ if ((current+change >= 0) && (current+change<count()) ) {
+ setCurrentIndex(current+change);
+ e->accept();
+ emit activated( currentIndex() );
+ }
+ else {
+ e->ignore();
+ }
+}
+
+//**********************************************************************************/
+
+CKeyChooserWidget::CKeyChooserWidget(int count, const bool useNextPrevSignals, QWidget *parent ) : QWidget(parent) {
+ m_useNextPrevSignals = useNextPrevSignals;
+
+ for (int index=1; index <= count; index++) {
+ m_list.append( QString::number(index) );
+ }
+ init();
+ reset(m_list,0,false);
+}
+
+CKeyChooserWidget::CKeyChooserWidget(QStringList *list, const bool useNextPrevSignals, QWidget *parent ) : QWidget(parent) {
+ m_useNextPrevSignals = useNextPrevSignals;
+
+ if (list) {
+ m_list = *list; //deep copy the items of list
+ }
+ else {
+ m_list.clear();
+ }
+
+ init();
+ reset(m_list,0,false);
+}
+
+void CKeyChooserWidget::reset(const int count, int index, bool do_emit) {
+ //This prevents the widget from resetting during application load, which
+ //produces undesirable behavior.
+ //if (!updatesEnabled())
+ // return;
+
+ m_list.clear();
+ for (int i=1; i <= count; i++) { //TODO: CHECK
+ m_list.append( QString::number(i) );
+ }
+
+ reset(&m_list,index,do_emit);
+}
+
+void CKeyChooserWidget::reset(QStringList& list, int index, bool do_emit) {
+ //This prevents the widget from resetting during application load, which
+ //produces undesirable behavior.
+ //if (!updatesEnabled())
+ // return;
+
+ m_list = list;
+ reset(&m_list,index,do_emit);
+}
+
+
+void CKeyChooserWidget::reset(QStringList *list, int index, bool do_emit) {
+ //if (isResetting || !updatesEnabled())
+ if (isResetting)
+ return;
+
+ // qWarning("starting insert");
+ isResetting = true;
+
+ oldKey = QString::null;
+
+ // m_comboBox->setUpdatesEnabled(false);
+ //DON'T REMOVE THE HIDE: Otherwise QComboBox's sizeHint() function won't work properly
+ m_comboBox->hide();
+ m_comboBox->clear();
+ if (list) {
+ m_comboBox->insertItems(-1, *list);
+ }
+
+ if (!list || (list && !list->count())) { //nothing in the combobox
+ setEnabled(false);
+ }
+ else if (!isEnabled()) { //was disabled
+ setEnabled(true);
+ }
+
+ if (list->count()) {
+ m_comboBox->setCurrentIndex(index);
+ }
+ if (do_emit) {
+ emit changed(m_comboBox->currentIndex());
+ }
+
+ const QSize dummySize = m_comboBox->sizeHint(); //without this function call the combo box won't be properly sized!
+ //DON'T REMOVE OR MOVE THE show()! Otherwise QComboBox's sizeHint() function won't work properly!
+ m_comboBox->show();
+
+ // m_comboBox->setFont( m_comboBox->font() );
+ // m_comboBox->setUpdatesEnabled(true);
+
+ isResetting = false;
+ // qWarning("inserted");
+}
+
+/** Initializes this widget. We need this function because we have more than one constructor. */
+void CKeyChooserWidget::init() {
+ qDebug("CKeyChooserWidget::init");
+ oldKey = QString::null;
+
+ setFocusPolicy(Qt::WheelFocus);
+
+ m_comboBox = new CKCComboBox();
+ m_comboBox->setAutoCompletion( true );
+ m_comboBox->setEditable(true);
+ m_comboBox->setInsertPolicy(QComboBox::NoInsert);
+ m_comboBox->setFocusPolicy(Qt::WheelFocus);
+
+ m_mainLayout = new QHBoxLayout( this );
+ m_mainLayout->setSpacing(0);
+ m_mainLayout->setContentsMargins(0,0,0,0);
+ m_mainLayout->addWidget(m_comboBox);
+
+ m_scroller = new CScrollerWidgetSet(this);
+
+ m_mainLayout->addWidget( m_scroller );
+ m_mainLayout->addSpacing(0);
+
+ setTabOrder(m_comboBox, 0);
+
+ connect(m_scroller, SIGNAL(scroller_pressed()), SLOT(lock()));
+ connect(m_scroller, SIGNAL(scroller_released()), SLOT(unlock()));
+ connect(m_scroller, SIGNAL(change(int)), SLOT(changeCombo(int)) );
+
+ connect(m_comboBox, SIGNAL(activated(int)), SLOT(slotComboChanged(int)));
+ // connect(m_comboBox, SIGNAL(activated(const QString&)), SLOT(slotReturnPressed(const QString&)));
+ connect(m_comboBox->lineEdit(), SIGNAL(returnPressed()), SLOT(slotReturnPressed()));
+ connect(m_comboBox, SIGNAL(focusOut(int)), SIGNAL(focusOut(int)));
+
+ updatelock = false;
+ isResetting = false;
+}
+
+/** Is called when the return key was presed in the combobox. */
+void CKeyChooserWidget::slotReturnPressed( /*const QString& text*/) {
+ Q_ASSERT(comboBox()->lineEdit());
+ qDebug("return pressed");
+
+ QString text = comboBox()->lineEdit()->text();
+ for (int index = 0; index < comboBox()->count(); ++index) {
+ if (comboBox()->itemText(index) == text) {
+// emit changed(index);
+ emit focusOut(index); // a workaround because focusOut is not checked, the slot connected to changed to check
+ break;
+ }
+ }
+}
+
+/** Is called when the current item of the combo box was changed. */
+void CKeyChooserWidget::slotComboChanged(int index) {
+ qDebug("CKeyChooserWidget::slotComboChanged(int index)");
+ if (!updatesEnabled()) {
+ return;
+ }
+
+ setUpdatesEnabled(false);
+
+ const QString key = comboBox()->itemText( index );
+ if (oldKey.isNull() || (oldKey != key)) {
+ emit changed(index);
+ }
+
+ oldKey = key;
+
+ setUpdatesEnabled(true);
+}
+
+/** Sets the tooltips for the given entries using the parameters as text. */
+void CKeyChooserWidget::setToolTips( const QString comboTip, const QString nextEntryTip, const QString scrollButtonTip, const QString previousEntryTip) {
+ comboBox()->setToolTip(comboTip);
+ m_scroller->setToolTips(nextEntryTip, scrollButtonTip, previousEntryTip);
+}
+
+/** Sets the current item to the one with the given text */
+bool CKeyChooserWidget::setItem( const QString item ) {
+ bool ret = false;
+ const int count = comboBox()->count();
+ for (int i = 0; i < count; ++i) {
+ if (comboBox()->itemText(i) == item) {
+ comboBox()->setCurrentIndex(i);
+ ret = true;
+ break;
+ }
+ }
+ if (!ret)
+ comboBox()->setCurrentIndex(-1);
+ return ret;
+}
+
+/* Handlers for the various scroller widgetset. */
+void CKeyChooserWidget::lock() {
+ updatelock = true;
+ comboBox()->setEditable(false);
+ oldKey = comboBox()->currentText();
+}
+
+void CKeyChooserWidget::unlock() {
+ updatelock = false;
+ comboBox()->setEditable(true);
+ comboBox()->setEditText(comboBox()->itemText(comboBox()->currentIndex()));
+ if (comboBox()->currentText() != oldKey) {
+ emit changed(comboBox()->currentIndex());
+ }
+}
+
+void CKeyChooserWidget::changeCombo(int n) {
+ const int old_index = comboBox()->currentIndex();
+ int new_index = old_index + n;
+
+ //index of highest Item
+ const int max = comboBox()->count()-1;
+ if(new_index > max) new_index = max;
+ if(new_index < 0) new_index = 0;
+
+ if(new_index != old_index) {
+ comboBox()->setCurrentIndex(new_index);
+ if(!updatelock)
+ emit changed(new_index);
+ }
+}
+
diff --git a/src/frontend/keychooser/ckeychooserwidget.h b/src/frontend/keychooser/ckeychooserwidget.h
new file mode 100644
index 0000000..05b0236
--- /dev/null
+++ b/src/frontend/keychooser/ckeychooserwidget.h
@@ -0,0 +1,171 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CKEYCHOOSERWIDGET_H
+#define CKEYCHOOSERWIDGET_H
+
+
+#include <QString>
+#include <QStringList>
+#include <QComboBox>
+
+class QWheelEvent;
+class QHBoxLayout;
+class QWidget;
+class QObject;
+class QEvent;
+
+class CLexiconKeyChooser;
+class CScrollerWidgetSet;
+/*
+* We use this class to conrtol the focus move in the combobox
+* This class is used in the key chooser widgets
+*/
+class CKCComboBox : public QComboBox {
+ Q_OBJECT
+
+public:
+ CKCComboBox();
+ /**
+ * Returns the size this widget would like to have.
+ */
+ // virtual QSize sizeHint() const;
+
+protected:
+ /**
+ * Reimplementation.
+ */
+ virtual bool eventFilter( QObject *o, QEvent *e );
+ /**
+ * Scrolls in the list if the wheel of the mouse was used.
+ */
+ virtual void wheelEvent( QWheelEvent* e);
+
+signals:
+ /**
+ * Emitted when the user moves the focus away from the combo by pressing tab
+ */
+ void focusOut(int itemIndex);
+};
+
+/**
+ * This class implements the KeyCooser Widget, which
+ * consists of a @ref QComboBox, two normal ref @QToolButton
+ * and a enhanced @ref CScrollButton
+ *
+ * @author The BibleTime team
+ */
+class CKeyChooserWidget : public QWidget {
+ Q_OBJECT
+public:
+ /**
+ * the constructor
+ */
+ CKeyChooserWidget(QStringList *list=0, const bool useNextPrevSignals = false, QWidget *parent=0 );
+ /**
+ * the constructor
+ */
+ CKeyChooserWidget(int count=0, const bool useNextPrevSignals = false, QWidget *parent=0 );
+ /**
+ * This function does clear the combobox, then fill in
+ * the StringList, set the ComboBox' current item to index
+ * and if do_emit is true, it will emit @ref #changed
+ *
+ * @param list the stringlist to be inserted
+ * @param index the index that the combobox is to jump to
+ * @param do_emit should we emit @ref #changed(int)
+ */
+ void reset(const int count, int index, bool do_emit);
+ void reset(QStringList& list, int index, bool do_emit);
+ void reset(QStringList *list, int index, bool do_emit);
+ /**
+ * Initializes this widget. We need this function because
+ * we have more than one constructor.
+ */
+ virtual void init();
+ /**
+ *
+ */
+ // virtual void adjustSize();
+ /**
+ * Sets the tooltips for the given entries using the parameters as text.
+ */
+ void setToolTips( const QString comboTip, const QString nextEntry, const QString scrollButton, const QString previousEntry);
+ /**
+ * Sets the current item to the one with the given text
+ */
+ bool setItem( const QString item);
+ /**
+ * Return the combobox of this key chooser widget.
+ */
+ QComboBox* comboBox() {return m_comboBox;};
+
+public slots:
+ /**
+ * is called to lock the combobox
+ */
+ void lock()
+ ;
+ /**
+ * is called to unlock the combobox
+ */
+ void unlock();
+ /**
+ * is called to move the combobox to a certain index
+ * @param index the index to jump to
+ */
+ void changeCombo(int index);
+ void slotComboChanged(int index);
+
+signals:
+ /**
+ * Is emitted if the widget changed, but
+ * only if it is not locked or being reset
+ *
+ * @param the current ComboBox index
+ */
+ void changed(int index);
+ /**
+ * Is emitted if the widget was left with a focus out event.
+ * @param index The new index of the ComboBox
+ */
+ void focusOut(int index);
+
+protected:
+ /**
+ * indicates wheter we are resetting at the moment
+ */
+ bool isResetting;
+ /**
+ *
+ */
+ QString oldKey;
+
+protected slots: // Protected slots
+ /**
+ * Is called when the return key was presed in the combobox.
+ */
+ void slotReturnPressed( /*const QString&*/ );
+
+
+private:
+ friend class CLexiconKeyChooser;
+ QStringList m_list;
+ bool m_useNextPrevSignals;
+ bool updatelock;
+
+ /**
+ * Members should never be public!!
+ */
+ CKCComboBox* m_comboBox;
+ QHBoxLayout *m_mainLayout;
+ CScrollerWidgetSet * m_scroller;
+};
+
+#endif
diff --git a/src/frontend/keychooser/clexiconkeychooser.cpp b/src/frontend/keychooser/clexiconkeychooser.cpp
new file mode 100644
index 0000000..00c02ba
--- /dev/null
+++ b/src/frontend/keychooser/clexiconkeychooser.cpp
@@ -0,0 +1,180 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#include "clexiconkeychooser.h"
+
+#include "bthistory.h"
+#include "ckeychooserwidget.h"
+#include "cscrollbutton.h"
+
+#include "backend/drivers/cswordlexiconmoduleinfo.h"
+#include "backend/keys/cswordldkey.h"
+#include "backend/config/cbtconfig.h"
+#include "util/cresmgr.h"
+
+//STL headers
+#include <algorithm>
+#include <iterator>
+#include <map>
+
+#include <QHBoxLayout>
+
+
+CLexiconKeyChooser::CLexiconKeyChooser(QList<CSwordModuleInfo*> modules, CSwordKey *key, QWidget *parent)
+ : CKeyChooser(modules, key, parent),
+ m_key(dynamic_cast<CSwordLDKey*>(key))
+{
+ setModules(modules, false);
+
+ //we use a layout because the key chooser should be resized to full size
+ m_layout = new QHBoxLayout(this);
+ m_layout->setSpacing(0);
+ m_layout->setContentsMargins(0,0,0,0);
+ m_layout->setDirection(QBoxLayout::LeftToRight);
+ m_layout->setSizeConstraint(QLayout::SetNoConstraint);
+
+ m_widget = new CKeyChooserWidget(0, false, this);
+
+ //don't allow a too high width, try to keep as narrow as possible
+ //to aid users with smaller screen resolutions
+ m_widget->comboBox()->setMaximumWidth(200);
+
+ m_widget->setToolTips(
+ tr("Entries of the current work"),
+ tr("Next entry"),
+ tr("Scroll through the entries of the list. Press the button and move the mouse to increase or decrease the item."),
+ tr("Previous entry")
+ );
+
+ m_layout->addWidget(m_widget,0,Qt::AlignLeft);
+
+ connect(m_widget,SIGNAL(changed(int)),SLOT(activated(int)));
+ connect(m_widget,SIGNAL(focusOut(int)),SLOT(activated(int)));
+
+ setModules(modules, true);
+ setKey(key);
+ connect(this, SIGNAL(keyChanged(CSwordKey*)), history(), SLOT(add(CSwordKey*)) );
+}
+
+CSwordKey* CLexiconKeyChooser::key() {
+ // qWarning("key");
+ return m_key;
+}
+
+void CLexiconKeyChooser::setKey(CSwordKey* key)
+{
+ qDebug("CLexiconKeyChooser::setKey");
+
+ if (!(m_key = dynamic_cast<CSwordLDKey*>(key))) {
+ return;
+ }
+
+ QString newKey = m_key->key();
+ const int index = m_widget->comboBox()->findText(newKey);
+ m_widget->comboBox()->setCurrentIndex(index);
+
+ // qWarning("setKey end");
+ emit keyChanged( m_key);
+}
+
+void CLexiconKeyChooser::activated(int index) {
+ // qWarning("activated");
+ const QString text = m_widget->comboBox()->itemText(index);
+
+ // To prevent from eternal loop, because activated() is emitted again
+ if (m_key && m_key->key() != text) {
+ m_key->key(text);
+ setKey(m_key);
+ }
+ // qWarning("activated end");
+}
+
+inline bool my_cmpEntries(const QString& a, const QString& b) {
+ return a < b;
+}
+
+/** Reimplementation. */
+void CLexiconKeyChooser::refreshContent() {
+ if (m_modules.count() == 1) {
+ m_widget->reset(m_modules.first()->entries(), 0, true);
+ // qWarning("resetted");
+ }
+ else {
+ typedef std::multimap<unsigned int, QStringList*> EntryMap;
+ EntryMap entryMap;
+ QStringList* entries = 0;
+ QListIterator<CSwordLexiconModuleInfo*> mit(m_modules);
+ while (mit.hasNext()) {
+ entries = mit.next()->entries();
+ entryMap.insert( std::make_pair(entries->count(), entries) );
+ }
+
+ QStringList goodEntries; //The string list which contains the entries which are available in all modules
+
+ EntryMap::iterator it = entryMap.begin(); //iterator to go thoigh all selected modules
+ QStringList refEntries = *(it->second); //copy the items for the first time
+ QStringList* cmpEntries = ( ++it )->second; //list for comparision, starts with the second module in the map
+
+ while(it != entryMap.end()) {
+ std::set_intersection(
+ refEntries.begin(), --(refEntries.end()), //--end() is the last valid entry
+ cmpEntries->begin(), --(cmpEntries->end()),
+ std::back_inserter(goodEntries), //append valid entries to the end of goodEntries
+ my_cmpEntries //ci_cmpEntries is the comparision function
+ );
+
+ cmpEntries = ( ++it )->second; //this is a pointer to the string list of a new module
+
+ /*
+ * use the good entries for next comparision,
+ * because the final list can only have the entries of goodEntries as maxiumum
+ */
+ refEntries = goodEntries;
+ };
+
+ m_widget->reset(goodEntries, 0, true); //write down the entries
+ } //end of ELSE
+
+}
+
+/** No descriptions */
+void CLexiconKeyChooser::adjustFont() {
+
+}
+
+/** Sets the module and refreshes the combo boxes */
+void CLexiconKeyChooser::setModules( const QList<CSwordModuleInfo*>& modules, const bool refresh ) {
+
+ while (!m_modules.isEmpty())
+ m_modules.takeFirst(); // not deleting the pointer
+
+ QList<CSwordModuleInfo*>::const_iterator end_it = modules.end();
+ for (QList<CSwordModuleInfo*>::const_iterator it(modules.begin()); it != end_it; ++it) {
+ CSwordLexiconModuleInfo* lexicon = dynamic_cast<CSwordLexiconModuleInfo*>(*it);
+ if (lexicon) {
+ m_modules.append(lexicon);
+ }
+ }
+
+ if (refresh) {
+ refreshContent();
+ // adjustFont();
+ }
+}
+
+/** No descriptions */
+void CLexiconKeyChooser::updateKey(CSwordKey*) {}
+
+void CLexiconKeyChooser::setKey(QString& newKey)
+{
+ m_key->key(newKey);
+ setKey(m_key);
+}
diff --git a/src/frontend/keychooser/clexiconkeychooser.h b/src/frontend/keychooser/clexiconkeychooser.h
new file mode 100644
index 0000000..a75ce37
--- /dev/null
+++ b/src/frontend/keychooser/clexiconkeychooser.h
@@ -0,0 +1,86 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CLEXICONKEYCHOOSER_H
+#define CLEXICONKEYCHOOSER_H
+
+
+#include "ckeychooser.h"
+class CSwordModuleInfo;
+
+
+class CKeyChooserWidget;
+class CSwordLexiconModuleInfo;
+class CSwordLDKey;
+
+class QWidget;
+class QHBoxLayout;
+
+/**
+ * This class implements the KeyChooser for lexicons
+ *
+ * it inhertits @ref CKeyChooser
+ * it uses 1 @ref CKeyChooserWidget to represent the lexicon keys
+ *
+ * @author The BibleTime team
+ */
+class CLexiconKeyChooser : public CKeyChooser {
+ Q_OBJECT
+public:
+ /**
+ * The constructor
+ *
+ * you should not need to use this, use @ref CKeyChooser::createInstance instead
+ */
+ CLexiconKeyChooser(QList<CSwordModuleInfo*> modules, CSwordKey *key=0, QWidget *parent=0);
+
+public slots:
+ /**
+ * see @ref CKeyChooser::getKey
+ * @return Return the key object we use.
+ */
+ virtual CSwordKey* key();
+ /**
+ * see @ref CKeyChooser::setKey
+ */
+ virtual void setKey(CSwordKey* key);
+ /**
+ * used to react to changes in the @ref CKeyChooserWidget
+ *
+ * @param index not used
+ **/
+ virtual void activated(int index);
+ /**
+ * Reimplementation.
+ */
+ virtual void refreshContent();
+ /**
+ * Sets the module and refreshes the combo boxes of this keychooser.
+ */
+ virtual void setModules( const QList<CSwordModuleInfo*>& modules, const bool refresh = true );
+
+protected:
+ CKeyChooserWidget *m_widget;
+ CSwordLDKey* m_key;
+ QList<CSwordLexiconModuleInfo*> m_modules;
+ QHBoxLayout *m_layout;
+
+ virtual void adjustFont();
+
+public slots: // Public slots
+ virtual void updateKey(CSwordKey* key);
+
+protected slots:
+ virtual void setKey(QString& newKey);
+
+};
+
+#endif
diff --git a/src/frontend/keychooser/cscrollbutton.cpp b/src/frontend/keychooser/cscrollbutton.cpp
new file mode 100644
index 0000000..742bc53
--- /dev/null
+++ b/src/frontend/keychooser/cscrollbutton.cpp
@@ -0,0 +1,85 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#include "cscrollbutton.h"
+
+
+#include <stdlib.h>
+#include <math.h>
+
+//Qt includes
+#include <QEvent>
+#include <QApplication>
+#include <QCursor>
+#include <QPoint>
+#include <QMouseEvent>
+#include <QWheelEvent>
+
+CScrollButton::CScrollButton(QWidget *parent) : QToolButton(parent) {
+ setFocusPolicy(Qt::WheelFocus);
+ setCursor(Qt::SplitVCursor );
+
+ m_isLocked = false;
+ connect(this, SIGNAL(pressed() ), SLOT(was_pressed() ));
+ connect(this, SIGNAL(released()), SLOT(was_released()));
+}
+
+bool CScrollButton::isLocked( ) const {
+ return m_isLocked;
+}
+
+void CScrollButton::was_pressed( ) {
+ QApplication::setOverrideCursor(Qt::BlankCursor);
+ m_isLocked = true;
+ lock_Point = get_lock_Point();
+
+ emit lock()
+ ;
+}
+
+void CScrollButton::was_released( ) {
+ QApplication::restoreOverrideCursor();
+ m_isLocked = false;
+
+ emit unlock();
+}
+
+const QPoint CScrollButton::get_lock_Point() const {
+ return mapToGlobal( QPoint( width()/2, height()/2 ) );
+}
+
+void CScrollButton::mouseMoveEvent( QMouseEvent* e ) {
+ if (m_isLocked) {
+ int vchange = (QCursor::pos().y() - lock_Point.y());
+
+ if (abs(vchange) < 10) {
+ vchange = (int)((vchange>0 ? 1 : -1) * pow(abs(vchange), 0.3));
+ }
+ else if (abs(vchange) < 30) {
+ vchange = (int)((vchange>0 ? 1 : -1) * pow(abs(vchange), 0.6));
+ }
+ else if (abs(vchange) < 40) {
+ vchange = (int)((vchange>0 ? 1 : -1) * pow(abs(vchange), 1.2));
+ }
+ else {
+ vchange = (int)((vchange>0 ? 1 : -1) * pow(abs(vchange), 2.0));
+ }
+
+ if (vchange) { //not emit 0
+ emit change_requested( vchange );
+ }
+
+ QCursor::setPos( lock_Point );
+ }
+ else {
+ QToolButton::mouseMoveEvent(e);
+ }
+}
diff --git a/src/frontend/keychooser/cscrollbutton.h b/src/frontend/keychooser/cscrollbutton.h
new file mode 100644
index 0000000..3a38f37
--- /dev/null
+++ b/src/frontend/keychooser/cscrollbutton.h
@@ -0,0 +1,85 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CSRCOLLBUTTON_H
+#define CSRCOLLBUTTON_H
+
+
+#include <QToolButton>
+
+
+class QMouseEvent;
+class QWidget;
+class QMouseEvent;
+class QWheelEvent;
+
+/** This Class implements the direct chooser button used in the KeyChooser Widget
+ * @author The BibleTime team
+ */
+class CScrollButton : public QToolButton {
+ Q_OBJECT
+public:
+ /**
+ * The constructor
+ */
+ CScrollButton(QWidget *parent=0);
+ bool isLocked() const;
+
+signals:
+ /**
+ * is emitted when the button enters locked state
+ */
+ void lock()
+ ;
+ /**
+ * is emitted when the button leaves locked state
+ */
+ void unlock();
+ /**
+ * indicates a change the user made by moving the mouse
+ * @param count the number of items to be changed in the KeyChooser ComboBox
+ */
+ void change_requested(int count);
+
+protected slots:
+ /*
+ * used to process the button press events
+ */
+ void was_pressed();
+ /**
+ * used to process the button release events
+ */
+ void was_released();
+
+protected:
+ /**
+ * Reimplementation from @ref QWidget#mouseMoveEvent - processes
+ * the mouse move events
+ */
+ virtual void mouseMoveEvent( QMouseEvent* e );
+ /**
+ * used to find the lock point - the middle of the button
+ * @return the lock point
+ */
+ const QPoint get_lock_Point() const;
+
+private:
+ /**
+ * Indicates whether the button is in locked state or not
+ */
+ bool m_isLocked;
+ /**
+ * stores the lock point
+ */
+ QPoint lock_Point;
+};
+
+#endif
diff --git a/src/frontend/keychooser/cscrollerwidgetset.cpp b/src/frontend/keychooser/cscrollerwidgetset.cpp
new file mode 100644
index 0000000..3577803
--- /dev/null
+++ b/src/frontend/keychooser/cscrollerwidgetset.cpp
@@ -0,0 +1,87 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+//BibleTime includes
+#include "cscrollbutton.h"
+#include "cscrollerwidgetset.h"
+
+//Qt includes
+#include <QString>
+#include <QToolButton>
+#include <QVBoxLayout>
+#include <QWheelEvent>
+
+const unsigned int WIDTH = 16;
+const unsigned int ARROW_HEIGHT = 12;
+const unsigned int MOVER_HEIGHT = 6;
+
+CScrollerWidgetSet::CScrollerWidgetSet(QWidget *parent) : QWidget(parent) {
+ m_layout = new QVBoxLayout(this);
+ m_layout->setSpacing(0);
+ m_layout->setContentsMargins(0,0,0,0);
+ m_layout->setAlignment(this, Qt::AlignHCenter | Qt::AlignCenter);
+
+ btn_up = new QToolButton(this);
+ btn_up->setArrowType(Qt::UpArrow);
+
+ btn_up->setFixedSize(WIDTH, ARROW_HEIGHT);
+ btn_up->setFocusPolicy(Qt::NoFocus);
+ btn_up->setAutoRaise(true);
+
+ btn_fx = new CScrollButton(this);
+ btn_fx->setFixedSize(WIDTH, MOVER_HEIGHT);
+ btn_fx->setFocusPolicy(Qt::NoFocus);
+
+ btn_down = new QToolButton(this);
+ btn_down->setArrowType(Qt::DownArrow);
+ btn_down->setFixedSize(WIDTH, ARROW_HEIGHT);
+ btn_down->setFocusPolicy(Qt::NoFocus);
+ btn_down->setAutoRaise(true);
+
+ m_layout->addWidget( btn_up,0 );
+ m_layout->addWidget( btn_fx,0 );
+ m_layout->addWidget( btn_down,0 );
+ setMinimumWidth(WIDTH); // Kludge to add some spacing but seems to work.
+
+ connect(btn_fx, SIGNAL(lock()), SLOT(slotLock()));
+ connect(btn_fx, SIGNAL(unlock()), SLOT(slotUnlock()));
+ connect(btn_fx, SIGNAL(change_requested(int)), SLOT(slotScroller(int)));
+ connect(btn_up, SIGNAL(clicked()), SLOT(slotUpClick()));
+ connect(btn_down, SIGNAL(clicked()), SLOT(slotDownClick()));
+}
+
+/** Sets the tooltips for the given entries using the parameters as text. */
+void CScrollerWidgetSet::setToolTips( const QString nextEntryTip, const QString scrollButtonTip, const QString previousEntryTip) {
+ btn_fx->setToolTip(scrollButtonTip);
+ btn_down->setToolTip(nextEntryTip);
+ btn_up->setToolTip(previousEntryTip);
+}
+
+
+void CScrollerWidgetSet::wheelEvent( QWheelEvent* e ) {
+ /**
+ * The problem is, that wheel events do everytime have the delta value 120
+ */
+ const int vchange = ((e->delta() > 0) ? (-1) : (1));
+
+ if (vchange!=0) {//do not emit a change with value 0
+ emit change(vchange);
+ e->accept();
+ }
+ else {
+ e->ignore();
+ }
+}
+
+void CScrollerWidgetSet::slotLock() { emit scroller_pressed(); }
+void CScrollerWidgetSet::slotUnlock() { emit scroller_released(); }
+void CScrollerWidgetSet::slotScroller(int n) { emit change(n); }
+void CScrollerWidgetSet::slotUpClick() { slotScroller(-1); }
+void CScrollerWidgetSet::slotDownClick() { slotScroller(1); }
diff --git a/src/frontend/keychooser/cscrollerwidgetset.h b/src/frontend/keychooser/cscrollerwidgetset.h
new file mode 100644
index 0000000..bd482df
--- /dev/null
+++ b/src/frontend/keychooser/cscrollerwidgetset.h
@@ -0,0 +1,76 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CSCROLLERWIDGETSET_H
+#define CSCROLLERWIDGETSET_H
+
+
+#include <QWidget>
+
+
+class QVBoxLayout;
+class QToolButton;
+class QString;
+
+class CScrollButton;
+
+/**
+ * This class implements the Scroller Widget-set, which
+ * consists of two normal ref @QToolButton and a enhanced @ref CScrollButton
+ *
+ * @author The BibleTime team
+ */
+class CScrollerWidgetSet : public QWidget {
+ Q_OBJECT
+public:
+ /**
+ * the constructor
+ */
+ CScrollerWidgetSet(QWidget *parent=0);
+ /**
+ * Sets the tooltips for the given entries using the parameters as text.
+ */
+ void setToolTips( const QString nextEntry, const QString scrollButton, const QString previousEntry);
+
+signals:
+ /**
+ * is emitted to proceed to some other entry relative to the
+ * current, indicated by the int value
+ */
+ void change(int count);
+
+ /**
+ * These emit when the scroll button is pressed or released
+ */
+ void scroller_pressed();
+ void scroller_released();
+
+protected:
+
+ virtual void wheelEvent( QWheelEvent* e );
+
+ QToolButton* btn_up;
+ QToolButton* btn_down;
+ CScrollButton* btn_fx;
+
+protected slots:
+ void slotLock();
+ void slotUnlock();
+ void slotUpClick();
+ void slotDownClick();
+ void slotScroller(int);
+
+private:
+ QVBoxLayout *m_layout;
+
+};
+
+#endif
diff --git a/src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.cpp b/src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.cpp
new file mode 100644
index 0000000..e4b05c3
--- /dev/null
+++ b/src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.cpp
@@ -0,0 +1,134 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btdropdownchooserbutton.h"
+#include "ckeyreferencewidget.h"
+#include "btversekeymenu.h"
+
+#include <QWheelEvent>
+#include <QDebug>
+
+const unsigned int ARROW_HEIGHT = 12;
+
+BtDropdownChooserButton::BtDropdownChooserButton(CKeyReferenceWidget* ref)
+ : QToolButton(),
+ m_ref(ref)
+{
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+
+ setAutoRaise(true);
+ setArrowType(Qt::NoArrow);
+ setFixedHeight(ARROW_HEIGHT);
+ setFocusPolicy(Qt::NoFocus);
+ setPopupMode(QToolButton::InstantPopup);
+ setStyleSheet("QToolButton{margin:0px;}QToolButton::menu-indicator{subcontrol-position: center center;}");
+
+ BtVerseKeyMenu* m = new BtVerseKeyMenu(this);
+// KAcceleratorManager::setNoAccel(m);
+ setMenu(m);
+ QObject::connect(m, SIGNAL(triggered(QAction*)), this, SLOT(slotMenuTriggered(QAction*)));
+}
+
+
+void BtDropdownChooserButton::mousePressEvent(QMouseEvent* e)
+{
+ //qDebug("BtDropdownChooserButton::mousePressEvent");
+ //recreate the menu
+ menu()->clear();
+ this->newList();
+
+ QToolButton::mousePressEvent(e);
+}
+
+void BtDropdownChooserButton::wheelEvent(QWheelEvent* e)
+{
+ // The problem is, that wheel events do everytime have the delta value 120
+ const int vchange = ((e->delta() > 0) ? (-1) : (1));
+
+ if (vchange!=0) {//do not emit a change with value 0
+ emit stepItem(vchange);
+ e->accept();
+ }
+ else {
+ e->ignore();
+ }
+}
+
+
+//******************Book dropdown button*************************************/
+
+BtBookDropdownChooserButton::BtBookDropdownChooserButton(CKeyReferenceWidget* ref)
+ : BtDropdownChooserButton(ref)
+{
+ setToolTip(tr("Select book"));
+ QObject::connect(this, SIGNAL(stepItem(int)), m_ref, SLOT(slotStepBook(int)));
+}
+
+void BtBookDropdownChooserButton::newList()
+{
+ QMenu* m = menu();
+ QStringList* booklist = ref()->m_module->books();
+ foreach (QString bookname, *booklist) {
+ m->addAction(bookname);
+ }
+}
+
+void BtBookDropdownChooserButton::slotMenuTriggered(QAction* action)
+{
+ qDebug() << "BtBookDropdownChooserButton::slotMenuTriggered" << action->text();
+ m_ref->slotChangeBook(action->text());
+}
+
+
+//****************** Chapter dropdown button *************************************/
+
+BtChapterDropdownChooserButton::BtChapterDropdownChooserButton(CKeyReferenceWidget* ref)
+ : BtDropdownChooserButton(ref)
+{
+ setToolTip(tr("Select chapter"));
+ QObject::connect(this, SIGNAL(stepItem(int)), m_ref, SLOT(slotStepChapter(int)));
+}
+
+void BtChapterDropdownChooserButton::newList()
+{
+ QMenu* m = menu();
+ int count = ref()->m_module->chapterCount(ref()->m_key->book());
+ for (int i = 1; i <= count; i++) {
+ m->addAction(QString::number(i));
+ }
+}
+
+void BtChapterDropdownChooserButton::slotMenuTriggered(QAction* action)
+{
+ m_ref->slotChangeChapter(action->text().toInt());
+}
+
+
+//****************** Verse dropdown button *************************************/
+
+BtVerseDropdownChooserButton::BtVerseDropdownChooserButton(CKeyReferenceWidget* ref)
+ : BtDropdownChooserButton(ref)
+{
+ setToolTip(tr("Select verse"));
+ QObject::connect(this, SIGNAL(stepItem(int)), m_ref, SLOT(slotStepVerse(int)));
+}
+
+void BtVerseDropdownChooserButton::newList()
+{
+ QMenu* m = menu();
+ int count = ref()->m_module->verseCount(ref()->m_key->book(), ref()->m_key->Chapter());
+ for (int i = 1; i <= count; i++) {
+ m->addAction(QString::number(i));
+ }
+}
+
+void BtVerseDropdownChooserButton::slotMenuTriggered(QAction* action)
+{
+ m_ref->slotChangeVerse(action->text().toInt());
+}
diff --git a/src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.h b/src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.h
new file mode 100644
index 0000000..969f5c2
--- /dev/null
+++ b/src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.h
@@ -0,0 +1,79 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTDROPDOWNCHOOSERBUTTON_H
+#define BTDROPDOWNCHOOSERBUTTON_H
+
+
+#include <QToolButton>
+
+class CKeyReferenceWidget;
+
+/**
+* Base class for book/ch/v dropdown list chooser buttons.
+*/
+class BtDropdownChooserButton : public QToolButton
+{
+ Q_OBJECT
+public:
+ BtDropdownChooserButton(CKeyReferenceWidget* ref);
+
+ virtual ~BtDropdownChooserButton() {}
+ /** The item list is constructed here just before the menu is shown.*/
+ virtual void mousePressEvent(QMouseEvent* event);
+ /** Recreates the menu list.*/
+ virtual void newList() = 0;
+ /** Returns the verse reference widget which this button belongs to.*/
+ CKeyReferenceWidget* ref() {return m_ref;}
+public slots:
+ /** When a menu item is selected the key will be changed.*/
+ virtual void slotMenuTriggered(QAction* action) = 0;
+protected:
+ CKeyReferenceWidget* m_ref;
+ void wheelEvent(QWheelEvent* event);
+signals:
+ void stepItem(int step);
+};
+
+/** See BtDropdownChooserButton.*/
+class BtBookDropdownChooserButton : public BtDropdownChooserButton
+{
+ Q_OBJECT
+public:
+ BtBookDropdownChooserButton(CKeyReferenceWidget* ref);
+ ~BtBookDropdownChooserButton() {}
+ virtual void newList();
+public slots:
+ virtual void slotMenuTriggered(QAction* action);
+};
+
+/** See BtDropdownChooserButton.*/
+class BtChapterDropdownChooserButton : public BtDropdownChooserButton
+{
+ Q_OBJECT
+public:
+ BtChapterDropdownChooserButton(CKeyReferenceWidget* ref);
+ ~BtChapterDropdownChooserButton() {}
+ virtual void newList();
+public slots:
+ virtual void slotMenuTriggered(QAction* action);
+};
+
+/** See BtDropdownChooserButton.*/
+class BtVerseDropdownChooserButton : public BtDropdownChooserButton
+{
+ Q_OBJECT
+public:
+ BtVerseDropdownChooserButton(CKeyReferenceWidget* ref);
+ ~BtVerseDropdownChooserButton() {}
+ virtual void newList();
+public slots:
+ virtual void slotMenuTriggered(QAction* action);
+};
+#endif
diff --git a/src/frontend/keychooser/versekeychooser/btversekeymenu.cpp b/src/frontend/keychooser/versekeychooser/btversekeymenu.cpp
new file mode 100644
index 0000000..f8607e4
--- /dev/null
+++ b/src/frontend/keychooser/versekeychooser/btversekeymenu.cpp
@@ -0,0 +1,52 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btversekeymenu.h"
+
+#include <QMenu>
+#include <QTimerEvent>
+#include <QMouseEvent>
+
+#include <QDebug>
+
+BtVerseKeyMenu::BtVerseKeyMenu(QWidget* parent)
+ : QMenu(parent),
+ m_timerId(0),
+ m_firstClickLock(true)
+{
+ qDebug("BtVerseKeyMenu::BtVerseKeyMenu");
+ QObject::connect(this, SIGNAL(aboutToShow()), this, SLOT(startFirstClickDelayTimer()));
+}
+
+void BtVerseKeyMenu::startFirstClickDelayTimer()
+{
+ //qDebug() << "BtVerseKeyMenu::startFirstClickDelayTimer";
+ m_firstClickLock = true;
+ killTimer(m_timerId);
+ m_timerId = startTimer(300);
+}
+
+void BtVerseKeyMenu::timerEvent(QTimerEvent* e)
+{
+ if (e->timerId() == m_timerId) {
+ //qDebug() << "BtVerseKeyMenu::timerEvent";
+ killTimer(m_timerId);
+ m_firstClickLock = false;
+ } else {
+ QMenu::timerEvent(e);
+ }
+}
+
+void BtVerseKeyMenu::mouseReleaseEvent(QMouseEvent* e)
+{
+ //qDebug() << "BtVerseKeyMenu::mouseReleaseEvent";
+ if (m_firstClickLock) return;
+ //qDebug() << "BtVerseKeyMenu::mouseReleaseEvent 2";
+ QMenu::mouseReleaseEvent(e);
+}
diff --git a/src/frontend/keychooser/versekeychooser/btversekeymenu.h b/src/frontend/keychooser/versekeychooser/btversekeymenu.h
new file mode 100644
index 0000000..45d9385
--- /dev/null
+++ b/src/frontend/keychooser/versekeychooser/btversekeymenu.h
@@ -0,0 +1,43 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTVERSEKEYMENU_H
+#define BTVERSEKEYMENU_H
+
+#include <QMenu>
+
+class QMouseEvent;
+class QTimerEvent;
+
+/**
+* Menu for book/ch/v dropdown lists.
+*
+* This is implemented mostly because it needs a delay which prevents unwanted actions after
+* the menu has been shown and mouse button is released over some item.
+*/
+class BtVerseKeyMenu : public QMenu
+{
+ Q_OBJECT
+public:
+ BtVerseKeyMenu(QWidget* parent);
+ ~BtVerseKeyMenu(){}
+protected:
+ virtual void mouseReleaseEvent(QMouseEvent* event);
+ /** Frees the mouse button release after the delay has elapsed.*/
+ virtual void timerEvent(QTimerEvent* event);
+private slots:
+ /** Starts the delay timer for the first mouse button release.*/
+ void startFirstClickDelayTimer();
+
+private:
+ int m_timerId;
+ bool m_firstClickLock;
+};
+
+#endif
diff --git a/src/frontend/keychooser/versekeychooser/cbiblekeychooser.cpp b/src/frontend/keychooser/versekeychooser/cbiblekeychooser.cpp
new file mode 100644
index 0000000..2bc9e77
--- /dev/null
+++ b/src/frontend/keychooser/versekeychooser/cbiblekeychooser.cpp
@@ -0,0 +1,108 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cbiblekeychooser.h"
+
+#include "../bthistory.h"
+#include "ckeyreferencewidget.h"
+#include "../cscrollbutton.h"
+
+#include "backend/keys/cswordversekey.h"
+#include "backend/drivers/cswordbiblemoduleinfo.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+
+#include "util/cresmgr.h"
+
+#include <QHBoxLayout>
+#include <QDebug>
+
+
+CBibleKeyChooser::CBibleKeyChooser(QList<CSwordModuleInfo*> modules, CSwordKey *key, QWidget *parent) :
+ CKeyChooser(modules, key, parent),
+ m_key(dynamic_cast<CSwordVerseKey*>(key))
+{
+ w_ref = 0;
+ setModules(modules, false);
+ if (!m_modules.count()) {
+ qWarning() << "CBibleKeyChooser: module is not a Bible or commentary!";
+ m_key = 0;
+ return;
+ }
+ QHBoxLayout* layout = new QHBoxLayout(this);
+ layout->setSpacing(0);
+ layout->setContentsMargins(0,0,0,0);
+ layout->setDirection( QBoxLayout::LeftToRight );
+
+ w_ref = new CKeyReferenceWidget(dynamic_cast<CSwordBibleModuleInfo*>(m_modules.first()), m_key, this);
+ layout->addWidget(w_ref);
+
+ connect(w_ref,SIGNAL(changed(CSwordVerseKey *)),SLOT(refChanged(CSwordVerseKey *)));
+
+ setKey(m_key); //set the key without changing it, setKey(key()) would change it
+
+ connect(this, SIGNAL(keyChanged(CSwordKey*)), history(), SLOT(add(CSwordKey*)) );
+}
+
+CSwordKey* CBibleKeyChooser::key() {
+ return m_key;
+}
+
+void CBibleKeyChooser::setKey(CSwordKey* key)
+{
+ Q_ASSERT(dynamic_cast<CSwordVerseKey*>(key));
+ if (dynamic_cast<CSwordVerseKey*>(key) == 0) return;
+
+ emit (beforeKeyChange(m_key->key())); //required to make direct setKey calls work from the outside
+ m_key = dynamic_cast<CSwordVerseKey*>(key);
+ w_ref->setKey(m_key);
+ emit keyChanged(m_key);
+}
+
+void CBibleKeyChooser::refChanged(CSwordVerseKey* key)
+{
+ Q_ASSERT(m_key);
+ Q_ASSERT(key);
+
+ if (!updatesEnabled()) return;
+
+ setUpdatesEnabled(false);
+ if (m_key) emit beforeKeyChange(m_key->key());
+ m_key = key;
+ emit keyChanged(m_key);
+
+ setUpdatesEnabled(true);
+}
+
+void CBibleKeyChooser::setModules(const QList<CSwordModuleInfo*>& modules, const bool refresh) {
+ m_modules.clear();
+
+ foreach (CSwordModuleInfo* mod, modules) {
+ if (mod->type() == CSwordModuleInfo::Bible || mod->type() == CSwordModuleInfo::Commentary) {
+ if (CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(mod)) m_modules.append(bible);
+ }
+ }
+
+ // First time this is called we havnt set up w_ref.
+ if (w_ref) w_ref->setModule(dynamic_cast<CSwordBibleModuleInfo*>(m_modules.first()));
+ if (refresh) refreshContent();
+}
+
+void CBibleKeyChooser::refreshContent() {
+ setKey(m_key);
+}
+
+void CBibleKeyChooser::updateKey(CSwordKey* /*key*/) {}
+
+void CBibleKeyChooser::adjustFont() {}
+
+void CBibleKeyChooser::setKey(QString& newKey)
+{
+ m_key->key(newKey);
+ setKey(m_key);
+}
diff --git a/src/frontend/keychooser/versekeychooser/cbiblekeychooser.h b/src/frontend/keychooser/versekeychooser/cbiblekeychooser.h
new file mode 100644
index 0000000..a410354
--- /dev/null
+++ b/src/frontend/keychooser/versekeychooser/cbiblekeychooser.h
@@ -0,0 +1,78 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CBIBLEKEYCHOOSER_H
+#define CBIBLEKEYCHOOSER_H
+
+
+#include "../ckeychooser.h"
+#include "backend/drivers/cswordbiblemoduleinfo.h"
+
+#include <QList>
+
+class QWidget;
+
+class CKeyReferenceWidget;
+class CSwordVerseKey;
+class CSwordBibleModuleInfo;
+
+/** This class implements the KeyChooser for bibles and commentaries
+ *
+ * it inhertits @ref CKeyChooser
+ *
+ * it uses a CKeyReferenceWidget 's to represent the bible keys
+ *
+ * @author The BibleTime team
+ */
+
+class CBibleKeyChooser : public CKeyChooser {
+ Q_OBJECT
+
+public:
+ /**
+ * the constructor
+ * you should not need to use this, use @ref CKeyChooser::createInstance instead
+ */
+ CBibleKeyChooser(QList<CSwordModuleInfo*> modules, CSwordKey *key=0, QWidget *parent=0);
+
+public slots:
+ /**
+ * see @ref CKeyChooser::getKey
+ */
+ CSwordKey* key();
+ /**
+ * see @ref CKeyChooser::setKey
+ */
+ virtual void setKey(CSwordKey *key);
+ /**
+ * Sets the module
+ */
+ virtual void setModules(const QList<CSwordModuleInfo*>& modules, const bool refresh = true);
+ /**
+ * used to react to changes
+ * @param index not used
+ */
+ void refChanged(CSwordVerseKey *key);
+
+ void updateKey(CSwordKey* key);
+ void adjustFont();
+ void refreshContent();
+
+protected slots:
+ virtual void setKey(QString& newKey);
+
+private:
+ CKeyReferenceWidget* w_ref;
+ QList<CSwordBibleModuleInfo*> m_modules;
+ CSwordVerseKey *m_key;
+};
+
+#endif
diff --git a/src/frontend/keychooser/versekeychooser/ckeyreferencewidget.cpp b/src/frontend/keychooser/versekeychooser/ckeyreferencewidget.cpp
new file mode 100644
index 0000000..0815a89
--- /dev/null
+++ b/src/frontend/keychooser/versekeychooser/ckeyreferencewidget.cpp
@@ -0,0 +1,229 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//BibleTime includes
+#include "ckeyreferencewidget.h"
+
+#include "../cscrollerwidgetset.h"
+#include "btdropdownchooserbutton.h"
+
+#include "backend/config/cbtconfig.h"
+
+#include "backend/keys/cswordversekey.h"
+
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+
+//Qt includes
+#include <QString>
+#include <QStringList>
+#include <QEvent>
+#include <QPixmap>
+#include <QApplication>
+#include <QHBoxLayout>
+#include <QToolButton>
+#include <QDebug>
+#include <QLineEdit>
+
+
+
+CKeyReferenceWidget::CKeyReferenceWidget( CSwordBibleModuleInfo *mod, CSwordVerseKey *key, QWidget *parent, const char* /*name*/) :
+ QWidget(parent),
+ m_key(new CSwordVerseKey(mod))
+{
+
+ updatelock = false;
+ m_module = mod;
+
+ setFocusPolicy(Qt::WheelFocus);
+
+ QToolButton* clearRef = new QToolButton(this);
+ clearRef->setIcon(util::filesystem::DirectoryUtil::getIcon("edit_clear_locationbar"));
+ clearRef->setAutoRaise(true);
+ clearRef->setStyleSheet("QToolButton{margin:0px;}");
+ connect(clearRef, SIGNAL(clicked()), SLOT(slotClearRef()) );
+
+ m_bookScroller = new CScrollerWidgetSet(this);
+
+ m_textbox = new QLineEdit( this );
+ m_textbox->setStyleSheet("QLineEdit{margin:0px;}");
+
+ setKey(key); // The order of these two functions is important.
+ setModule();
+
+ m_chapterScroller = new CScrollerWidgetSet(this);
+ m_verseScroller = new CScrollerWidgetSet(this);
+
+ m_bookDropdownButton = new BtBookDropdownChooserButton(this);
+ m_chapterDropdownButton = new BtChapterDropdownChooserButton(this);
+ m_verseDropdownButton = new BtVerseDropdownChooserButton(this);
+
+ QHBoxLayout* dropdownButtonsLayout = new QHBoxLayout();
+ QVBoxLayout* editorAndButtonsLayout = new QVBoxLayout();
+ dropdownButtonsLayout->setContentsMargins(0,0,0,0);
+ editorAndButtonsLayout->setContentsMargins(0,0,0,0);
+ dropdownButtonsLayout->setSpacing(0);
+ editorAndButtonsLayout->setSpacing(0);
+
+ dropdownButtonsLayout->addWidget(m_bookDropdownButton, 2);
+ dropdownButtonsLayout->addWidget(m_chapterDropdownButton,1);
+ dropdownButtonsLayout->addWidget(m_verseDropdownButton,1);
+ editorAndButtonsLayout->addWidget(m_textbox);
+ editorAndButtonsLayout->addLayout(dropdownButtonsLayout);
+
+ QHBoxLayout* m_mainLayout = new QHBoxLayout( this );
+ m_mainLayout->setContentsMargins(0,0,0,0);
+ m_mainLayout->setSpacing(0);
+ m_mainLayout->addWidget(clearRef);
+ m_mainLayout->addWidget(m_bookScroller);
+ m_mainLayout->addLayout(editorAndButtonsLayout);
+ m_mainLayout->addWidget(m_chapterScroller);
+ m_mainLayout->addWidget(m_verseScroller);
+
+
+ setTabOrder(m_textbox, 0);
+
+ QString scrollButtonToolTip(tr("Scroll through the entries of the list. Press the button and move the mouse to increase or decrease the item."));
+ m_bookScroller->setToolTips(
+ tr("Next book"),
+ scrollButtonToolTip,
+ tr("Previous book")
+ );
+ m_chapterScroller->setToolTips(
+ tr("Next chapter"),
+ scrollButtonToolTip,
+ tr("Previous chapter")
+ );
+ m_verseScroller->setToolTips(
+ tr("Next verse"),
+ scrollButtonToolTip,
+ tr("Previous verse")
+ );
+
+ // signals and slots connections
+
+ connect(m_bookScroller, SIGNAL(change(int)), SLOT(slotStepBook(int)));
+ connect(m_bookScroller, SIGNAL(scroller_pressed()), SLOT(slotUpdateLock()));
+ connect(m_bookScroller, SIGNAL(scroller_released()), SLOT(slotUpdateUnlock()));
+ connect(m_textbox, SIGNAL(returnPressed()), SLOT(slotReturnPressed()));
+ connect(m_chapterScroller, SIGNAL(change(int)), SLOT(slotStepChapter(int)));
+ connect(m_chapterScroller, SIGNAL(scroller_pressed()), SLOT(slotUpdateLock()));
+ connect(m_chapterScroller, SIGNAL(scroller_released()), SLOT(slotUpdateUnlock()));
+ connect(m_verseScroller, SIGNAL(change(int)), SLOT(slotStepVerse(int)));
+ connect(m_verseScroller, SIGNAL(scroller_pressed()), SLOT(slotUpdateLock()));
+ connect(m_verseScroller, SIGNAL(scroller_released()), SLOT(slotUpdateUnlock()));
+}
+
+void CKeyReferenceWidget::setModule(CSwordBibleModuleInfo *m)
+{
+ if (m) //can be null
+ {
+ m_module = m;
+ m_key->module(m);
+ }
+}
+
+void CKeyReferenceWidget::slotClearRef( )
+{
+ m_textbox->setText("");
+ m_textbox->setFocus();
+}
+
+void CKeyReferenceWidget::updateText()
+{
+ m_textbox->setText(m_key->key());
+}
+
+bool CKeyReferenceWidget::setKey(CSwordVerseKey *key)
+{
+ if (!key) return false;
+
+ m_key->key(key->key());
+ updateText();
+ return true;
+}
+
+QLineEdit* CKeyReferenceWidget::textbox()
+{
+ return m_textbox;
+}
+
+void CKeyReferenceWidget::slotReturnPressed()
+{
+ m_key->key(m_textbox->text());
+ updateText();
+
+ emit changed(m_key.get());
+}
+
+/* Handlers for the various scroller widgetsets. Do we really want a verse scroller? */
+void CKeyReferenceWidget::slotUpdateLock()
+{
+ updatelock = true;
+ oldKey = m_key->key();
+}
+
+void CKeyReferenceWidget::slotUpdateUnlock()
+{
+ updatelock = false;
+ if (oldKey != m_key->key()) emit changed(m_key.get());
+}
+
+void CKeyReferenceWidget::slotStepBook(int n)
+{
+ n > 0 ? m_key->next( CSwordVerseKey::UseBook ) : m_key->previous( CSwordVerseKey::UseBook );
+ updateText();
+ if (!updatelock) emit changed(m_key.get());
+}
+
+void CKeyReferenceWidget::slotStepChapter(int n)
+{
+ n > 0 ? m_key->next( CSwordVerseKey::UseChapter ) : m_key->previous( CSwordVerseKey::UseChapter );
+ updateText();
+ if (!updatelock) emit changed(m_key.get());
+}
+
+void CKeyReferenceWidget::slotStepVerse(int n)
+{
+ n > 0 ? m_key->next( CSwordVerseKey::UseVerse ) : m_key->previous( CSwordVerseKey::UseVerse );
+ updateText();
+ if (!updatelock) emit changed(m_key.get());
+}
+
+
+void CKeyReferenceWidget::slotChangeVerse(int n)
+{
+ if (m_key->Verse() != n) {
+ m_key->Verse( n );
+ setKey( m_key.get() );
+ }
+ updateText();
+ if (!updatelock) emit changed(m_key.get());
+}
+
+void CKeyReferenceWidget::slotChangeChapter(int n)
+{
+ if (m_key->Chapter() != n) {
+ m_key->Chapter( n );
+ setKey( m_key.get() );
+ }
+ updateText();
+ if (!updatelock) emit changed(m_key.get());
+}
+
+void CKeyReferenceWidget::slotChangeBook(QString bookname)
+{
+ if (m_key->book() != bookname) {
+ m_key->book( bookname );
+ setKey( m_key.get() );
+ }
+ updateText();
+ if (!updatelock) emit changed(m_key.get());
+}
+
diff --git a/src/frontend/keychooser/versekeychooser/ckeyreferencewidget.h b/src/frontend/keychooser/versekeychooser/ckeyreferencewidget.h
new file mode 100644
index 0000000..d6d5eee
--- /dev/null
+++ b/src/frontend/keychooser/versekeychooser/ckeyreferencewidget.h
@@ -0,0 +1,86 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CKEYREFERENCEWIDGET_H
+#define CKEYREFERENCEWIDGET_H
+
+#include "../cscrollerwidgetset.h"
+#include "backend/drivers/cswordbiblemoduleinfo.h"
+
+#include <QWidget>
+
+#include <boost/scoped_ptr.hpp>
+
+
+class CLexiconKeyChooser;
+class CSwordVerseKey;
+class BtDropdownChooserButton;
+
+class QLineEdit;
+
+
+class CKeyReferenceWidget : public QWidget {
+ Q_OBJECT
+public:
+ /**
+ * the constructor
+ */
+ CKeyReferenceWidget(CSwordBibleModuleInfo *, CSwordVerseKey*, QWidget *parent=0, const char *name=0);
+ bool setKey(CSwordVerseKey* key);
+ QLineEdit* textbox();
+ void setModule(CSwordBibleModuleInfo *m = 0);
+
+signals:
+ void changed(CSwordVerseKey* key);
+
+protected:
+ void updateText();
+
+protected slots: // Protected slots
+ /**
+ * Is called when the return key was presed in the textbox.
+ */
+ void slotReturnPressed();
+
+ void slotClearRef();
+
+ void slotUpdateLock();
+ void slotUpdateUnlock();
+ void slotStepBook(int);
+ void slotStepChapter(int);
+ void slotStepVerse(int);
+ void slotChangeBook(QString bookname);
+ void slotChangeChapter(int chapter);
+ void slotChangeVerse(int verse);
+
+private:
+ friend class CLexiconKeyChooser;
+ friend class BtDropdownChooserButton;
+ friend class BtBookDropdownChooserButton;
+ friend class BtChapterDropdownChooserButton;
+ friend class BtVerseDropdownChooserButton;
+
+ boost::scoped_ptr<CSwordVerseKey> m_key;
+
+ QLineEdit* m_textbox;
+
+ CScrollerWidgetSet *m_bookScroller;
+ CScrollerWidgetSet *m_chapterScroller;
+ CScrollerWidgetSet *m_verseScroller;
+
+ BtDropdownChooserButton* m_bookDropdownButton;
+ BtDropdownChooserButton* m_chapterDropdownButton;
+ BtDropdownChooserButton* m_verseDropdownButton;
+
+ bool updatelock;
+ QString oldKey;
+ CSwordBibleModuleInfo *m_module;
+};
+
+#endif
diff --git a/src/frontend/mainindex/bookmarks/btbookmarkfolder.cpp b/src/frontend/mainindex/bookmarks/btbookmarkfolder.cpp
new file mode 100644
index 0000000..ac86b0e
--- /dev/null
+++ b/src/frontend/mainindex/bookmarks/btbookmarkfolder.cpp
@@ -0,0 +1,150 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+#include "btbookmarkfolder.h"
+#include "btbookmarkitembase.h"
+#include "btbookmarkitem.h"
+#include "btbookmarkloader.h"
+
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+
+#include <QFileDialog>
+
+#include <QDebug>
+
+BtBookmarkFolder::BtBookmarkFolder(QTreeWidgetItem* parent, QString name)
+ : BtBookmarkItemBase(parent)
+{
+ setText(0, name);
+ setFlags(Qt::ItemIsEditable|Qt::ItemIsSelectable|Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled|Qt::ItemIsEnabled);
+}
+
+bool BtBookmarkFolder::enableAction(MenuAction action)
+{
+ if (action == ChangeFolder || action == NewFolder || action == DeleteEntries || action == ImportBookmarks )
+ return true;
+ if (action == ExportBookmarks || action == ImportBookmarks )
+ return true;
+ if ((action == PrintBookmarks) && childCount())
+ return true;
+ return false;
+}
+
+void BtBookmarkFolder::exportBookmarks()
+{
+ QString filter = QObject::tr("BibleTime bookmark files") + QString(" (*.btb);;") + QObject::tr("All files") + QString(" (*.*)");
+ QString fileName = QFileDialog::getSaveFileName(0, QObject::tr("Export Bookmarks"), "", filter);
+
+ if (!fileName.isEmpty()) {
+ qDebug() << "exportBookmarks()";
+ BtBookmarkLoader loader;
+ loader.saveTreeFromRootItem(this, fileName, false ); //false: don't overwrite without asking
+ };
+
+}
+
+void BtBookmarkFolder::importBookmarks()
+{
+ QString filter = QObject::tr("BibleTime bookmark files") + QString(" (*.btb);;") + QObject::tr("All files") + QString(" (*.*)");
+ QString fileName = QFileDialog::getOpenFileName(0, QObject::tr("Import bookmarks"), "", filter);
+ if (!fileName.isEmpty()) {
+ qDebug() << "import bookmarks";
+ BtBookmarkLoader loader;
+ QList<QTreeWidgetItem*> itemList = loader.loadTree(fileName);
+ this->insertChildren(0, itemList);
+ };
+}
+
+QString BtBookmarkFolder::toolTip()
+{
+ return QString();
+}
+
+void BtBookmarkFolder::newSubFolder()
+{
+ if (dynamic_cast<BtBookmarkFolder*>(this)) {
+ BtBookmarkFolder* f = new BtBookmarkFolder(this, QObject::tr("New folder"));
+
+ treeWidget()->setCurrentItem(f);
+ f->update();
+ f->rename();
+ }
+}
+
+QList<QTreeWidgetItem*> BtBookmarkFolder::getChildList() const
+{
+ QList<QTreeWidgetItem*> list;
+ for (int i = 0; i < childCount(); i++) {
+ list.append(child(i));
+ }
+ return list;
+}
+
+void BtBookmarkFolder::rename()
+{
+ treeWidget()->editItem(this);
+}
+
+void BtBookmarkFolder::update()
+{
+ qDebug() << "BtBookmarkFolder::update()";
+ BtBookmarkItemBase::update();
+ if (isExpanded() && childCount())
+ setIcon(0, util::filesystem::DirectoryUtil::getIcon(CResMgr::mainIndex::openedFolder::icon));
+ else
+ setIcon(0, util::filesystem::DirectoryUtil::getIcon(CResMgr::mainIndex::closedFolder::icon));
+}
+
+bool BtBookmarkFolder::hasDescendant(QTreeWidgetItem* item) const
+{
+ qDebug() << "BtBookmarkFolder::hasDescendant, this:" << this << "possible descendant:" << item;
+
+ if (this == item) {
+ qDebug() << "it's this, return true";
+ return true;
+ }
+ if (getChildList().indexOf(item) > -1) {
+ qDebug() << "direct child, return true";
+ return true;
+ }
+ foreach(QTreeWidgetItem* childItem, getChildList()) {
+ bool subresult = false;
+ BtBookmarkFolder* folder = 0;
+ if ( (folder = dynamic_cast<BtBookmarkFolder*>(childItem)) ) {
+ subresult = folder->hasDescendant(childItem);
+ }
+
+ if (subresult == true) {
+ qDebug() << "descendand child, return true";
+ return true;
+ }
+ }
+ qDebug() << "no child, return false";
+ return false;
+}
+
+BtBookmarkFolder* BtBookmarkFolder::deepCopy()
+{
+ qDebug() << "BtBookmarkFolder::deepCopy";
+ BtBookmarkFolder* newFolder = new BtBookmarkFolder(0, this->text(0));
+ foreach(QTreeWidgetItem* subitem, getChildList()) {
+ if (BtBookmarkItem* bmItem = dynamic_cast<BtBookmarkItem*>(subitem)) {
+ newFolder->addChild(new BtBookmarkItem(*bmItem));
+ } else {
+ if (BtBookmarkFolder* bmFolder = dynamic_cast<BtBookmarkFolder*>(subitem)) {
+ newFolder->addChild(bmFolder->deepCopy());
+ }
+ }
+ }
+ newFolder->update();
+ return newFolder;
+}
+
diff --git a/src/frontend/mainindex/bookmarks/btbookmarkfolder.h b/src/frontend/mainindex/bookmarks/btbookmarkfolder.h
new file mode 100644
index 0000000..a659917
--- /dev/null
+++ b/src/frontend/mainindex/bookmarks/btbookmarkfolder.h
@@ -0,0 +1,51 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTBOOKMARKFOLDER_H
+#define BTBOOKMARKFOLDER_H
+
+#include "btbookmarkitembase.h"
+
+#define CURRENT_SYNTAX_VERSION 1
+
+
+class BtBookmarkFolder : public BtBookmarkItemBase
+{
+public:
+ friend class BtBookmarkLoader;
+ BtBookmarkFolder(QTreeWidgetItem* parent, QString name);
+ ~BtBookmarkFolder() {}
+
+ /** See the base class. */
+ virtual bool enableAction(const MenuAction action);
+
+ /** User gives a file from which to load items into this folder. */
+ virtual void exportBookmarks();
+ /** User gives a file to which items from this folder are saved. */
+ virtual void importBookmarks();
+
+ /** Creates a new folder under this. */
+ void newSubFolder();
+
+ /** Returns a list of direct childs of this item. */
+ QList<QTreeWidgetItem*> getChildList() const;
+
+ /** Returns true if the given item is this or a direct or indirect subitem of this. */
+ bool hasDescendant(QTreeWidgetItem* item) const;
+
+ /** Creates a deep copy of this item. */
+ BtBookmarkFolder* deepCopy();
+
+ void rename();
+ void update();
+
+ QString toolTip();
+};
+
+#endif
diff --git a/src/frontend/mainindex/bookmarks/btbookmarkitem.cpp b/src/frontend/mainindex/bookmarks/btbookmarkitem.cpp
new file mode 100644
index 0000000..84473f7
--- /dev/null
+++ b/src/frontend/mainindex/bookmarks/btbookmarkitem.cpp
@@ -0,0 +1,163 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+#include "btbookmarkitem.h"
+#include "btbookmarkfolder.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/keys/cswordversekey.h"
+#include "frontend/cinputdialog.h"
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+#include "backend/config/cbtconfig.h"
+#include "util/cpointers.h"
+
+#include <QDebug>
+
+#include <boost/scoped_ptr.hpp>
+
+
+BtBookmarkItem::BtBookmarkItem(CSwordModuleInfo* module, QString key, QString& description)
+ :m_description(description),
+ m_moduleName(module ? module->name() : QString::null)
+{
+ if (((module && (module->type() == CSwordModuleInfo::Bible)) || (module->type() == CSwordModuleInfo::Commentary)) ) {
+ CSwordVerseKey vk(0);
+ vk.key(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)
+{
+ update();
+}
+
+CSwordModuleInfo* BtBookmarkItem::module()
+{
+ CSwordModuleInfo* const m = CPointers::backend()->findModuleByName(m_moduleName);
+ return m;
+}
+
+QString BtBookmarkItem::key()
+{
+ const QString englishKeyName = englishKey();
+ if (!module()) {
+ return englishKeyName;
+ }
+
+ QString returnKeyName = englishKeyName;
+ if ((module()->type() == CSwordModuleInfo::Bible) || (module()->type() == CSwordModuleInfo::Commentary)) {
+ CSwordVerseKey vk(0);
+ vk.key(englishKeyName);
+ vk.setLocale(CPointers::backend()->booknameLanguage().toLatin1() );
+
+ returnKeyName = vk.key(); //the returned key is always in the currently set bookname language
+ }
+
+ return returnKeyName;
+}
+
+const QString& BtBookmarkItem::description()
+{
+ return m_description;
+}
+
+void BtBookmarkItem::setDescription(QString text)
+{
+ m_description = text;
+}
+
+QString BtBookmarkItem::toolTip()
+{
+ if (!module()) {
+ return QString::null;
+ }
+
+ CSwordBackend::FilterOptions filterOptions = CBTConfig::getFilterOptionDefaults();
+ filterOptions.footnotes = false;
+ filterOptions.scriptureReferences = false;
+ CPointers::backend()->setFilterOptions(filterOptions);
+
+ QString ret;
+ boost::scoped_ptr<CSwordKey> k( CSwordKey::createInstance(module()) );
+ k->key(this->key());
+
+ const CLanguageMgr::Language* lang = module()->language();
+ CBTConfig::FontSettingsPair fontPair = CBTConfig::get
+ (lang);
+
+ Q_ASSERT(k.get());
+ if (fontPair.first) { //use a special font
+ ret = QString::fromLatin1("<b>%1 (%2)</b><hr>%3")
+ .arg(key())
+ .arg(module()->name())
+ .arg(description())
+ ;
+ }
+ else {
+ ret = QString::fromLatin1("<b>%1 (%2)</b><hr>%3")
+ .arg(key())
+ .arg(module()->name())
+ .arg(description())
+ ;
+ }
+
+ return ret;
+}
+
+bool BtBookmarkItem::enableAction(MenuAction action)
+{
+ if (action == ChangeBookmark || (module() && (action == PrintBookmarks)) || action == DeleteEntries)
+ return true;
+
+ return false;
+}
+
+void BtBookmarkItem::rename()
+{
+ bool ok = false;
+ const QString newDescription = CInputDialog::getText(QObject::tr("Change description ..."), QObject::tr("Enter a new description for the chosen bookmark."), description(), &ok, treeWidget());
+
+ if (ok) {
+ m_description = newDescription;
+ update();
+ }
+}
+
+QString BtBookmarkItem::englishKey() const
+{
+ return m_key;
+}
+
+void BtBookmarkItem::update()
+{
+ qDebug() << "BtBookmarkItem::update";
+ setIcon(0, util::filesystem::DirectoryUtil::getIcon(CResMgr::mainIndex::bookmark::icon));
+
+ const QString title = QString::fromLatin1("%1 (%2)").arg(key()).arg(module() ? module()->name() : QObject::tr("unknown"));
+ setText(0, title);
+ setToolTip(0, toolTip());
+}
+
diff --git a/src/frontend/mainindex/bookmarks/btbookmarkitem.h b/src/frontend/mainindex/bookmarks/btbookmarkitem.h
new file mode 100644
index 0000000..8529e23
--- /dev/null
+++ b/src/frontend/mainindex/bookmarks/btbookmarkitem.h
@@ -0,0 +1,67 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTBOOKMARKITEM_H
+#define BTBOOKMARKITEM_H
+
+
+#include "btbookmarkitembase.h"
+
+#include <QString>
+
+class BtBookmarkFolder;
+class CSwordModuleInfo;
+
+class BtBookmarkItem : public BtBookmarkItemBase
+{
+public:
+ friend class BtBookmarkLoader;
+
+ BtBookmarkItem(QTreeWidgetItem* parent);
+
+ /** Creates a bookmark with module, key and description. */
+ BtBookmarkItem(CSwordModuleInfo* module, QString key, QString& description);
+
+ /** Creates a copy. */
+ BtBookmarkItem(const BtBookmarkItem& other);
+
+ ~BtBookmarkItem() {}
+
+ /** Returns the used module, 0 if there is no such module. */
+ CSwordModuleInfo* module();
+
+ /** Returns the used key. */
+ QString key();
+
+ /** Returns the used description. */
+ const QString& description();
+ /** Sets the description text for this bookmark. */
+ virtual void setDescription(QString text);
+
+ /** Returns a tooltip for this bookmark. */
+ virtual QString toolTip();
+
+ /** Returns whether the action is supported by this item. */
+ virtual bool enableAction(MenuAction action);
+
+ /** Changes this bookmark. */
+ virtual void rename();
+
+ void update();
+
+private:
+ /** Returns the english key.*/
+ QString englishKey() const;
+
+ QString m_key;
+ QString m_description;
+ QString m_moduleName;
+};
+
+#endif
diff --git a/src/frontend/mainindex/bookmarks/btbookmarkitembase.cpp b/src/frontend/mainindex/bookmarks/btbookmarkitembase.cpp
new file mode 100644
index 0000000..bd5ae13
--- /dev/null
+++ b/src/frontend/mainindex/bookmarks/btbookmarkitembase.cpp
@@ -0,0 +1,41 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btbookmarkitembase.h"
+#include "cbookmarkindex.h"
+
+#include <QTreeWidgetItem>
+#include <QDropEvent>
+
+BtBookmarkItemBase::BtBookmarkItemBase()
+{}
+
+BtBookmarkItemBase::BtBookmarkItemBase(QTreeWidgetItem* parent)
+ : QTreeWidgetItem(parent)
+{}
+
+CBookmarkIndex* BtBookmarkItemBase::bookmarkWidget() const
+{
+ return dynamic_cast<CBookmarkIndex*>(treeWidget());
+}
+
+// void BtBookmarkItemBase::dropped(QDropEvent* e)
+// {
+//
+// }
+//
+// void BtBookmarkItemBase::addPreviousSibling(BtBookmarkItemBase* item)
+// {
+//
+// }
+//
+// void BtBookmarkItemBase::addNextSibling(BtBookmarkItemBase* item)
+// {
+//
+// }
diff --git a/src/frontend/mainindex/bookmarks/btbookmarkitembase.h b/src/frontend/mainindex/bookmarks/btbookmarkitembase.h
new file mode 100644
index 0000000..1e486e6
--- /dev/null
+++ b/src/frontend/mainindex/bookmarks/btbookmarkitembase.h
@@ -0,0 +1,63 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTBOOKMARKITEMBASE_H
+#define BTBOOKMARKITEMBASE_H
+
+
+#include <QTreeWidgetItem>
+#include <QString>
+#include <QMimeData>
+#include <QDropEvent>
+
+class CBookmarkIndex;
+
+
+class BtBookmarkItemBase : public QTreeWidgetItem
+{
+public:
+
+ enum MenuAction {
+ NewFolder = 0,
+ ChangeFolder,
+
+ ChangeBookmark,
+ ImportBookmarks,
+ ExportBookmarks,
+ PrintBookmarks,
+
+ DeleteEntries,
+
+ ActionBegin = NewFolder,
+ ActionEnd = DeleteEntries
+ };
+
+ /** Where to drop/create item(s): above, below or inside an item.*/
+ enum Location {Above, Below, Inside};
+
+ BtBookmarkItemBase();
+ BtBookmarkItemBase(QTreeWidgetItem* parent);
+ virtual ~BtBookmarkItemBase() {}
+
+ virtual QString toolTip() = 0;
+ virtual CBookmarkIndex* bookmarkWidget() const;
+
+ /** Returns true if the given action should be enabled in the popup menu. */
+ virtual bool enableAction( MenuAction action ) = 0;
+
+ /** Rename the item. */
+ virtual void rename() = 0;
+
+ /** Update the item (icon etc.) after creating or changing it. */
+ virtual void update() {}
+
+};
+
+#endif
+
diff --git a/src/frontend/mainindex/bookmarks/btbookmarkloader.cpp b/src/frontend/mainindex/bookmarks/btbookmarkloader.cpp
new file mode 100644
index 0000000..3e70dbe
--- /dev/null
+++ b/src/frontend/mainindex/bookmarks/btbookmarkloader.cpp
@@ -0,0 +1,174 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btbookmarkloader.h"
+
+#include "btbookmarkitem.h"
+#include "btbookmarkfolder.h"
+
+#include "util/ctoolclass.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+
+#include <QTreeWidgetItem>
+#include <QDomElement>
+#include <QDomNode>
+#include <QDomDocument>
+#include <QTextStream>
+#include <QFile>
+#include <QIODevice>
+#include <QTextCodec>
+
+#include <QDebug>
+
+#define CURRENT_SYNTAX_VERSION 1
+
+QList<QTreeWidgetItem*> BtBookmarkLoader::loadTree(QString fileName)
+{
+ qDebug() << "BtBookmarkLoader::loadTree";
+ QList<QTreeWidgetItem*> itemList;
+
+ QDomDocument doc;
+ doc.setContent(loadXmlFromFile(fileName));
+
+ //bookmarkfolder::loadBookmarksFromXML()
+
+ QDomElement document = doc.documentElement();
+ if( document.tagName() != "SwordBookmarks" ) {
+ qWarning("Not a BibleTime Bookmark XML file");
+ return QList<QTreeWidgetItem*>();
+ }
+
+ QDomElement child = document.firstChild().toElement();
+
+ while ( !child.isNull() && child.parentNode() == document) {
+ qDebug() << "BtBookmarkLoader::loadTree while start";
+ QTreeWidgetItem* i = handleXmlElement(child, 0);
+ itemList.append(i);
+ if (!child.nextSibling().isNull()) {
+ child = child.nextSibling().toElement();
+ } else {
+ child = QDomElement(); //null
+ }
+
+ }
+
+ return itemList;
+}
+
+QTreeWidgetItem* BtBookmarkLoader::handleXmlElement(QDomElement& element, QTreeWidgetItem* parent)
+{
+ qDebug() << "BtBookmarkLoader::handleXmlElement";
+ QTreeWidgetItem* newItem = 0;
+ if (element.tagName() == "Folder") {
+ qDebug() << "BtBookmarkLoader::handleXmlElement: found folder";
+ BtBookmarkFolder* newFolder = new BtBookmarkFolder(parent, QString());
+ if (element.hasAttribute("caption")) {
+ newFolder->setText(0, element.attribute("caption"));
+ }
+ QDomNodeList childList = element.childNodes();
+ for (unsigned int i = 0; i < childList.length(); i++) {
+ qDebug() << "BtBookmarkLoader::handleXmlElement: go through child list of folder";
+ QDomElement newElement = childList.at(i).toElement();
+ QTreeWidgetItem* newChildItem = handleXmlElement(newElement, newFolder);
+ newFolder->addChild(newChildItem);
+ }
+ newFolder->update();
+ newItem = newFolder;
+ }
+ else if (element.tagName() == "Bookmark") {
+ qDebug() << "BtBookmarkLoader::handleXmlElement: found bookmark";
+ BtBookmarkItem* newBookmarkItem = new BtBookmarkItem(parent);
+ if (element.hasAttribute("modulename")) {
+ //we use the name in all cases, even if the module isn't installed anymore
+ newBookmarkItem->m_moduleName = element.attribute("modulename");
+ }
+ if (element.hasAttribute("key")) {
+ newBookmarkItem->m_key = element.attribute("key");
+ }
+ if (element.hasAttribute("description")) {
+ newBookmarkItem->m_description = element.attribute("description");
+ }
+ newBookmarkItem->update();
+ newItem = newBookmarkItem;
+ }
+ qDebug() << "BtBookmarkLoader::handleXmlElement: return new item";
+ return newItem;
+}
+
+
+QString BtBookmarkLoader::loadXmlFromFile(QString fileName)
+{
+ if (fileName.isNull()) {
+ fileName = util::filesystem::DirectoryUtil::getUserBaseDir().absolutePath() + "/bookmarks.xml";
+ }
+ QFile file(fileName);
+ if (!file.exists())
+ return QString();
+
+ QString xml;
+ if (file.open(QIODevice::ReadOnly)) {
+ QTextStream t;
+ t.setAutoDetectUnicode(false);
+ t.setCodec(QTextCodec::codecForName("UTF-8"));
+ t.setDevice(&file);
+ xml = t.readAll();
+ file.close();
+ }
+ return xml;
+}
+
+void BtBookmarkLoader::saveTreeFromRootItem(QTreeWidgetItem* rootItem, QString fileName, bool forceOverwrite)
+{
+ Q_ASSERT(rootItem);
+ if (fileName.isNull()) {
+ fileName = util::filesystem::DirectoryUtil::getUserBaseDir().absolutePath() + "/bookmarks.xml";
+ }
+
+ QDomDocument doc("DOC");
+ doc.appendChild( doc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
+
+ QDomElement content = doc.createElement("SwordBookmarks");
+ content.setAttribute("syntaxVersion", CURRENT_SYNTAX_VERSION);
+ doc.appendChild(content);
+
+ //append the XML nodes of all child items
+
+ for (int i = 0; i < rootItem->childCount(); i++) {
+ saveItem(rootItem->child(i), content);
+ }
+ CToolClass::savePlainFile(fileName, doc.toString(), forceOverwrite, QTextCodec::codecForName("UTF-8"));
+
+}
+
+void BtBookmarkLoader::saveItem(QTreeWidgetItem* item, QDomElement& parentElement)
+{
+ BtBookmarkFolder* folderItem = 0;
+ BtBookmarkItem* bookmarkItem = 0;
+
+ if ((folderItem = dynamic_cast<BtBookmarkFolder*>(item))) {
+ QDomElement elem = parentElement.ownerDocument().createElement("Folder");
+ elem.setAttribute("caption", folderItem->text(0));
+
+ parentElement.appendChild(elem);
+
+ for (int i = 0; i < folderItem->childCount(); i++) {
+ saveItem(folderItem->child(i), elem);
+ }
+ }
+ else if ((bookmarkItem = dynamic_cast<BtBookmarkItem*>(item))) {
+ QDomElement elem = parentElement.ownerDocument().createElement("Bookmark");
+
+ elem.setAttribute("key", bookmarkItem->englishKey());
+ elem.setAttribute("description", bookmarkItem->description());
+ elem.setAttribute("modulename", bookmarkItem->m_moduleName);
+ elem.setAttribute("moduledescription", bookmarkItem->module() ? bookmarkItem->module()->config(CSwordModuleInfo::Description) : QString::null);
+
+ parentElement.appendChild(elem);
+ }
+}
diff --git a/src/frontend/mainindex/bookmarks/btbookmarkloader.h b/src/frontend/mainindex/bookmarks/btbookmarkloader.h
new file mode 100644
index 0000000..3ae0bb6
--- /dev/null
+++ b/src/frontend/mainindex/bookmarks/btbookmarkloader.h
@@ -0,0 +1,47 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTBOOKMARKLOADER_H
+#define BTBOOKMARKLOADER_H
+
+#include "util/directoryutil.h"
+
+#include <QString>
+#include <QList>
+#include <QDomElement>
+
+
+class QTreeWidgetItem;
+
+/**
+* Class for loading and saving bookmarks.
+*/
+class BtBookmarkLoader
+{
+public:
+ /** Loads a list of items (with subitem trees) from a named file
+ * or from the default bookmarks file. */
+ QList<QTreeWidgetItem*> loadTree(QString fileName=QString::null);
+
+ /** Takes one item and saves the tree which is under it to a named file
+ * or to the default bookmarks file, asking the user about overwriting if necessary. */
+ void saveTreeFromRootItem(QTreeWidgetItem* rootItem, QString fileName=QString::null, bool forceOverwrite=true);
+
+private:
+ /** Create a new item from a document element. */
+ QTreeWidgetItem* handleXmlElement(QDomElement& element, QTreeWidgetItem* parent);
+
+ /** Writes one item to a document element. */
+ void saveItem(QTreeWidgetItem* item, QDomElement& parentElement);
+
+ /** Loads a bookmark XML document from a named file or from the default bookmarks file. */
+ QString loadXmlFromFile(QString fileName=QString::null);
+};
+
+#endif
diff --git a/src/frontend/mainindex/bookmarks/cbookmarkindex.cpp b/src/frontend/mainindex/bookmarks/cbookmarkindex.cpp
new file mode 100644
index 0000000..7405fd3
--- /dev/null
+++ b/src/frontend/mainindex/bookmarks/cbookmarkindex.cpp
@@ -0,0 +1,850 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//BibleTime includes
+#include "cbookmarkindex.h"
+
+#include "btbookmarkitembase.h"
+#include "btbookmarkitem.h"
+#include "btbookmarkfolder.h"
+#include "btbookmarkloader.h"
+
+#include "backend/managers/creferencemanager.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+
+#include "frontend/searchdialog/csearchdialog.h"
+#include "backend/config/cbtconfig.h"
+#include "frontend/cinfodisplay.h"
+
+#include "frontend/cprinter.h"
+#include "frontend/cdragdrop.h"
+
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+#include "util/ctoolclass.h"
+
+#include <boost/scoped_ptr.hpp>
+
+//Qt includes
+#include <QInputDialog>
+#include <QDragLeaveEvent>
+#include <QDragMoveEvent>
+#include <QDropEvent>
+#include <QHeaderView>
+#include <QTimer>
+#include <QToolTip>
+#include <QList>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+#include <QCursor>
+#include <QMouseEvent>
+#include <QMessageBox>
+#include <QMenu>
+#include <QAction>
+#include <QPaintEvent>
+#include <QPainter>
+#include <QApplication>
+#include <QDrag>
+
+#include <QDebug>
+
+CBookmarkIndex::CBookmarkIndex(QWidget *parent)
+ : QTreeWidget(parent),
+ m_magTimer(this),
+ m_previousEventItem(0)
+{
+ setMouseTracking(true);
+ m_magTimer.setSingleShot(true);
+ m_magTimer.setInterval(CBTConfig::get(CBTConfig::magDelay));
+ setContextMenuPolicy(Qt::CustomContextMenu);
+ initView();
+ initConnections();
+ initTree();
+}
+
+CBookmarkIndex::~CBookmarkIndex()
+{
+ saveBookmarks();
+}
+
+
+/** Initializes the view. */
+void CBookmarkIndex::initView()
+{
+ //qDebug("CBookmarkIndex::initView");
+
+ header()->hide();
+
+ setFocusPolicy(Qt::WheelFocus);
+
+ //d'n'd related settings
+ setDragEnabled( true );
+ setAcceptDrops( true );
+ setDragDropMode(QAbstractItemView::DragDrop);
+ viewport()->setAcceptDrops(true);
+ setAutoScroll(true);
+ setAutoExpandDelay(800);
+
+ setItemsExpandable(true);
+ setRootIsDecorated(true);
+ setAllColumnsShowFocus(true);
+ setSelectionMode(QAbstractItemView::ExtendedSelection);
+
+ //setup the popup menu
+ m_popup = new QMenu(viewport());
+ m_popup->setTitle(tr("Bookmarks"));
+
+ m_actions.newFolder = newQAction(tr("New folder"), CResMgr::mainIndex::newFolder::icon, 0, this, SLOT(createNewFolder()), this);
+ m_actions.changeFolder = newQAction(tr("Rename folder"),CResMgr::mainIndex::changeFolder::icon, 0, this, SLOT(changeFolder()), this);
+
+ m_actions.changeBookmark = newQAction(tr("Change bookmark description..."), CResMgr::mainIndex::changeBookmark::icon, 0, this, SLOT(changeBookmark()), this);
+ m_actions.importBookmarks = newQAction(tr("Import to folder..."), CResMgr::mainIndex::importBookmarks::icon, 0, this, SLOT(importBookmarks()), this);
+ m_actions.exportBookmarks = newQAction(tr("Export from folder..."), CResMgr::mainIndex::exportBookmarks::icon, 0, this, SLOT(exportBookmarks()), this);
+ m_actions.printBookmarks = newQAction(tr("Print bookmarks..."), CResMgr::mainIndex::printBookmarks::icon, 0, this, SLOT(printBookmarks()), this);
+
+ m_actions.deleteEntries = newQAction(tr("Remove selected items..."), CResMgr::mainIndex::deleteItems::icon, 0, this, SLOT(deleteEntries()), this);
+
+
+ //fill the popup menu itself
+ m_popup->addAction(m_actions.newFolder);
+ m_popup->addAction(m_actions.changeFolder);
+ QAction* separator = new QAction(this);
+ separator->setSeparator(true);
+ m_popup->addAction(separator);
+ m_popup->addAction(m_actions.changeBookmark);
+ m_popup->addAction(m_actions.importBookmarks);
+ m_popup->addAction(m_actions.exportBookmarks);
+ m_popup->addAction(m_actions.printBookmarks);
+ separator = new QAction(this);
+ separator->setSeparator(true);
+ m_popup->addAction(separator);
+ m_popup->addAction(m_actions.deleteEntries);
+
+ //qDebug("CBookmarkIndex::initView end");
+}
+
+/** Convenience function for creating a new QAction.
+* Should be replaced with something better; it was easier to make a new function
+* than to modify all QAction constructors.
+*/
+QAction* CBookmarkIndex::newQAction(const QString& text, const QString& pix, const int /*shortcut*/, const QObject* receiver, const char* slot, QObject* parent)
+{
+ QAction* action = new QAction(util::filesystem::DirectoryUtil::getIcon(pix), text, parent);
+ QObject::connect(action, SIGNAL(triggered()), receiver, slot);
+ return action;
+}
+
+/** Initialize the SIGNAL<->SLOT connections */
+void CBookmarkIndex::initConnections()
+{
+ //qDebug("CBookmarkIndex::initConnections");
+ bool ok;
+ ok = connect(this, SIGNAL(itemActivated(QTreeWidgetItem*, int)), this, SLOT(slotExecuted(QTreeWidgetItem*)));
+ Q_ASSERT(ok);
+ ok = connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),
+ SLOT(contextMenu(const QPoint&)));
+ Q_ASSERT(ok);
+ ok = connect(&m_magTimer, SIGNAL(timeout()), this, SLOT(magTimeout()));
+ Q_ASSERT(ok);
+ ok = connect(this, SIGNAL(itemEntered(QTreeWidgetItem*, int)), this, SLOT(slotItemEntered(QTreeWidgetItem*, int)) );
+ Q_ASSERT(ok);
+}
+
+
+/**
+* Hack to get single click and selection working. See slotExecuted.
+*/
+void CBookmarkIndex::mouseReleaseEvent(QMouseEvent* event)
+{
+ //qDebug("CBookmarkIndex::mouseReleaseEvent");
+ m_mouseReleaseEventModifiers = event->modifiers();
+ QTreeWidget::mouseReleaseEvent(event);
+}
+
+/** Called when an item is clicked with mouse or activated with keyboard. */
+void CBookmarkIndex::slotExecuted( QTreeWidgetItem* i )
+{
+ qDebug("CBookmarkIndex::slotExecuted");
+
+ //HACK: checking the modifier keys from the last mouseReleaseEvent
+ //depends on executing order: mouseReleaseEvent first, then itemClicked signal
+ int modifiers = m_mouseReleaseEventModifiers;
+ m_mouseReleaseEventModifiers = Qt::NoModifier;
+ if (modifiers != Qt::NoModifier) {
+ return;
+ }
+
+ BtBookmarkItemBase* btItem = dynamic_cast<BtBookmarkItemBase*>(i);
+ if (!btItem) {
+ return;
+ }
+
+ BtBookmarkFolder* folderItem = 0;
+ BtBookmarkItem* bookmarkItem = 0;
+ if ((folderItem = dynamic_cast<BtBookmarkFolder*>(btItem))) {
+ i->setExpanded( !i->isExpanded() );
+ }
+ else if (( bookmarkItem = dynamic_cast<BtBookmarkItem*>(btItem) )) { //clicked on a bookmark
+ if (CSwordModuleInfo* mod = bookmarkItem->module()) {
+ QList<CSwordModuleInfo*> modules;
+ modules.append(mod);
+ emit createReadDisplayWindow(modules, bookmarkItem->key());
+ }
+ }
+}
+
+/** Creates a drag mime data object for the current selection. */
+QMimeData* CBookmarkIndex::dragObject()
+{
+ BTMimeData::ItemList dndItems;
+ BTMimeData* mimeData = new BTMimeData;
+
+ foreach( QTreeWidgetItem* widgetItem, selectedItems() ) {
+ if (!widgetItem)
+ break;
+ if (dynamic_cast<BtBookmarkItemBase*>(widgetItem)) {
+ if (BtBookmarkItem* bookmark = dynamic_cast<BtBookmarkItem*>( widgetItem )) {
+ //take care of bookmarks which have no valid module any more, e.g. if it was uninstalled
+ const QString moduleName = bookmark->module() ? bookmark->module()->name() : QString::null;
+ mimeData->appendBookmark(moduleName, bookmark->key(), bookmark->description());
+ }
+ }
+ }
+ return mimeData;
+}
+
+void CBookmarkIndex::dragEnterEvent( QDragEnterEvent* event )
+{
+ //qDebug("CBookmarkIndex::dragEnterEvent");
+ setState(QAbstractItemView::DraggingState);
+ QTreeWidget::dragEnterEvent(event);
+ if (event->source() == this || event->mimeData()->hasFormat("BibleTime/Bookmark")) {
+ event->acceptProposedAction();
+ }
+}
+
+
+void CBookmarkIndex::dragMoveEvent( QDragMoveEvent* event )
+{
+ //qDebug("CBookmarkIndex::dragMoveEvent");
+
+ // do this first, otherwise the event may be ignored
+ QTreeWidget::dragMoveEvent(event);
+
+ event->acceptProposedAction();
+ event->accept();
+
+ // do this to paint the arrow
+ m_dragMovementPosition = event->pos();
+ viewport()->update();
+
+}
+
+void CBookmarkIndex::dragLeaveEvent( QDragLeaveEvent* )
+{
+ qDebug("CBookmarkIndex::dragLeaveEvent");
+ setState(QAbstractItemView::NoState); // not dragging anymore
+ viewport()->update(); // clear the arrow
+}
+
+
+void CBookmarkIndex::paintEvent(QPaintEvent* event)
+{
+ static QPixmap pix;
+ static int halfPixHeight;
+ static bool arrowInitialized = false;
+
+ // Initialize the static variables, including the arrow pixmap
+ if (!arrowInitialized) {
+ arrowInitialized = true;
+ int arrowSize = CToolClass::mWidth(this, 1);
+ QString fileName;
+ if (util::filesystem::DirectoryUtil::getIconDir().exists("pointing_arrow.svg")) {
+ fileName = util::filesystem::DirectoryUtil::getIconDir().filePath("pointing_arrow.svg");
+ } else {
+ if (util::filesystem::DirectoryUtil::getIconDir().exists("pointing_arrow.png")) {
+ fileName = util::filesystem::DirectoryUtil::getIconDir().filePath("pointing_arrow.png");
+ } else {
+ qWarning() << "Picture file pointing_arrow.svg or .png not found!";
+ }
+ }
+
+ pix = QPixmap(fileName);
+ pix = pix.scaled(arrowSize, arrowSize, Qt::KeepAspectRatioByExpanding);
+ halfPixHeight = pix.height()/2;
+ }
+
+ // Do the normal painting first
+ QTreeWidget::paintEvent(event);
+
+ // Paint the arrow if the drag is going on
+ if (QAbstractItemView::DraggingState == state()) {
+ bool rtol = QApplication::isRightToLeft();
+
+ QPainter painter(this->viewport());
+ QTreeWidgetItem* item = itemAt(m_dragMovementPosition);
+ bool isFolder = dynamic_cast<BtBookmarkFolder*>(item);
+ bool isBookmark = dynamic_cast<BtBookmarkItem*>(item);
+
+ // Find the place for the arrow
+ QRect rect = visualItemRect(item);
+ int xCoord = rtol ? rect.right() : rect.left();
+ int yCoord;
+ if (isFolder) {
+ if (m_dragMovementPosition.y() > rect.bottom() - (2* rect.height()/3) ) {
+ yCoord = rect.bottom() - halfPixHeight; // bottom
+ xCoord = rtol ? (xCoord - indentation()) : (xCoord + indentation());
+ } else {
+ yCoord = rect.top() - halfPixHeight - 1; // top
+ }
+
+ } else {
+ if (isBookmark) {
+ if (m_dragMovementPosition.y() > rect.bottom() - rect.height()/2) {
+ yCoord = rect.bottom() - halfPixHeight; // bottom
+ } else {
+ yCoord = rect.top() - halfPixHeight - 1; // top
+ }
+ } else {
+ if (item) { // the extra item
+ yCoord = rect.top() - halfPixHeight - 1;
+ } else { // empty area
+ rect = visualItemRect(m_extraItem);
+ yCoord = rect.top() - halfPixHeight - 1;
+ xCoord = rtol ? rect.right() : rect.left();
+ }
+ }
+ }
+
+ painter.drawPixmap(xCoord, yCoord, pix);
+ }
+}
+
+
+void CBookmarkIndex::dropEvent( QDropEvent* event )
+{
+ qDebug("CBookmarkIndex::dropEvent");
+
+ //setState(QAbstractItemView::NoState);
+ // Try to prevent annoying timed autocollapsing. Remember to disconnect before return.
+ QObject::connect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*)));
+ QTreeWidgetItem* item = itemAt(event->pos());
+ QTreeWidgetItem* parentItem = 0;
+ int indexUnderParent = 0;
+
+ // Find the place where the drag is dropped
+ if (item) {
+ qDebug()<<"there was item";
+
+ QRect rect = visualItemRect(item);
+ bool isFolder = dynamic_cast<BtBookmarkFolder*>(item);
+ bool isBookmark = dynamic_cast<BtBookmarkItem*>(item);
+
+ if (isFolder) { // item is a folder
+ qDebug()<<"item was folder";
+ if (event->pos().y() > rect.bottom() - (2* rect.height()/3) ) {
+ parentItem = item;
+ } else {
+ parentItem = item->parent();
+ if (!parentItem) {
+ parentItem = invisibleRootItem();
+ }
+ qDebug()<<"item:" << item << "parent:" << parentItem;
+ indexUnderParent = parentItem->indexOfChild(item); // before the current folder
+ }
+ } else {
+ if (isBookmark) { // item is a bookmark
+ qDebug()<<"item was bookmark";
+ parentItem = item->parent();
+ if (!parentItem) {
+ parentItem = invisibleRootItem();
+ }
+ indexUnderParent = parentItem->indexOfChild(item); // before the current bookmark
+ if (event->pos().y() > rect.bottom() - rect.height()/2) {
+ indexUnderParent++; // after the current bookmark
+ }
+ } else { // item is the extra item
+ parentItem = item->parent();
+ if (!parentItem) {
+ parentItem = invisibleRootItem();
+ }
+ indexUnderParent = parentItem->indexOfChild(item); // before the current bookmark
+ }
+ }
+
+ } else { // no item under event point: drop to the end
+ qDebug()<<"there was no item";
+ parentItem = invisibleRootItem();
+ indexUnderParent = parentItem->childCount()-1;
+ }
+
+
+ if ( event->source() == this ) {
+ qDebug("dropping internal drag");
+ event->accept();
+
+ bool bookmarksOnly = true;
+ bool targetIncluded = false;
+ bool moreThanOneFolder = false;
+
+ QList<QTreeWidgetItem*> newItems = addItemsToDropTree(parentItem, bookmarksOnly, targetIncluded, moreThanOneFolder);
+
+ if (moreThanOneFolder) {
+ QToolTip::showText(QCursor::pos(), tr("Can drop only bookmarks or one folder"));
+ QObject::disconnect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*)));
+ return;
+ }
+ if (targetIncluded) {
+ QToolTip::showText(QCursor::pos(), tr("Can't drop folder into the folder itself or into its subfolder"));
+ QObject::disconnect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*)));
+ return;
+ }
+ // Ask whether to copy or move with a popup menu
+
+ QMenu* dropPopupMenu = new QMenu(this);
+ QAction* copy = dropPopupMenu->addAction(tr("Copy"));
+ QAction* move = dropPopupMenu->addAction(tr("Move"));
+ QAction* dropAction = dropPopupMenu->exec(QCursor::pos());
+ if (dropAction == copy) {
+ qDebug() << "copy";
+ parentItem->insertChildren(indexUnderParent, newItems);
+ } else {
+ if (dropAction == move) {
+ qDebug() << "move";
+ parentItem->insertChildren(indexUnderParent, newItems);
+ deleteEntries(false);
+ } else {
+ QObject::disconnect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*)));
+ return; // user canceled
+ }
+ }
+
+ } else {
+ qDebug()<<"the source was outside this";
+ createBookmarkFromDrop(event, parentItem, indexUnderParent);
+ }
+ QObject::disconnect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*)));
+ setState(QAbstractItemView::NoState);
+}
+
+
+void CBookmarkIndex::createBookmarkFromDrop(QDropEvent* event, QTreeWidgetItem* parentItem, int indexInParent)
+{
+ //qDebug("CBookmarkIndex::createBookmarkFromDrop");
+ //take the bookmark data from the mime source
+ const BTMimeData* mdata = dynamic_cast<const BTMimeData*>(event->mimeData());
+ if (mdata) {
+ //create the new bookmark
+ QString moduleName = mdata->bookmark().module();
+ QString keyText = mdata->bookmark().key();
+ QString description = mdata->bookmark().description();
+ CSwordModuleInfo* minfo = CPointers::backend()->findModuleByName(moduleName);
+
+ QTreeWidgetItem* newItem = new BtBookmarkItem(minfo, keyText, description);
+ parentItem->insertChild(indexInParent, newItem);
+ }
+}
+
+
+/** Load the tree from file */
+void CBookmarkIndex::initTree() {
+ qDebug("CBookmarkIndex::initTree");
+ BtBookmarkLoader loader;
+ addTopLevelItems(loader.loadTree());
+
+ // add the invisible extra item at the end
+ m_extraItem = new QTreeWidgetItem();
+ m_extraItem->setFlags(Qt::ItemIsDropEnabled);
+ addTopLevelItem(m_extraItem);
+}
+
+void CBookmarkIndex::slotItemEntered(QTreeWidgetItem* item, int)
+{
+ qDebug() << "CBookmarkIndex::slotItemEntered";
+ if (item == m_extraItem) {
+ m_extraItem->setText(0, tr("Drag references from text views to this view"));
+ }
+ else {
+ m_extraItem->setText(0, QString::null);
+ }
+}
+
+
+/** Returns the correct QAction object for the given type of action. */
+QAction* CBookmarkIndex::action( BtBookmarkItemBase::MenuAction type ) const {
+ switch (type) {
+ case BtBookmarkItemBase::NewFolder:
+ return m_actions.newFolder;
+ case BtBookmarkItemBase::ChangeFolder:
+ return m_actions.changeFolder;
+
+ case BtBookmarkItemBase::ChangeBookmark:
+ return m_actions.changeBookmark;
+ case BtBookmarkItemBase::ImportBookmarks:
+ return m_actions.importBookmarks;
+ case BtBookmarkItemBase::ExportBookmarks:
+ return m_actions.exportBookmarks;
+ case BtBookmarkItemBase::PrintBookmarks:
+ return m_actions.printBookmarks;
+
+ case BtBookmarkItemBase::DeleteEntries:
+ return m_actions.deleteEntries;
+
+ default:
+ return 0;
+ }
+}
+
+/** Shows the context menu at the given position. */
+void CBookmarkIndex::contextMenu(const QPoint& p)
+{
+ //qDebug("CBookmarkIndex::contextMenu");
+ //setup menu entries depending on current selection
+ QTreeWidgetItem* i = itemAt(p);
+ QList<QTreeWidgetItem *> items = selectedItems();
+ //The item which was clicked may not be selected
+ if (i && !items.contains(i) && i != m_extraItem)
+ items.append(i);
+
+ if (items.count() == 0) {
+ //special handling for no selection
+ BtBookmarkItemBase::MenuAction actionType;
+ for (int index = BtBookmarkItemBase::ActionBegin; index <= BtBookmarkItemBase::ActionEnd; ++index) {
+ actionType = static_cast<BtBookmarkItemBase::MenuAction>(index);
+ if (QAction* a = action(actionType)) {
+ switch (index) {
+ //case BtBookmarkItemBase::ExportBookmarks:
+ //case BtBookmarkItemBase::ImportBookmarks:
+ case BtBookmarkItemBase::NewFolder:
+ //case BtBookmarkItemBase::PrintBookmarks:
+ a->setEnabled(true);
+ break;
+ default:
+ a->setEnabled(false);
+ }
+ }
+ }
+ }
+ else if (items.count() == 1) {
+ //special handling for one selected item
+
+ BtBookmarkItemBase* item = dynamic_cast<BtBookmarkItemBase*>(items.at(0));
+ BtBookmarkItemBase::MenuAction actionType;
+ for (int index = BtBookmarkItemBase::ActionBegin; index <= BtBookmarkItemBase::ActionEnd; ++index) {
+ actionType = static_cast<BtBookmarkItemBase::MenuAction>(index);
+ if (QAction* a = action(actionType))
+ a->setEnabled( item->enableAction(actionType) );
+ }
+ }
+ else {
+ //first disable all actions
+ BtBookmarkItemBase::MenuAction actionType;
+ for (int index = BtBookmarkItemBase::ActionBegin; index <= BtBookmarkItemBase::ActionEnd; ++index) {
+ actionType = static_cast<BtBookmarkItemBase::MenuAction>(index);
+ if (QAction* a = action(actionType))
+ a->setEnabled(false);
+ }
+ //enable the menu items depending on the types of the selected items.
+ for (int index = BtBookmarkItemBase::ActionBegin; index <= BtBookmarkItemBase::ActionEnd; ++index) {
+ actionType = static_cast<BtBookmarkItemBase::MenuAction>(index);
+ bool enableAction = isMultiAction(actionType);
+ QListIterator<QTreeWidgetItem *> it(items);
+ while(it.hasNext()) {
+ BtBookmarkItemBase* i = dynamic_cast<BtBookmarkItemBase*>(it.next());
+ enableAction = enableAction && i->enableAction(actionType);
+ }
+ if (enableAction) {
+ QAction* a = action(actionType) ;
+ if (i && a)
+ a->setEnabled(enableAction);
+ }
+ }
+ }
+ //finally, open the popup
+ m_popup->exec(mapToGlobal(p));
+ //qDebug("CBookmarkIndex::contextMenu end");
+}
+
+/** Adds a new subfolder to the current item. */
+void CBookmarkIndex::createNewFolder() {
+ //qDebug("CBookmarkIndex::createNewFolder");
+ QList<QTreeWidgetItem*> selected = selectedItems();
+ if (selected.count() > 0) {
+ BtBookmarkFolder* i = dynamic_cast<BtBookmarkFolder*>(currentItem());
+ if (i) {
+ i->newSubFolder();
+ }
+ }
+ else {
+ // create a top level folder
+ BtBookmarkFolder* newFolder = new BtBookmarkFolder(0, QObject::tr("New folder"));
+ //parentFolder->addChild(newFolder);
+ insertTopLevelItem(topLevelItemCount()-1, newFolder);
+ newFolder->update();
+ newFolder->rename();
+ }
+}
+
+/** Opens a dialog to change the current folder. */
+void CBookmarkIndex::changeFolder() {
+ BtBookmarkFolder* i = dynamic_cast<BtBookmarkFolder*>(currentItem());
+ Q_ASSERT(i);
+ if (i) {
+ i->rename();
+ }
+}
+
+/** Changes the current bookmark. */
+void CBookmarkIndex::changeBookmark() {
+ BtBookmarkItem* i = dynamic_cast<BtBookmarkItem*>(currentItem());
+ Q_ASSERT(i);
+
+ if (i) {
+ i->rename();
+ }
+}
+
+/** Exports the bookmarks being in the selected folder. */
+void CBookmarkIndex::exportBookmarks() {
+ BtBookmarkFolder* i = dynamic_cast<BtBookmarkFolder*>(currentItem());
+ Q_ASSERT(i);
+
+ if (i) {
+ i->exportBookmarks();
+ }
+}
+
+/** Import bookmarks from a file and add them to the selected folder. */
+void CBookmarkIndex::importBookmarks() {
+ BtBookmarkFolder* i = dynamic_cast<BtBookmarkFolder*>(currentItem());
+ Q_ASSERT(i);
+
+ if (i) {
+ i->importBookmarks();
+ }
+}
+
+/** Prints the selected bookmarks. */
+void CBookmarkIndex::printBookmarks() {
+ Printing::CPrinter::KeyTree tree;
+ Printing::CPrinter::KeyTreeItem::Settings settings;
+ settings.keyRenderingFace = Printing::CPrinter::KeyTreeItem::Settings::CompleteShort;
+
+ QList<QTreeWidgetItem*> items;
+ BtBookmarkFolder* bf = dynamic_cast<BtBookmarkFolder*>(currentItem());
+
+ if (bf) {
+ items = bf->getChildList();
+ }
+ else {
+ items = selectedItems();
+ }
+
+ //create a tree of keytreeitems using the bookmark hierarchy.
+ QListIterator<QTreeWidgetItem*> it(items);
+ while(it.hasNext()) {
+ BtBookmarkItem* i = dynamic_cast<BtBookmarkItem*>(it.next());
+ if (i) {
+ qDebug() << "printBookmarks: add to list" << i->key();
+ tree.append( new Printing::CPrinter::KeyTreeItem( i->key(), i->module(), settings ) );
+ }
+ }
+
+ if (items.count() == 0) {
+ qWarning("Tried to print empty bookmark list.");
+ return;
+ }
+ boost::scoped_ptr<Printing::CPrinter> printer(
+ new Printing::CPrinter( this, CBTConfig::getDisplayOptionDefaults(), CBTConfig::getFilterOptionDefaults() )
+ );
+ printer->printKeyTree(tree);
+}
+
+/** Deletes the selected entries. */
+void CBookmarkIndex::deleteEntries(bool confirm)
+{
+ if (confirm) {
+ if (!selectedItems().count()) {
+ BtBookmarkItemBase* f = dynamic_cast<BtBookmarkItemBase*>(currentItem());
+ if (f) {
+ currentItem()->setSelected(true);
+ } else {
+ return;
+ }
+ }
+
+ if (QMessageBox::question(this, tr("Delete Items"), tr("Do you really want to delete the selected items and child-items?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes) {
+ return;
+ }
+ }
+
+ while (selectedItems().size() > 0) {
+ delete selectedItems().at(0); // deleting all does not work because it may cause double deletion
+ }
+
+}
+
+
+/*
+Reimplementation from QAbstractItemView/QTreeWidget. Takes care of movable items.
+It's easier to use this than to start drag with mouse event handlers.
+The default implementation would drag items, but we don't call it. Instead we create
+a BibleTime mimedata object. It can be dragged and dropped to a text view or somewhere else.
+The internal drag is handled differently, it doesn't use the mimedata (see dropEvent()).
+*/
+void CBookmarkIndex::startDrag(Qt::DropActions)
+{
+ qDebug("CBookmarkIndex::startDrag");
+
+ QMimeData* mData = dragObject(); // create the data which can be used in other widgets
+ QDrag* drag = new QDrag(this);
+ drag->setMimeData(mData);
+ drag->exec();
+
+ viewport()->update(); // because of the arrow
+}
+
+
+
+
+
+
+/* Returns true if more than one entry is supported by this action type. Returns false for actions which support only one entry, e.g. about module etc. */
+bool CBookmarkIndex::isMultiAction( const BtBookmarkItemBase::MenuAction type ) const {
+ switch (type) {
+ case BtBookmarkItemBase::NewFolder:
+ return false;
+ case BtBookmarkItemBase::ChangeFolder:
+ return false;
+
+ case BtBookmarkItemBase::ChangeBookmark:
+ return false;
+ case BtBookmarkItemBase::ImportBookmarks:
+ return false;
+ case BtBookmarkItemBase::ExportBookmarks:
+ return false;
+ case BtBookmarkItemBase::PrintBookmarks:
+ return true;
+
+ case BtBookmarkItemBase::DeleteEntries:
+ return true;
+ }
+
+ return false;
+}
+
+/* Saves the bookmarks to the default bookmarks file. */
+void CBookmarkIndex::saveBookmarks() {
+
+ qDebug("CBookmarkIndex::saveBookmarks()");
+ BtBookmarkLoader loader;
+ loader.saveTreeFromRootItem(invisibleRootItem());
+ //qDebug("CBookmarkIndex::saveBookmarks end");
+}
+
+void CBookmarkIndex::mouseMoveEvent(QMouseEvent* event)
+{
+ //qDebug() << "CBookmarkIndex::mouseMoveEvent";
+
+ // Restart the mag timer if we have moved to another item and shift was not pressed.
+ QTreeWidgetItem* itemUnderPointer = itemAt(event->pos());
+ if (itemUnderPointer && (itemUnderPointer != m_previousEventItem) ) {
+ //qDebug("CBookmarkIndex::mouseMoveEvent, moved onto another item");
+ if ( !(event->modifiers() & Qt::ShiftModifier)) {
+ m_magTimer.start(); // see the ctor for the timer properties
+ }
+ }
+ m_previousEventItem = itemUnderPointer;
+
+ // Clear the extra item text unless we are on top of it
+ if ( (itemUnderPointer != m_extraItem) && !m_extraItem->text(0).isNull()) {
+ m_extraItem->setText(0, QString::null);
+ }
+
+ QTreeWidget::mouseMoveEvent(event);
+}
+
+void CBookmarkIndex::magTimeout()
+{
+ //qDebug("CBookmarkIndex::magTimeout");
+
+ QTreeWidgetItem* itemUnderPointer = 0;
+ if (underMouse()) {
+ itemUnderPointer = itemAt(mapFromGlobal(QCursor::pos()));
+ }
+ // if the mouse pointer have been over the same item since the timer was started
+ if (itemUnderPointer && (m_previousEventItem == itemUnderPointer)) {
+ BtBookmarkItem* bitem = dynamic_cast<BtBookmarkItem*>(itemUnderPointer);
+ if (bitem) {
+ //qDebug("CBookmarkIndex::timerEvent: update the infodisplay");
+ // Update the mag
+ if (bitem->module()) {
+ (CPointers::infoDisplay())->setInfo(
+ InfoDisplay::CInfoDisplay::CrossReference,
+ bitem->module()->name() + ":" + bitem->key()
+ );
+ } else {
+ (CPointers::infoDisplay())->setInfo(InfoDisplay::CInfoDisplay::Text, tr("The work to which the bookmark points to is not installed."));
+ }
+
+ }
+ }
+}
+
+/*
+Creates a list of new items based on the current selection.
+If there are only bookmarks in the selection they are all included.
+If there is one folder it's included as a deep copy.
+Sets bookmarksOnly=false if it finds a folder.
+Sets targetIncluded=true if the target is in the list.
+Sets moreThanOneFolder=true if selection includes one folder and something more.
+If moreThanOneFolder or targetIncluded is detected the creation of list is stopped
+and the list is incomplete.
+*/
+QList<QTreeWidgetItem*> CBookmarkIndex::addItemsToDropTree(
+ QTreeWidgetItem* target, bool& bookmarksOnly, bool& targetIncluded, bool& moreThanOneFolder)
+{
+ qDebug() << "CBookmarkIndex::addItemsToDropTree";
+ QList<QTreeWidgetItem*> selectedList = selectedItems();
+ QList<QTreeWidgetItem*> newList;
+
+ foreach(QTreeWidgetItem* item, selectedList) {
+ qDebug() << "go through all items:" << item;
+ if ( BtBookmarkFolder* folder = dynamic_cast<BtBookmarkFolder*>(item)) {
+ bookmarksOnly = false;
+ if (selectedList.count() > 1) { // only one item allowed if a folder is selected
+ qDebug() << "one folder and something else is selected";
+ moreThanOneFolder = true;
+ break;
+ }
+ if (folder->hasDescendant(target)) { // dropping to self or descendand not allowed
+ qDebug() << "addItemsToDropTree: target is included";
+ targetIncluded = true;
+ break;
+ }
+ } else {
+ qDebug() << "append new QTreeWidget item (should be BtBookmarkItem?)";
+ newList.append(new BtBookmarkItem( *(dynamic_cast<BtBookmarkItem*>(item)) ));
+ }
+ }
+ if (!bookmarksOnly && selectedList.count() == 1) {
+ qDebug() << "exactly one folder";
+ BtBookmarkFolder* folder = dynamic_cast<BtBookmarkFolder*>(selectedList.value(0));
+ BtBookmarkFolder* copy = folder->deepCopy();
+ newList.append(copy);
+ }
+ if (!bookmarksOnly && selectedList.count() > 1) {
+ // wrong amount of items
+ qDebug() << "one folder and something else is selected 2";
+ moreThanOneFolder = true;
+ }
+ qDebug() << "return the new list" << newList;
+ return newList;
+}
+
diff --git a/src/frontend/mainindex/bookmarks/cbookmarkindex.h b/src/frontend/mainindex/bookmarks/cbookmarkindex.h
new file mode 100644
index 0000000..39e2df3
--- /dev/null
+++ b/src/frontend/mainindex/bookmarks/cbookmarkindex.h
@@ -0,0 +1,182 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CBOOKMARKINDEX_H
+#define CBOOKMARKINDEX_H
+
+//BibleTime includes
+#include "btbookmarkitembase.h"
+
+class CSwordModuleInfo;
+#include "frontend/displaywindow/cdisplaywindow.h"
+
+#include "util/cpointers.h"
+
+//Qt includes
+#include <QTimer>
+#include <QToolTip>
+#include <QList>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+
+class CSearchDialog;
+class CMainIndex;
+class QWidget;
+class QDropEvent;
+class QDragMoveEvent;
+class QDragLeaveEvent;
+class BTMimeData;
+class QMenu;
+class QAction;
+class QPaintEvent;
+
+class QMouseEvent;
+
+/**
+* The widget which manages all bookmarks.
+* @author The BibleTime team
+*/
+class CBookmarkIndex : public QTreeWidget {
+ Q_OBJECT
+
+public:
+ CBookmarkIndex(QWidget *parent);
+ virtual ~CBookmarkIndex();
+
+ void initTree();
+
+ /**
+ * Saves the bookmarks to disk
+ */
+ void saveBookmarks();
+
+signals:
+ /**
+ * Is emitted when a module should be opened,
+ */
+ void createReadDisplayWindow( QList<CSwordModuleInfo*>, const QString& );
+
+protected: // Protected methods
+
+ /** A hack to get the modifiers. */
+ virtual void mouseReleaseEvent(QMouseEvent* event);
+
+ /** Needed to paint an drag pointer arrow. */
+ virtual void paintEvent(QPaintEvent* event);
+
+ /** Initialize the SIGNAL<->SLOT connections. */
+ void initConnections();
+
+ /** Returns the drag object for the current selection. */
+ virtual QMimeData* dragObject();
+
+ /**
+ * D'n'd methods are reimplementations from QTreeWidget or its ancestors.
+ * In these we handle creating, moving and copying bookmarks with d'n'd.
+ */
+ virtual void dragEnterEvent( QDragEnterEvent* event );
+ virtual void dragMoveEvent( QDragMoveEvent* event );
+ virtual void dropEvent( QDropEvent* event );
+ virtual void dragLeaveEvent( QDragLeaveEvent* event );
+
+ /** Returns the correct action object for the given type of action. */
+ QAction* action( BtBookmarkItemBase::MenuAction type ) const;
+
+ /** Reimplementation from QAbstractItemView. Takes care of movable items. */
+ virtual void startDrag(Qt::DropActions supportedActions);
+
+
+ /** Handle mouse moving (mag updates) */
+ virtual void mouseMoveEvent(QMouseEvent* event);
+
+
+protected slots:
+
+ /** Prevents annoying folder collapsing while dropping. */
+ void expandAutoCollapsedItem(QTreeWidgetItem* i) {expandItem(i);}
+
+ /** Is called when an item was clicked or activated. */
+ void slotExecuted( QTreeWidgetItem* );
+
+ /** Shows the context menu at the given position. */
+ void contextMenu(const QPoint&);
+
+ /** Adds a new subfolder to the current item. */
+ void createNewFolder();
+
+ /** Opens a dialog to change the current folder. */
+ void changeFolder();
+
+ /** Exports the bookmarks from the selected folder. */
+ void exportBookmarks();
+
+ /** Changes the current bookmark. */
+ void changeBookmark();
+
+ /** Helps with the extra item. */
+ void slotItemEntered(QTreeWidgetItem*, int);
+
+ /** Import bookmarks from a file and add them to the selected folder. */
+ void importBookmarks();
+
+ /** Deletes the selected entries. */
+ void deleteEntries(bool confirm=true);
+
+ /** Prints the selected bookmarks. */
+ void printBookmarks();
+
+ /** Slot for the mag update timer. */
+ void magTimeout();
+
+private:
+
+ /** Initializes the view. */
+ void initView();
+
+ /** Convenience function for creating a new action. */
+ QAction* newQAction(const QString& text, const QString& pix, int shortcut, const QObject* receiver, const char* slot, QObject* parent);
+
+ /**
+ * Returns true if more than one entry is supported by this action type.
+ * Returns false for actions which support only one entry.
+ */
+ bool isMultiAction( const BtBookmarkItemBase::MenuAction type ) const;
+
+ /** A helper function for d'n'd which creates a new bookmark item when drop happens. */
+ void createBookmarkFromDrop(QDropEvent* event, QTreeWidgetItem* parentItem, int indexInParent);
+
+ /**
+ * Returns a list of new items created from the selection.
+ * Sets flags which indicate whether the selection was legal for dropping.
+ */
+ QList<QTreeWidgetItem*> addItemsToDropTree(QTreeWidgetItem* target, bool& bookmarksOnly, bool& targetIncluded, bool& moreThanOneFolder);
+
+ struct Actions {
+ QAction* newFolder;
+ QAction* changeFolder;
+
+ QAction* changeBookmark;
+ QAction* importBookmarks;
+ QAction* exportBookmarks;
+ QAction* printBookmarks;
+
+ QAction* deleteEntries;
+ }
+ m_actions;
+
+ QMenu* m_popup;
+ QTimer m_magTimer;
+ int m_mouseReleaseEventModifiers;
+ QTreeWidgetItem* m_previousEventItem;
+ QPoint m_dragMovementPosition;
+ QPoint m_dragStartPosition;
+ QTreeWidgetItem* m_extraItem;
+};
+
+#endif
diff --git a/src/frontend/mainindex/bookshelf/actionenum.h b/src/frontend/mainindex/bookshelf/actionenum.h
new file mode 100644
index 0000000..919e8ac
--- /dev/null
+++ b/src/frontend/mainindex/bookshelf/actionenum.h
@@ -0,0 +1,24 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef ACTIONENUM_H
+#define ACTIONENUM_H
+
+enum IndexAction {
+ EditModule,
+ UnlockModule,
+ HideModules,
+ ShowAllModules,
+ SearchModules,
+ UpdateModules,
+ Grouping,
+ AboutModule
+};
+
+#endif
diff --git a/src/frontend/mainindex/bookshelf/btindexfolder.cpp b/src/frontend/mainindex/bookshelf/btindexfolder.cpp
new file mode 100644
index 0000000..632817e
--- /dev/null
+++ b/src/frontend/mainindex/bookshelf/btindexfolder.cpp
@@ -0,0 +1,19 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btindexfolder.h"
+#include "backend/btmoduletreeitem.h"
+#include "util/directoryutil.h"
+
+BTIndexFolder::BTIndexFolder(BTModuleTreeItem* treeItem, QTreeWidgetItem* parent)
+ : BTIndexItem(parent)
+{
+ setText(0, treeItem->text());
+ setIcon(0, util::filesystem::DirectoryUtil::getIcon(treeItem->iconName()));
+}
diff --git a/src/frontend/mainindex/bookshelf/btindexfolder.h b/src/frontend/mainindex/bookshelf/btindexfolder.h
new file mode 100644
index 0000000..6c8f672
--- /dev/null
+++ b/src/frontend/mainindex/bookshelf/btindexfolder.h
@@ -0,0 +1,30 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTINDEXFOLDER_H
+#define BTINDEXFOLDER_H
+
+#include "btindexitem.h"
+
+#include <QString>
+
+class BTModuleTreeItem;
+
+/**
+ @author The BibleTime team <info@bibletime.info>
+*/
+class BTIndexFolder : public BTIndexItem
+{
+public:
+ BTIndexFolder(BTModuleTreeItem* treeItem, QTreeWidgetItem* p);
+
+ ~BTIndexFolder() {}
+};
+
+#endif
diff --git a/src/frontend/mainindex/bookshelf/btindexitem.cpp b/src/frontend/mainindex/bookshelf/btindexitem.cpp
new file mode 100644
index 0000000..2356f84
--- /dev/null
+++ b/src/frontend/mainindex/bookshelf/btindexitem.cpp
@@ -0,0 +1,19 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btindexitem.h"
+#include "cbookshelfindex.h"
+
+#include <QTreeWidgetItem>
+#include <QTreeWidget>
+
+
+BTIndexItem::BTIndexItem(QTreeWidgetItem* parent)
+ : QTreeWidgetItem(parent)
+{}
diff --git a/src/frontend/mainindex/bookshelf/btindexitem.h b/src/frontend/mainindex/bookshelf/btindexitem.h
new file mode 100644
index 0000000..33d2f7b
--- /dev/null
+++ b/src/frontend/mainindex/bookshelf/btindexitem.h
@@ -0,0 +1,45 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTINDEXITEM_H
+#define BTINDEXITEM_H
+
+#include "actionenum.h"
+
+#include <QTreeWidgetItem>
+#include <QString>
+
+class CMainIndex;
+class QMimeData;
+class QAction;
+
+
+/**
+@author The BibleTime team <info@bibletime.info>
+*/
+class BTIndexItem : public QTreeWidgetItem
+{
+public:
+ /** Those menu actions which are item specific. */
+
+ BTIndexItem(QTreeWidgetItem* parent);
+ virtual ~BTIndexItem() {};
+ /**
+ * Enables the given action if it has the "indexActionType" property which this item supports.
+ * Handles only those actions which may or may not be supported, not those which
+ * are always supported by all items. If the action is not supported in the current state of the
+ * item this function does nothing.
+ */
+ virtual bool enableAction(QAction*) const {return false;}
+
+ //TODO: d'n'd functions so that view can delegate d'n'd to items?
+ virtual bool acceptDrop(const QMimeData*) {return false;}
+};
+
+#endif
diff --git a/src/frontend/mainindex/bookshelf/btindexmodule.cpp b/src/frontend/mainindex/bookshelf/btindexmodule.cpp
new file mode 100644
index 0000000..91a9f2f
--- /dev/null
+++ b/src/frontend/mainindex/bookshelf/btindexmodule.cpp
@@ -0,0 +1,93 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btindexmodule.h"
+
+#include "backend/btmoduletreeitem.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "util/directoryutil.h"
+#include "frontend/cdragdrop.h"
+
+#include <QIcon>
+#include <QString>
+#include <QDebug>
+#include <QAction>
+
+
+
+BTIndexModule::BTIndexModule(BTModuleTreeItem* treeItem, QTreeWidgetItem* previous)
+ : BTIndexItem(previous)
+{
+ //qDebug("BTIndexModule::BTIndexModule");
+ setText(0, treeItem->text()); //set text
+ setIcon(0, util::filesystem::DirectoryUtil::getIcon(treeItem->iconName()) );
+ m_moduleInfo = treeItem->moduleInfo();
+ setToolTip(0, CToolClass::moduleToolTip(moduleInfo()) );
+
+ setFlags(Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled|Qt::ItemIsSelectable);
+ if (!m_moduleInfo->isHidden()) {
+ setFlags(flags()|Qt::ItemIsEnabled);
+ }
+}
+
+
+BTIndexModule::~BTIndexModule()
+{
+}
+
+
+bool BTIndexModule::enableAction(QAction* action) const
+{
+ if (!action->isEnabled()) {
+ IndexAction actionType = (IndexAction)action->property("indexActionType").toInt();
+
+ switch (actionType) {
+ case EditModule:
+ if (moduleInfo()->isWritable()) action->setEnabled(true);
+ break;
+ case UnlockModule:
+ if (moduleInfo()->isEncrypted()) action->setEnabled(true);
+ break;
+ case HideModules:
+ if (!m_moduleInfo->isHidden()) action->setEnabled(true);
+ case UpdateModules:
+ break;
+ case AboutModule:
+ case Grouping:
+ case SearchModules:
+ case ShowAllModules: break;
+ }
+ }
+ return true; //TODO: check, is this correct?
+}
+
+
+bool BTIndexModule::acceptDrop(const QMimeData* data)
+{
+ //TODO: check the module type of the reference, accept only proper type.
+ // Bible accepts biblical references and plain text (for search),
+ // but it could accept a lexicon entry too for search, especially a Strong's entry.
+ // Lexicon could accept lexicon references but also biblical references to find all places where
+ // the verse is referred to. Same with genbooks.
+
+ const BTMimeData* btData = dynamic_cast<const BTMimeData*>(data);
+ if (btData) {
+ return true;
+ }
+ if (data->hasText()) {
+ return true;
+ }
+ return false;
+}
+
+
+CSwordModuleInfo* BTIndexModule::moduleInfo() const
+{
+ return m_moduleInfo;
+}
diff --git a/src/frontend/mainindex/bookshelf/btindexmodule.h b/src/frontend/mainindex/bookshelf/btindexmodule.h
new file mode 100644
index 0000000..cbd711c
--- /dev/null
+++ b/src/frontend/mainindex/bookshelf/btindexmodule.h
@@ -0,0 +1,39 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTINDEXMODULE_H
+#define BTINDEXMODULE_H
+
+#include "btindexitem.h"
+
+#include "util/ctoolclass.h"
+
+class BTModuleTreeItem;
+class CSwordModuleInfo;
+
+class QAction;
+class QMimeData;
+
+
+class BTIndexModule : public BTIndexItem
+{
+public:
+ BTIndexModule(BTModuleTreeItem* treeItem, QTreeWidgetItem* previous);
+
+ ~BTIndexModule();
+
+ virtual bool enableAction(QAction* action) const;
+ virtual bool acceptDrop(const QMimeData* data);
+ CSwordModuleInfo* moduleInfo() const;
+
+private:
+ CSwordModuleInfo* m_moduleInfo;
+};
+
+#endif
diff --git a/src/frontend/mainindex/bookshelf/cbookshelfindex.cpp b/src/frontend/mainindex/bookshelf/cbookshelfindex.cpp
new file mode 100644
index 0000000..1c6db2a
--- /dev/null
+++ b/src/frontend/mainindex/bookshelf/cbookshelfindex.cpp
@@ -0,0 +1,722 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cbookshelfindex.h"
+
+#include "btindexitem.h"
+#include "btindexmodule.h"
+#include "btindexfolder.h"
+#include "chidemodulechooserdialog.h"
+
+#include "backend/btmoduletreeitem.h"
+#include "backend/managers/creferencemanager.h"
+
+#include "frontend/searchdialog/csearchdialog.h"
+#include "backend/config/cbtconfig.h"
+#include "frontend/cinfodisplay.h"
+#include "frontend/btaboutmoduledialog.h"
+#include "frontend/cprinter.h"
+#include "frontend/cdragdrop.h"
+
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+
+//Qt includes
+#include <QDragLeaveEvent>
+#include <QDragMoveEvent>
+#include <QDropEvent>
+#include <QHeaderView> //for hiding the header
+#include <QTimer> // for delayed auto-opening of folders
+#include <QList>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+#include <QInputDialog> // for unlocking key
+#include <QDebug>
+#include <QMenu>
+
+#include <boost/scoped_ptr.hpp>
+
+
+
+CBookshelfIndex::CBookshelfIndex(QWidget *parent)
+ : QTreeWidget(parent),
+ m_searchDialog(0),
+ m_autoOpenFolder(0),
+ m_autoOpenTimer(this)
+{
+ m_grouping = (BTModuleTreeItem::Grouping)CBTConfig::get(CBTConfig::bookshelfGrouping);
+ m_showHidden = CBTConfig::get(CBTConfig::bookshelfShowHidden);
+ setContextMenuPolicy(Qt::CustomContextMenu);
+ initView();
+ initConnections();
+ initTree();
+}
+
+CBookshelfIndex::~CBookshelfIndex() {}
+
+
+
+/** Initializes the view. */
+void CBookshelfIndex::initView()
+{
+// qDebug("CBookshelfIndex::initView");
+
+ header()->hide();
+
+ setFocusPolicy(Qt::WheelFocus);
+ setAcceptDrops( false ); // TODO: accept drops
+ setDragEnabled( true );
+ setDropIndicatorShown( true );
+
+ setItemsExpandable(true);
+ viewport()->setAcceptDrops(false); //TODO: accept drops
+ setRootIsDecorated(false);
+ setAllColumnsShowFocus(true);
+ setSelectionMode(QAbstractItemView::ExtendedSelection);
+
+ //setup the popup menu
+ m_popup = new QMenu(viewport());
+ m_popup->setTitle(tr("Bookshelf"));
+
+ initActions();
+
+// qDebug("CBookshelfIndex::initView end");
+}
+
+void CBookshelfIndex::initActions()
+{
+
+ // Each action has a type attached to it as a dynamic property, see actionenum.h.
+ // Menuitem and its subitems can have the same type.
+ // Actions can have also "singleItemAction" property if
+ // it supports only one item.
+ // See contextMenu() and BTIndexItem for how these properties are used later.
+
+ // Actions are added to the popup menu and also to a list for easy foreach access.
+
+ QMenu* actionMenu = 0;
+ QAction* action = 0;
+
+ // -------------------------Grouping --------------------------------------
+ actionMenu = new QMenu(tr("Grouping"), this);
+ actionMenu->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::mainIndex::grouping::icon));
+ actionMenu->setProperty("indexActionType", QVariant(Grouping));
+
+ m_groupingGroup = new QActionGroup(this);
+ QObject::connect(m_groupingGroup, SIGNAL(triggered(QAction*)), this, SLOT(actionChangeGrouping(QAction*)) );
+
+ //TODO: set the inital checked state
+ action = newQAction(tr("Category/Language"), CResMgr::mainIndex::grouping::icon, 0, 0, 0, this);
+ action->setCheckable(true);
+ action->setProperty("indexActionType", QVariant(Grouping));
+ action->setProperty("grouping", BTModuleTreeItem::CatLangMod);
+ actionMenu->addAction(action);
+ m_groupingGroup->addAction(action);
+ if (m_grouping == BTModuleTreeItem::CatLangMod) action->setChecked(true);
+ m_actionList.append(action);
+
+ action = newQAction(tr("Category"),CResMgr::mainIndex::grouping::icon, 0, 0, 0, this);
+ action->setCheckable(true);
+ m_groupingGroup->addAction(action);
+ if (m_grouping == BTModuleTreeItem::CatMod) action->setChecked(true);
+ action->setProperty("indexActionType", QVariant(Grouping));
+ action->setProperty("grouping", BTModuleTreeItem::CatMod);
+ actionMenu->addAction(action);
+ m_actionList.append(action);
+
+ action = newQAction(tr("Language/Category"),CResMgr::mainIndex::grouping::icon, 0, 0, 0, this);
+ action->setCheckable(true);
+ m_groupingGroup->addAction(action);
+ if (m_grouping == BTModuleTreeItem::LangCatMod) action->setChecked(true);
+ actionMenu->addAction(action);
+ action->setProperty("indexActionType", QVariant(Grouping));
+ action->setProperty("grouping", BTModuleTreeItem::LangCatMod);
+ m_actionList.append(action);
+
+ action = newQAction(tr("Language"),CResMgr::mainIndex::grouping::icon, 0, 0, 0, this);
+ action->setCheckable(true);
+ m_groupingGroup->addAction(action);
+ if (m_grouping == BTModuleTreeItem::LangMod) action->setChecked(true);
+ actionMenu->addAction(action);
+ action->setProperty("indexActionType", QVariant(Grouping));
+ action->setProperty("grouping", BTModuleTreeItem::LangMod);
+ m_actionList.append(action);
+
+ action = newQAction(tr("Works only"),CResMgr::mainIndex::grouping::icon, 0, 0, 0, this);
+ action->setCheckable(true);
+ m_groupingGroup->addAction(action);
+ if (m_grouping == BTModuleTreeItem::Mod) action->setChecked(true);
+ actionMenu->addAction(action);
+ action->setProperty("indexActionType", QVariant(Grouping));
+ action->setProperty("grouping", BTModuleTreeItem::Mod);
+ m_actionList.append(action);
+
+ action = m_popup->addMenu(actionMenu);
+ action->setProperty("indexActionType", QVariant(Grouping));
+ m_actionList.append(action);
+
+
+ // ------------Hide---------------------
+ action = newQAction(tr("Hide/unhide works..."),CResMgr::mainIndex::search::icon, 0, this, SLOT(actionHideModules()), this);
+ action->setProperty("indexActionType", QVariant(HideModules));
+ //action->setProperty("multiItemAction", QVariant(true));
+ m_popup->addAction(action);
+ m_actionList.append(action);
+
+// -------------------Show hidden---------------------------
+ action = newQAction(tr("Show hidden"),CResMgr::mainIndex::search::icon, 0, 0, 0, this);
+ action->setProperty("indexActionType", QVariant(ShowAllModules));
+ action->setCheckable(true);
+ QObject::connect(action, SIGNAL(toggled(bool)), this, SLOT(actionShowModules(bool)));
+ if (m_showHidden) action->setChecked(true); else action->setChecked(false);
+ m_popup->addAction(action);
+ m_actionList.append(action);
+
+
+ m_popup->addSeparator();
+
+ //------------------------------------------------------------
+ //----------------- Actions for items ------------------------
+
+ // -------------------------Edit module --------------------------------
+ actionMenu = new QMenu(tr("Edit"), this);
+ actionMenu->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::mainIndex::editModuleMenu::icon) );
+// actionMenu->setDelayed(false);
+ actionMenu->setProperty("indexActionType", QVariant(EditModule));
+ actionMenu->setProperty("singleItemAction", QVariant(true));
+ //m_actionList.append(actionMenu);
+
+ action = newQAction(tr("Plain text..."),CResMgr::mainIndex::editModulePlain::icon, 0, this, SLOT(actionEditModulePlain()), this);
+ actionMenu->addAction(action);
+ m_actionList.append(action);
+ action->setProperty("indexActionType", QVariant(EditModule));
+ action->setProperty("singleItemAction", QVariant(true));
+
+ action = newQAction(tr("HTML..."),CResMgr::mainIndex::editModuleHTML::icon, 0, this, SLOT(actionEditModuleHTML()), this);
+ actionMenu->addAction(action);
+ m_actionList.append(action);
+ action->setProperty("indexActionType", QVariant(EditModule));
+ action->setProperty("singleItemAction", QVariant(true));
+
+ m_actionList.append(m_popup->addMenu(actionMenu));
+
+
+ // ------------------------ Misc actions -------------------------------------
+ action = newQAction(tr("Search..."),CResMgr::mainIndex::search::icon, 0, this, SLOT(actionSearchInModules()), this);
+ action->setProperty("indexActionType", QVariant(SearchModules));
+ action->setProperty("multiItemAction", QVariant(true));
+ m_popup->addAction(action);
+ m_actionList.append(action);
+
+ action = newQAction(tr("Unlock..."),CResMgr::mainIndex::unlockModule::icon, 0, this, SLOT(actionUnlockModule()), this);
+ m_popup->addAction(action);
+ action->setProperty("indexActionType", QVariant(UnlockModule));
+ action->setProperty("singleItemAction", QVariant(true));
+ m_actionList.append(action);
+
+ action = newQAction(tr("About..."),CResMgr::mainIndex::aboutModule::icon, 0, this, SLOT(actionAboutModule()), this);
+ m_popup->addAction(action);
+ action->setProperty("singleItemAction", QVariant(true));
+ action->setProperty("indexActionType", QVariant(AboutModule));
+ m_actionList.append(action);
+
+
+}
+
+/** Convenience function for creating a new QAction.
+* Should be replaced with something better; it was easier to make a new function
+* than to modify all QAction constructors.
+*/
+QAction* CBookshelfIndex::newQAction(const QString& text, const QString& pix, const int /*shortcut*/, const QObject* receiver, const char* slot, QObject* parent)
+{
+ QAction* action = new QAction(util::filesystem::DirectoryUtil::getIcon(pix), text, parent);
+ if (receiver && !QString(slot).isEmpty())
+ {
+ QObject::connect(action, SIGNAL(triggered()), receiver, slot);
+ }
+ return action;
+}
+
+/** Initialize the SIGNAL<->SLOT connections */
+void CBookshelfIndex::initConnections()
+{
+ //Connect this to the backend module list changes.
+ bool ok;
+ ok = connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), SLOT(reloadSword(CSwordBackend::SetupChangedReason)));
+ Q_ASSERT(ok);
+
+ ok = connect(this, SIGNAL(itemActivated(QTreeWidgetItem*, int)), this, SLOT(slotExecuted(QTreeWidgetItem*)));
+ Q_ASSERT(ok);
+
+ // Single/double click item activation is style dependend
+ if (style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) == 0)
+ {
+ ok = connect(this, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(slotExecuted(QTreeWidgetItem*)));
+ Q_ASSERT(ok);
+ }
+
+ ok = connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(contextMenu(const QPoint&)));
+ Q_ASSERT(ok);
+
+ ok = connect(&m_autoOpenTimer, SIGNAL(timeout()), this, SLOT(autoOpenTimeout()));
+ Q_ASSERT(ok);
+
+ ok = connect(this, SIGNAL(itemSelectionChanged()), this, SLOT(slotModifySelection()));
+ Q_ASSERT(ok);
+}
+
+void CBookshelfIndex::slotModifySelection()
+{
+ // This creates recursion if a folder is selected, but not infinite.
+ //qDebug("CBookshelfIndex::slotModifySelection");
+ QList<QTreeWidgetItem*> selection = selectedItems();
+ foreach (QTreeWidgetItem* item, selection) {
+ BTIndexFolder* folder = dynamic_cast<BTIndexFolder*>(item);
+ if (folder) {
+ item->setSelected(false);
+ break;
+ }
+ }
+}
+
+/**
+* Hack to get single click and selection working. See slotExecuted.
+*/
+void CBookshelfIndex::mouseReleaseEvent(QMouseEvent* event) {
+ //qDebug("CBookshelfIndex::mouseReleaseEvent");
+ //qDebug() << event->type() << event->modifiers();
+ if (itemAt(event->pos())) {
+ if (m_frozenModules.contains( itemAt(event->pos())->text(0) )) {
+ //do nothing
+ event->accept();
+ return;
+ }
+ }
+ m_mouseReleaseEventModifiers = event->modifiers();
+ QTreeWidget::mouseReleaseEvent(event);
+
+}
+
+/** Called when an item is clicked with mouse or activated with keyboard. */
+void CBookshelfIndex::slotExecuted( QTreeWidgetItem* i )
+{
+ qDebug("CBookshelfIndex::slotExecuted");
+
+ //HACK: checking the modifier keys from the last mouseReleaseEvent
+ //depends on executing order: mouseReleaseEvent first, then itemClicked signal
+ int modifiers = m_mouseReleaseEventModifiers;
+ m_mouseReleaseEventModifiers = Qt::NoModifier;
+ if (modifiers != Qt::NoModifier) {
+ return;
+ }
+
+ BTIndexItem* btItem = dynamic_cast<BTIndexItem*>(i);
+ if (!btItem) {
+ qWarning("item was not BTIndexItem!");
+ return;
+ }
+
+ if (BTIndexModule* m = dynamic_cast<BTIndexModule*>(i)) { //clicked on a module
+ CSwordModuleInfo* mod = m->moduleInfo();
+ if (!m_frozenModules.contains(mod->name())) {
+ m_frozenModules.insert(mod->name());
+ QList<CSwordModuleInfo*> modules;
+ modules.append(mod);
+ qDebug("will emit createReadDisplayWindow");
+ emit createReadDisplayWindow(modules, QString::null);
+
+ }
+ } else {
+ i->setExpanded( !i->isExpanded() );
+ }
+}
+
+void CBookshelfIndex::unfreezeModules(QList<CSwordModuleInfo*> modules)
+{
+ foreach (CSwordModuleInfo* mInfo, modules) {
+ m_frozenModules.remove(mInfo->name());
+ }
+}
+
+/** Reimplementation. Returns the drag object for the current selection. */
+QMimeData* CBookshelfIndex::dragObject()
+{
+ //TODO: we have to add a mime type "module" if we want to for example enable draggin a module to a displaywindow
+ return 0;
+}
+
+
+/** Reimplementation from QTreeWidget. Returns true if the drag is acceptable for the widget. */
+void CBookshelfIndex::dragEnterEvent( QDragEnterEvent* event )
+{
+ //qDebug("CBookshelfIndex::dragEnterEvent");
+ event->acceptProposedAction();
+}
+
+void CBookshelfIndex::dragMoveEvent( QDragMoveEvent* event )
+{
+ const QPoint pos = event->pos();
+
+ BTIndexItem* i = dynamic_cast<BTIndexItem*>(itemAt(pos));
+ //TODO: implement accepting drop in item
+ if (i && i->acceptDrop(event->mimeData()) ) {
+ event->acceptProposedAction();
+ } else {
+ event->ignore();
+ }
+}
+
+void CBookshelfIndex::dropEvent( QDropEvent* event )
+{
+ const QPoint pos = event->pos();
+
+ BTIndexItem* i = dynamic_cast<BTIndexItem*>(itemAt(pos));
+ //TODO: implement accepting drop in item
+ if (i && i->acceptDrop(event->mimeData()) ) {
+ QMenu* menu = new QMenu(this);
+ QAction* openAction = menu->addAction("Open reference in new subwindow");
+ QAction* searchRefAction = menu->addAction("Search for reference as crossreference");
+ QAction* searchAction = menu->addAction("Search text");
+ QAction* selectedAction = menu->exec(this->mapToGlobal(pos));
+ if (selectedAction == openAction) {;}
+ if (selectedAction == searchAction) {;}
+ if (selectedAction == searchRefAction) {;}
+ event->acceptProposedAction();
+ } else {
+ event->ignore();
+ }
+}
+
+void CBookshelfIndex::changeEvent(QEvent* e)
+{
+ if (e->type() == QEvent::StyleChange) {
+ // Single/double click item activation is style dependend
+ QObject::disconnect(this, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(slotExecuted(QTreeWidgetItem*)));
+ if (style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) == 0) {
+ QObject::connect(this, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(slotExecuted(QTreeWidgetItem*)));
+ }
+ }
+ QTreeWidget::changeEvent(e);
+}
+
+/** No descriptions */
+void CBookshelfIndex::initTree() {
+ qDebug("CBookshelfIndex::initTree");
+
+ //first clean the tree
+ clear();
+ //m_grouping = (BTModuleTreeItem::Grouping)CBTConfig::get(CBTConfig::bookshelfGrouping);
+
+ BTModuleTreeItem::HiddenOff hiddenFilter;
+ QList<BTModuleTreeItem::Filter*> filters;
+ if (!m_showHidden) {
+ filters.append(&hiddenFilter);
+ }
+ BTModuleTreeItem root(filters, m_grouping);
+ addToTree(&root, this->invisibleRootItem());
+}
+
+void CBookshelfIndex::addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem)
+{
+ foreach (BTModuleTreeItem* i, item->children()) {
+ if (i->type() == BTModuleTreeItem::Module) {
+ addToTree(i, new BTIndexModule(i, widgetItem));
+ }
+ else
+ addToTree(i, new BTIndexFolder(i, widgetItem));
+ }
+ // Possible TODO: if item is Language and it's under Category and Category is Glossaries,
+ // add the second language name - but how to add other language group?
+ // do we have to modify btmoduletreeitem?
+}
+
+
+/** No descriptions */
+void CBookshelfIndex::emitModulesChosen( QList<CSwordModuleInfo*> modules, QString key ) {
+ emit createReadDisplayWindow(modules, key);
+}
+
+
+
+/** Shows the context menu at the given position. */
+void CBookshelfIndex::contextMenu(const QPoint& p) {
+ qDebug("CBookshelfIndex::contextMenu");
+ qDebug() << "list of actions: ";
+ foreach (QAction* action, m_actionList) {
+ qDebug() << action->text();
+ }
+ //setup menu entries depending on current selection
+ QTreeWidgetItem* i = itemAt(p);
+ qDebug() << "item at point: " << i;
+ QList<QTreeWidgetItem *> items = selectedItems();
+ //The item which was clicked may not be selected - but don't add folder
+ if (i && !dynamic_cast<BTIndexFolder*>(i) && !items.contains(i))
+ items.append(i);
+
+ // disable those menu entries which are item dependent,
+ // dis/enable some others
+ qDebug()<<"grouping action type:"<<(int)Grouping;
+ foreach (QAction* action, m_actionList) {
+ IndexAction actionType = (IndexAction)action->property("indexActionType").toInt();
+ qDebug() << "action type:" << actionType;
+ if ( actionType == Grouping ) {
+ qDebug()<<"grouping action, enabling...";
+ action->setEnabled(true);
+ qDebug()<< action->isEnabled();
+ }
+ else if (actionType == ShowAllModules) {
+ //enabled only if there are hidden modules
+ if (!CBTConfig::get(CBTConfig::hiddenModules).empty()) {
+ action->setEnabled(true);
+ } else {
+ action->setEnabled(false);
+ }
+ action->setChecked(m_showHidden);
+
+ }
+ else if (actionType == SearchModules) {
+ action->setText(tr("Search"));
+ if (items.count() > 0)
+ action->setEnabled(true);
+ else action->setEnabled(false);
+ }
+ else if (actionType == HideModules) {
+ //action->setText(tr("Hide"));
+ action->setEnabled(true);
+ }
+ else action->setEnabled(false);
+ }
+
+
+ if (items.count() == 0) {
+ //special handling for no selection: do nothing
+ }
+
+ if (items.count() == 1) {
+ //special handling for one selected item
+ qDebug("there was one selected item");
+ BTIndexItem* btItem = dynamic_cast<BTIndexItem*>(items.at(0));
+
+ if (btItem && !dynamic_cast<BTIndexFolder*>(btItem)) {
+ foreach (QAction* action, m_actionList) {
+ if ( (IndexAction)action->property("indexActionType").toInt() == AboutModule ) {
+ qDebug() << "enabling action" << action->text();
+ action->setEnabled(true);
+ }
+ else if ((IndexAction)action->property("indexActionType").toInt() == SearchModules ) {
+ // Change the text of the menu item to reflect the module name
+ BTIndexModule* modItem = dynamic_cast<BTIndexModule*>(btItem);
+ if (modItem) {
+ CSwordModuleInfo* info = modItem->moduleInfo();
+ action->setText(tr("Search in %1...").arg(info->name()));
+ }
+ }
+ else {
+ qDebug() << "ask item" << items.at(0)->text(0) << "to enable the action" << action->text();
+ btItem->enableAction(action);
+ }
+ qDebug() << "action enabled is: " << action->isEnabled();
+ }
+ }
+ }
+ else { // more than one item
+ foreach (QAction* action, m_actionList) {
+ // Change the text of some menu items to reflect multiple selection
+ if ((IndexAction)action->property("indexActionType").toInt() == SearchModules ) {
+ action->setText(tr("Search in selected..."));
+ }
+ // Enable items
+ foreach(QTreeWidgetItem* item, items) {
+ BTIndexItem* btItem = dynamic_cast<BTIndexItem*>(item);
+ if (btItem && !action->property("singleItemAction").isValid()) {
+ btItem->enableAction(action);
+ }
+ }
+ }
+ }
+
+ //finally, open the popup
+ m_popup->exec(mapToGlobal(p));
+}
+
+void CBookshelfIndex::actionChangeGrouping(QAction* action)
+{
+ BTModuleTreeItem::Grouping grouping = (BTModuleTreeItem::Grouping)action->property("grouping").toInt();
+ m_grouping = grouping;
+ CBTConfig::set(CBTConfig::bookshelfGrouping, grouping);
+ initTree();
+}
+
+
+/** Opens the searchdialog for the selected modules. */
+void CBookshelfIndex::actionSearchInModules() {
+ QList<QTreeWidgetItem *> items = selectedItems();
+ QListIterator<QTreeWidgetItem *> it(items);
+ QList<CSwordModuleInfo*> modules;
+ while(it.hasNext()) {
+ if (BTIndexModule* i = dynamic_cast<BTIndexModule*>(it.next())) {
+ if (i->moduleInfo()) {
+ modules.append(i->moduleInfo());
+ }
+ }
+ }
+
+ if (modules.isEmpty()) { //get a list of useful default modules for the search if no modules were selected
+ CSwordModuleInfo* m = CBTConfig::get(CBTConfig::standardBible);
+ if (m) {
+ modules.append(m);
+ }
+ }
+
+ Search::CSearchDialog::openDialog(modules, QString::null);
+}
+
+/** Unlocks the current module. */
+void CBookshelfIndex::actionUnlockModule() {
+ if (BTIndexModule* i = dynamic_cast<BTIndexModule*>(currentItem())) {
+ bool ok = false;
+ const QString unlockKey =
+ QInputDialog::getText(
+ this,
+ tr("Unlock Work"),
+ tr("Enter the unlock key for this work."),
+ QLineEdit::Normal,
+ i->moduleInfo()->config(CSwordModuleInfo::CipherKey),
+ &ok
+ );
+
+ if (ok) {
+ i->moduleInfo()->unlock( unlockKey );
+ CPointers::backend()->reloadModules(CSwordBackend::OtherChange);
+ }
+ }
+}
+
+void CBookshelfIndex::actionShowModules(bool checked)
+{
+ qDebug("CBookshelfIndex::actionShowModules");
+ m_showHidden = checked;
+ CBTConfig::set(CBTConfig::bookshelfShowHidden, m_showHidden);
+ // show hidden status is changed, notify others who may rebuild their module lists
+ CPointers::backend()->notifyChange(CSwordBackend::HidedModules);
+
+}
+
+void CBookshelfIndex::actionHideModules()
+{
+ qDebug("CBookshelfIndex::actionHideModules");
+ QString current;
+ if (BTIndexModule* i = dynamic_cast<BTIndexModule*>(currentItem())) {
+ current = i->text(0);
+ }
+
+ QString title(tr("Hide/Unhide Works"));
+ QString label(tr("Select the works to be hidden."));
+ CHideModuleChooserDialog* dlg = new CHideModuleChooserDialog(this, title, label, current);
+ connect(dlg, SIGNAL(modulesChanged(QList<CSwordModuleInfo*>)),
+ this, SLOT(setHiddenModules(QList<CSwordModuleInfo*>)));
+ int code = dlg->exec();
+ if (code == QDialog::Accepted) {
+ // notify all who may rebuild their module lists
+ CPointers::backend()->notifyChange(CSwordBackend::HidedModules);
+ }
+}
+
+
+/** Shows information about the current module. */
+void CBookshelfIndex::actionAboutModule() {
+ if (BTIndexModule* i = dynamic_cast<BTIndexModule*>(currentItem())) {
+ BTAboutModuleDialog* dialog = new BTAboutModuleDialog(this, i->moduleInfo());
+ dialog->show();
+ dialog->raise();
+ }
+}
+
+/** Reimplementation. Takes care of movable items. */
+void CBookshelfIndex::startDrag(Qt::DropActions /*supportedActions*/) {
+
+}
+
+/** Reimplementation to support the items dragEnter and dragLeave functions. */
+void CBookshelfIndex::contentsDragMoveEvent( QDragMoveEvent* /*event*/ ) {
+// // qWarning("void CBookshelfIndex:: drag move event ( QDragLeaveEvent* e )");
+// CIndexItemBase* i = dynamic_cast<CIndexItemBase*>( itemAt( contentsToViewport(event->pos())) );
+// if (i) {
+// if (i->allowAutoOpen(event) || (i->acceptDrop(event) && i->isFolder() && i->allowAutoOpen(event) && !i->isOpen() && autoOpen()) ) {
+// if (m_autoOpenFolder != i) {
+// m_autoOpenTimer.stop();
+// }
+//
+// m_autoOpenFolder = i;
+// m_autoOpenTimer.start( 400 );
+// }
+// else {
+// m_autoOpenFolder = 0;
+// }
+// }
+// else {
+// m_autoOpenFolder = 0;
+// }
+//
+// QTreeWidget::contentsDragMoveEvent(event);
+}
+
+
+void CBookshelfIndex::autoOpenTimeout() {
+ m_autoOpenTimer.stop();
+ if (m_autoOpenFolder && !m_autoOpenFolder->isExpanded() && m_autoOpenFolder->childCount()) {
+ m_autoOpenFolder->setExpanded(true);
+ }
+}
+
+/** No descriptions */
+void CBookshelfIndex::contentsDragLeaveEvent( QDragLeaveEvent* /*e*/ ) {
+// m_autoOpenTimer.stop();
+// QTreeWidget::contentsDragLeaveEvent(e);
+}
+
+
+/** Opens an editor window to edit the modules content. */
+void CBookshelfIndex::actionEditModulePlain() {
+ QList<CSwordModuleInfo*> modules;
+ QList<QTreeWidgetItem *> items = selectedItems();
+ QListIterator<QTreeWidgetItem *> it(items);
+ //loop through items
+ while(it.hasNext()) {
+ if (BTIndexModule* i = dynamic_cast<BTIndexModule*>(it.next())) {
+ modules.append(i->moduleInfo());
+ }
+ }
+ if (modules.count() == 1) {
+ emit createWriteDisplayWindow(modules.first(), QString::null, CDisplayWindow::PlainTextWindow);
+ };
+}
+
+/** Opens an editor window to edit the modules content. */
+void CBookshelfIndex::actionEditModuleHTML() {
+ QList<CSwordModuleInfo*> modules;
+ QList<QTreeWidgetItem *> items = selectedItems();
+ QListIterator<QTreeWidgetItem *> it(items);
+ while(it.hasNext()) {
+ if (BTIndexModule* i = dynamic_cast<BTIndexModule*>(it.next())) {
+ modules.append(i->moduleInfo());
+ }
+ }
+
+ if (modules.count() == 1) {
+ emit createWriteDisplayWindow(modules.first(), QString::null, CDisplayWindow::HTMLWindow);
+ }
+}
+
+/** Reloads the main index's Sword dependend things like modules */
+void CBookshelfIndex::reloadSword(CSwordBackend::SetupChangedReason) {
+ //reload the modules
+ qDebug("CBookshelfIndex::reloadSword");
+ initTree();
+}
diff --git a/src/frontend/mainindex/bookshelf/cbookshelfindex.h b/src/frontend/mainindex/bookshelf/cbookshelfindex.h
new file mode 100644
index 0000000..f9e56e7
--- /dev/null
+++ b/src/frontend/mainindex/bookshelf/cbookshelfindex.h
@@ -0,0 +1,207 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CBOOKSHELFINDEX_H
+#define CBOOKSHELFINDEX_H
+
+//BibleTime includes
+#include "btindexitem.h"
+#include "backend/btmoduletreeitem.h"
+class CSwordModuleInfo;
+#include "frontend/displaywindow/cdisplaywindow.h"
+
+#include "util/cpointers.h"
+
+//Qt includes
+#include <QTimer>
+#include <QList>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+
+
+
+class CSearchDialog;
+class CMainIndex;
+class QWidget;
+class QDropEvent;
+class QDragMoveEvent;
+class QDragLeaveEvent;
+class BTMimeData;
+class QMenu;
+class QActionGroup;
+class QMouseEvent;
+class BTModuleTreeItem;
+
+
+
+/**
+* The widget which manages the modules. The modules are put into own,
+* fixed subfolders sorted by category and/or language.
+* @author The BibleTime team
+*/
+class CBookshelfIndex : public QTreeWidget {
+ Q_OBJECT
+
+public:
+ CBookshelfIndex(QWidget *parent);
+ virtual ~CBookshelfIndex();
+
+ void initTree();
+ /**
+ * Opens the searchdialog using the given modules using the given search text.
+ */
+ void emitModulesChosen( QList<CSwordModuleInfo*> modules, QString key );
+
+ /** Helper method for "freezing" modules while opening them in windows. */
+ void unfreezeModules(QList<CSwordModuleInfo*>);
+
+public slots:
+
+ /**
+ * Reloads the main index's Sword dependend things like modules
+ */
+ void reloadSword(CSwordBackend::SetupChangedReason);
+
+ /**
+ * Opens the searchdialog for the selected modules.
+ */
+ void actionSearchInModules();
+
+protected:
+
+ /** Handle mouse clicks.*/
+ virtual void mouseReleaseEvent(QMouseEvent* event);
+
+ /** Empty re-implementation to prevent unwanted opening of folders with some styles.*/
+ virtual void mouseDoubleClickEvent(QMouseEvent*) {}
+
+ /**
+ * Initialize the SIGNAL<->SLOT connections
+ */
+ void initConnections();
+ /**
+ * Reimplementation. Returns the drag object for the current selection.
+ */
+ virtual QMimeData* dragObject();
+ /**
+ * Reimplementation from QTreeWidget (QAbstractItemView). Returns true if the drag is acceptable for the listview.
+ */
+ virtual void dragEnterEvent( QDragEnterEvent* event );
+ virtual void dragMoveEvent( QDragMoveEvent* event );
+ virtual void dropEvent( QDropEvent* event );
+
+ /** Receive style change event to change single/double click activation behaviour. */
+ virtual void changeEvent(QEvent*);
+
+ /**
+ * Reimplementation from QAbstractItemView. Takes care of movable items.
+ */
+ virtual void startDrag(Qt::DropActions supportedActions);
+ /**
+ * TODO: qt4 Reimplementation to support the items dragEnter and dragLeave functions.
+ */
+ virtual void contentsDragMoveEvent( QDragMoveEvent* event );
+ /**
+ * Reimplementation.
+ */
+ virtual void contentsDragLeaveEvent( QDragLeaveEvent* e );
+
+
+protected slots: // Protected slots
+ /**
+ * Called when the selection is changed.
+ */
+ void slotModifySelection();
+ /**
+ * Is called when an item was clicked or activated.
+ */
+ void slotExecuted( QTreeWidgetItem* );
+
+ /**
+ * Shows the context menu at the given position.
+ */
+ void contextMenu(const QPoint&);
+
+ /**
+ * Changes the grouping.
+ */
+ void actionChangeGrouping(QAction* action);
+
+ /**
+ * Shows information about the current module.
+ */
+
+ /**
+ * Show or hide the hidden modules, depending on the action check state.
+ */
+ void actionShowModules(bool checked);
+
+ /**
+ * Set the selected modules hidden.
+ */
+ void actionHideModules();
+
+
+ void actionAboutModule();
+ /**
+ * Unlocks the current module.
+ */
+ void actionUnlockModule();
+ void autoOpenTimeout();
+
+ /**
+ * Opens a plain text editor window to edit the modules content.
+ */
+ void actionEditModulePlain();
+ /**
+ * Opens an HTML editor window to edit the modules content.
+ */
+ void actionEditModuleHTML();
+
+ void addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem);
+
+
+private:
+ CSearchDialog* m_searchDialog;
+ //ToolTip* m_toolTip;
+ bool m_itemsMovable;
+ QTreeWidgetItem* m_autoOpenFolder;
+ QTimer m_autoOpenTimer;
+ BTModuleTreeItem::Grouping m_grouping; //temporary solution - this should be in config
+ QActionGroup* m_groupingGroup;
+ int m_mouseReleaseEventModifiers;
+ bool m_showHidden;
+ QSet<QString> m_frozenModules;
+
+ /**
+ * Initializes the view.
+ */
+ void initView();
+ void initActions();
+
+ /** Convenience function for creating a new QAction. */
+ QAction* newQAction(const QString& text, const QString& pix, int shortcut, const QObject* receiver, const char* slot, QObject* parent);
+
+ QList<QAction*> m_actionList;
+
+ QMenu* m_popup;
+
+signals:
+ /**
+ * Is emitted when a module should be opened,
+ */
+ void createReadDisplayWindow( QList<CSwordModuleInfo*>, const QString& );
+ /**
+ * Is emitted when a write window should be created.
+ */
+ void createWriteDisplayWindow( CSwordModuleInfo*, const QString&, const CDisplayWindow::WriteWindowType& );
+
+};
+
+#endif
diff --git a/src/frontend/mainindex/bookshelf/chidemodulechooserdialog.cpp b/src/frontend/mainindex/bookshelf/chidemodulechooserdialog.cpp
new file mode 100644
index 0000000..0a923c4
--- /dev/null
+++ b/src/frontend/mainindex/bookshelf/chidemodulechooserdialog.cpp
@@ -0,0 +1,70 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2007 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "chidemodulechooserdialog.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/managers/cswordbackend.h"
+#include "backend/btmoduletreeitem.h"
+
+#include "util/cpointers.h"
+#include "util/cresmgr.h"
+#include "util/ctoolclass.h"
+#include "util/directoryutil.h"
+
+#include <QDialog>
+#include <QButtonGroup>
+#include <QDialogButtonBox>
+#include <QHBoxLayout>
+#include <QSpacerItem>
+#include <QTreeWidget>
+#include <QVBoxLayout>
+#include <QStringList>
+#include <QDebug>
+#include <QHeaderView>
+
+
+CHideModuleChooserDialog::CHideModuleChooserDialog( QWidget* parent, QString title, QString label, QString currentModule)
+ : CModuleChooserDialog(parent, title, label),
+ m_currentModule(currentModule),
+ m_focusItem(0)
+{
+ QObject::connect(this, SIGNAL(modulesChanged(QList<CSwordModuleInfo*>, QTreeWidget*)), this, SLOT(applyHiddenModules(QList<CSwordModuleInfo*>)));
+ init();
+ if (m_focusItem) {
+ treeWidget()->scrollToItem(m_focusItem);
+ }
+}
+
+
+void CHideModuleChooserDialog::initModuleItem(BTModuleTreeItem* btItem, QTreeWidgetItem* widgetItem)
+{
+ widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
+ if (btItem->moduleInfo()->isHidden())
+ widgetItem->setCheckState(0, Qt::Checked);
+ else
+ widgetItem->setCheckState(0, Qt::Unchecked);
+ if (m_currentModule == widgetItem->text(0)) {
+ m_focusItem = widgetItem;
+ }
+}
+
+void CHideModuleChooserDialog::applyHiddenModules(QList<CSwordModuleInfo*> hiddenModules)
+{
+ qDebug("CHideModuleChooserDialog::applyHiddenModules");
+ QList<CSwordModuleInfo*> allModules = CPointers::backend()->moduleList();
+ foreach(CSwordModuleInfo* i, allModules) {
+ if (hiddenModules.contains(i)) {
+ i->setHidden(true);
+ } else {
+ i->setHidden(false);
+ }
+
+ }
+}
diff --git a/src/frontend/mainindex/bookshelf/chidemodulechooserdialog.h b/src/frontend/mainindex/bookshelf/chidemodulechooserdialog.h
new file mode 100644
index 0000000..9fd7e8c
--- /dev/null
+++ b/src/frontend/mainindex/bookshelf/chidemodulechooserdialog.h
@@ -0,0 +1,43 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CHIDEMODULECHOOSERDIALOG_H
+#define CHIDEMODULECHOOSERDIALOG_H
+
+class CSwordModuleInfo;
+
+#include "frontend/cmodulechooserdialog.h"
+
+class QTreeWidgetItem;
+
+class BTModuleTreeItem;
+
+
+
+class CHideModuleChooserDialog : public CModuleChooserDialog
+{
+ Q_OBJECT
+public:
+ CHideModuleChooserDialog(QWidget* parent, QString title, QString label, QString currentModule);
+ ~CHideModuleChooserDialog() {}
+
+protected:
+ virtual void initModuleItem(BTModuleTreeItem* btItem, QTreeWidgetItem* widgetItem);
+protected slots:
+ void applyHiddenModules(QList<CSwordModuleInfo*> hiddenModules);
+
+
+private:
+ QString m_currentModule;
+ QTreeWidgetItem* m_focusItem;
+};
+
+
+
+#endif
diff --git a/src/frontend/mainindex/cmainindex.cpp b/src/frontend/mainindex/cmainindex.cpp
new file mode 100644
index 0000000..04341b0
--- /dev/null
+++ b/src/frontend/mainindex/cmainindex.cpp
@@ -0,0 +1,36 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//BibleTime includes
+#include "cmainindex.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+
+#include "bookshelf/cbookshelfindex.h"
+#include "bookmarks/cbookmarkindex.h"
+
+#include <QTabWidget>
+
+
+CMainIndex::CMainIndex(QWidget *parent) : QTabWidget(parent)
+{
+ setFocusPolicy(Qt::StrongFocus);
+ m_bookmarksPage = new CBookmarkIndex(0);
+ m_bookshelfPage = new CBookshelfIndex(0);
+ addTab(m_bookshelfPage, tr("Bookshelf"));
+ addTab(m_bookmarksPage, tr("Bookmarks"));
+
+ //shortcut some signals from pages to signals of this widget so that outsiders
+ // do not have to use the pages directly
+ QObject::connect(m_bookshelfPage, SIGNAL(createReadDisplayWindow( QList<CSwordModuleInfo*>, const QString& )), this, SIGNAL(createReadDisplayWindow( QList<CSwordModuleInfo*>, const QString& )));
+ QObject::connect(m_bookmarksPage, SIGNAL(createReadDisplayWindow( QList<CSwordModuleInfo*>, const QString& )), this, SIGNAL(createReadDisplayWindow( QList<CSwordModuleInfo*>, const QString& )));
+
+ QObject::connect(m_bookshelfPage, SIGNAL(createWriteDisplayWindow( CSwordModuleInfo*, const QString&, const CDisplayWindow::WriteWindowType& )), this, SIGNAL(createWriteDisplayWindow( CSwordModuleInfo*, const QString&, const CDisplayWindow::WriteWindowType&)));
+
+}
diff --git a/src/frontend/mainindex/cmainindex.h b/src/frontend/mainindex/cmainindex.h
new file mode 100644
index 0000000..b5d217d
--- /dev/null
+++ b/src/frontend/mainindex/cmainindex.h
@@ -0,0 +1,57 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CMAININDEX_H
+#define CMAININDEX_H
+
+#include "frontend/displaywindow/cdisplaywindow.h"
+
+#include <QTabWidget>
+#include <QFocusEvent>
+
+class CBookmarkIndex;
+class CBookshelfIndex;
+class CSwordModuleInfo;
+
+/** The class which manages all bookmarks and modules. The modules are put into own, fixed subfolders sorted by language.
+ * @author The BibleTime team
+ */
+class CMainIndex : public QTabWidget {
+ Q_OBJECT
+
+public:
+ CMainIndex(QWidget *parent);
+ virtual ~CMainIndex() {};
+
+ //void reloadSword();
+
+ CBookshelfIndex* bookshelfIndex() {return m_bookshelfPage;}
+
+signals:
+ /**
+ * Is emitted when a module should be opened,
+ */
+ void createReadDisplayWindow( QList<CSwordModuleInfo*>, const QString& );
+ /**
+ * Is emitted when a write window should be created.
+ */
+ void createWriteDisplayWindow( CSwordModuleInfo*, const QString&, const CDisplayWindow::WriteWindowType& );
+
+protected:
+ /** QWidget method - move focus to the active page widget */
+ virtual void focusInEvent(QFocusEvent*) {currentWidget()->setFocus();}
+
+private:
+
+ CBookmarkIndex* m_bookmarksPage;
+ CBookshelfIndex* m_bookshelfPage;
+
+};
+
+#endif
diff --git a/src/frontend/profile/cprofile.cpp b/src/frontend/profile/cprofile.cpp
new file mode 100644
index 0000000..f6c8be1
--- /dev/null
+++ b/src/frontend/profile/cprofile.cpp
@@ -0,0 +1,433 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cprofile.h"
+#include "util/directoryutil.h"
+
+//Qt includes
+#include <QFile>
+#include <QString>
+#include <QTextStream>
+#include <QDomDocument>
+
+#define CURRENT_SYNTAX_VERSION 3
+
+namespace Profile {
+
+CProfile::CProfile( const QString& file, const QString& name )
+ : m_name(name.isEmpty() ? QObject::tr("unknown") : name),
+ m_filename(file),
+ m_fullscreen(false),
+ m_geometry(10,20,640,480),
+ m_mdiArrangementMode((CMDIArea::MDIArrangementMode)0) //0 is not a valid enum entry, means "unknown"
+{
+ if (!m_filename.isEmpty() && name.isEmpty()) {
+ loadBasics();
+ }
+ else if (m_filename.isEmpty() && !name.isEmpty()) {
+ m_filename = name;
+ m_filename.replace(QRegExp("\\s=#."),"_");
+ m_filename = util::filesystem::DirectoryUtil::getUserSessionsDir().absolutePath() + "/" + m_filename + ".xml";
+ init(m_filename);
+ }
+ else {
+ qWarning("CProfile: empty file name!");
+ }
+}
+
+CProfile::~CProfile() {
+ qDeleteAll(m_profileWindows); //there's no autodelete feature in qt4
+ m_profileWindows.clear(); //delete all CProfileWindows objects
+}
+
+/** Loads the profile from the file given in the constructor. */
+QList<CProfileWindow*> CProfile::load() {
+ QFile file(m_filename);
+ if (!file.exists())
+ {
+ //qWarning() << "Standard profile not found at filename " << m_filename;
+ return QList<CProfileWindow*>();
+ }
+
+ QDomDocument doc;
+ if (file.open(QIODevice::ReadOnly)) {
+ QTextStream t( &file );
+ t.setCodec("UTF-8");
+ doc.setContent(t.readAll());
+ file.close();
+ }
+
+ QDomElement document = doc.documentElement();
+ if( document.tagName() != "BibleTimeProfile" && document.tagName() != "BibleTime" ) { //BibleTime was used in syntax version 1.0
+ qWarning("CProfile::load: Missing BibleTime doc");
+ return m_profileWindows;
+ }
+ if (document.hasAttribute("name")) {
+ m_name = document.attribute("name");
+ }
+
+ //load settings of the main window
+ {
+ // see if there's a section with the name MAINWINDOW
+ QDomElement elem = document.firstChild().toElement();
+ QDomElement mainWindow;
+ while (!elem.isNull()) {
+ if (elem.tagName() == "MAINWINDOW") {
+ mainWindow = elem;
+ break; //found the element
+ }
+ elem = elem.nextSibling().toElement();
+ }
+ if (!mainWindow.isNull()) { //was found
+ setFullscreen( (bool)mainWindow.attribute("fullscreen").toInt());
+
+ QByteArray bstate;
+ bstate += mainWindow.attribute("state");
+ setMainwindowState(QByteArray::fromHex(bstate));
+
+ QDomElement geometry_element = mainWindow.namedItem("GEOMETRY").toElement();
+ QRect rect;
+ if(!geometry_element.isNull()) {
+ if (geometry_element.hasAttribute("x")) {
+ rect.setX(geometry_element.attribute("x").toInt());
+ }
+ if (geometry_element.hasAttribute("y")) {
+ rect.setY(geometry_element.attribute("y").toInt());
+ }
+ if (geometry_element.hasAttribute("width")) {
+ rect.setWidth(geometry_element.attribute("width").toInt());
+ }
+ if (geometry_element.hasAttribute("height")) {
+ rect.setHeight(geometry_element.attribute("height").toInt());
+ }
+ if (geometry_element.hasAttribute("isMaximized")) {
+ this->setMaximized( static_cast<bool>(geometry_element.attribute("isMaximized").toInt()) );
+ }
+ setGeometry(rect);
+ }
+
+ QDomElement mdi_element = mainWindow.namedItem("MDI").toElement();
+ if(!mdi_element.isNull()) {
+ if (mdi_element.hasAttribute("ArrangementMode")) {
+ this->setMDIArrangementMode((CMDIArea::MDIArrangementMode)mdi_element.attribute("ArrangementMode").toInt());
+ }
+ }
+ }
+ }
+
+ m_profileWindows.clear();
+ QDomElement elem = document.firstChild().toElement();
+ while (!elem.isNull()) {
+ CProfileWindow* p = 0;
+ if (elem.tagName() == "BIBLE") {
+ p = new CProfileWindow(CSwordModuleInfo::Bible);
+ }
+ else if (elem.tagName() == "COMMENTARY") {
+ p = new CProfileWindow(CSwordModuleInfo::Commentary);
+ }
+ else if (elem.tagName() == "LEXICON") {
+ p = new CProfileWindow(CSwordModuleInfo::Lexicon);
+ }
+ else if (elem.tagName() == "BOOK") {
+ p = new CProfileWindow(CSwordModuleInfo::GenericBook);
+ }
+
+ if (p) {
+ m_profileWindows.append(p);
+
+ if (elem.hasAttribute("windowSettings")) {
+ p->setWindowSettings( elem.attribute("windowSettings").toInt() );
+ }
+ if (elem.hasAttribute("writeWindowType")) {
+ p->setWriteWindowType( elem.attribute("writeWindowType").toInt() );
+ }
+ if (elem.hasAttribute("hasFocus")) {
+ p->setFocus( static_cast<bool>(elem.attribute("hasFocus").toInt()) );
+ }
+
+ QRect rect;
+
+ QDomElement object = elem.namedItem("GEOMETRY").toElement();
+ if(!object.isNull()) {
+ if (object.hasAttribute("x")) {
+ rect.setX(object.attribute("x").toInt());
+ }
+ if (object.hasAttribute("y")) {
+ rect.setY(object.attribute("y").toInt());
+ }
+ if (object.hasAttribute("width")) {
+ rect.setWidth(object.attribute("width").toInt());
+ }
+ if (object.hasAttribute("height")) {
+ rect.setHeight(object.attribute("height").toInt());
+ }
+ if (object.hasAttribute("isMaximized")) {
+ p->setMaximized( static_cast<bool>(object.attribute("isMaximized").toInt()) );
+ }
+ }
+ p->setGeometry(rect);
+
+ object = elem.namedItem("MODULES").toElement();
+ if(!object.isNull()) {
+ if (object.hasAttribute("list")) {
+ const QString sep = object.hasAttribute("separator") ? object.attribute("separator") : "|";
+ QStringList modules = object.attribute("list").split(sep);
+ p->setModules(modules);
+ }
+ }
+
+ object = elem.namedItem("KEY").toElement();
+ if(!object.isNull()) {
+ if (object.hasAttribute("name"))
+ p->setKey(object.attribute("name"));
+ }
+
+ object = elem.namedItem("SCROLLBARS").toElement();
+ if(!object.isNull()) {
+ int horizontal = 0, vertical = 0;
+ if (object.hasAttribute("horizontal"))
+ horizontal = object.attribute("horizontal").toInt();
+ if (object.hasAttribute("vertical"))
+ vertical = object.attribute("vertical").toInt();
+
+ p->setScrollbarPositions(horizontal, vertical);
+ }
+ }
+ elem = elem.nextSibling().toElement();
+ }
+ return m_profileWindows;
+}
+
+/** Saves the profile to the file given in the constructor. */
+bool CProfile::save(QList<CProfileWindow*> windows) {
+ /** Save the settings using a XML file
+ * Save the CProfileWindow objects using a XML file which name is in m_filename
+ */
+ bool ret = false;
+ QDomDocument doc("DOC");
+ doc.appendChild( doc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
+
+ QDomElement content = doc.createElement("BibleTimeProfile");
+ content.setAttribute("syntaxVersion", CURRENT_SYNTAX_VERSION);
+ content.setAttribute("name", m_name);
+ doc.appendChild(content);
+
+ //save mainwindow settings
+ {
+ QDomElement mainWindow = doc.createElement("MAINWINDOW");
+ mainWindow.setAttribute("fullscreen", fullscreen());
+
+ QString sstate = QString(getMainwindowState().toHex());
+ mainWindow.setAttribute("state", sstate);
+
+ QDomElement geometry = doc.createElement("GEOMETRY");
+ mainWindow.appendChild(geometry);
+ const QRect r = this->geometry();
+ geometry.setAttribute("x",r.x());
+ geometry.setAttribute("y",r.y());
+ geometry.setAttribute("width",r.width());
+ geometry.setAttribute("height",r.height());
+ geometry.setAttribute("isMaximized",static_cast<int>(this->maximized()));
+
+ QDomElement mdi = doc.createElement("MDI");
+ mainWindow.appendChild(mdi);
+ mdi.setAttribute("ArrangementMode",static_cast<int>(this->getMDIArrangementMode()));
+
+ content.appendChild(mainWindow);
+ }
+
+ //for (CProfileWindow* p = windows.first(); p; p = windows.next()) {
+ foreach(CProfileWindow* p, windows) {
+ QDomElement window;
+ switch (p->type()) {
+ case CSwordModuleInfo::Bible:
+ window = doc.createElement("BIBLE");
+ break;
+ case CSwordModuleInfo::Commentary:
+ window = doc.createElement("COMMENTARY");
+ break;
+ case CSwordModuleInfo::Lexicon:
+ window = doc.createElement("LEXICON");
+ break;
+ case CSwordModuleInfo::GenericBook:
+ window = doc.createElement("BOOK");
+ break;
+ default:
+ break;
+ }
+ if (window.isNull())
+ break;
+ window.setAttribute("windowSettings", p->windowSettings());
+ window.setAttribute("writeWindowType", p->writeWindowType());
+ window.setAttribute("hasFocus", p->hasFocus());
+
+ //save geomtery
+ const QRect r = p->geometry();
+ QDomElement geometry = doc.createElement("GEOMETRY");
+ geometry.setAttribute("x",r.x());
+ geometry.setAttribute("y",r.y());
+ geometry.setAttribute("width",r.width());
+ geometry.setAttribute("height",r.height());
+ geometry.setAttribute("isMaximized",static_cast<int>(p->maximized()));
+ window.appendChild( geometry );
+
+ QDomElement modules = doc.createElement("MODULES");
+ modules.setAttribute("separator", "|");
+ modules.setAttribute("list", p->modules().join("|"));
+ window.appendChild( modules );
+
+ QDomElement key = doc.createElement("KEY");
+ key.setAttribute("name", p->key());
+ window.appendChild( key );
+
+ QDomElement scrollbars = doc.createElement("SCROLLBARS");
+ scrollbars.setAttribute("horizontal", p->scrollbarPositions().horizontal);
+ scrollbars.setAttribute("vertical", p->scrollbarPositions().vertical);
+ window.appendChild( scrollbars );
+
+ content.appendChild( window );
+ }
+
+ QFile file(m_filename);
+ if ( file.open(QIODevice::WriteOnly) ) {
+ ret = true;
+ QTextStream t( &file );
+ t.setCodec("UTF-8");
+ t << doc.toString();
+ file.close();
+ }
+ else
+ ret = false;
+
+ return ret;
+}
+
+/** Saves the profile to the file given in the constructor. */
+bool CProfile::save() {
+ return save(m_profileWindows);
+}
+
+/** Returns the filename used for this profile. */
+const QString& CProfile::filename() {
+ return m_filename;
+}
+
+/** Returns the name of this profile. */
+const QString& CProfile::name() {
+ return m_name;
+}
+
+/** Initializes the XML for the first time (use to create a new profile) */
+void CProfile::init(const QString file) {
+ const QString oldFile = m_filename;
+ m_filename = file;
+ save(QList<CProfileWindow*>());
+ m_filename = oldFile;
+}
+
+/** Changes the name of this profile. */
+void CProfile::setName( const QString& newName ) {
+ m_name = newName;
+ saveBasics(); //save chanegd name
+}
+
+/** Loads the basic settings requires for proper operation. */
+void CProfile::loadBasics() {
+ QFile file(m_filename);
+ if (!file.exists())
+ return;
+
+ QDomDocument doc;
+ if (file.open(QIODevice::ReadOnly)) {
+ QTextStream t( &file );
+ t.setCodec("UTF-8");
+ doc.setContent(t.readAll());
+ file.close();
+ }
+ QDomElement document = doc.documentElement();
+ if (document.hasAttribute("name"))
+ m_name = document.attribute("name");
+}
+
+void CProfile::saveBasics() {
+ QFile file(m_filename);
+ if (!file.exists())
+ return;
+
+ QDomDocument doc;
+ if (file.open(QIODevice::ReadOnly)) {
+ QTextStream t(&file);
+ t.setCodec("UTF-8");
+ doc.setContent(t.readAll());
+ file.close();
+ }
+
+ QDomElement document = doc.documentElement();
+ document.setAttribute("name", m_name);
+
+ if (file.open(QIODevice::WriteOnly)) {
+ QTextStream t( &file );
+ t.setCodec("UTF-8");
+ t << doc.toString();
+ file.close();
+ }
+}
+
+/** Returns true if the main window was in fullscreen mode as the profile was saved. */
+bool CProfile::fullscreen() const {
+ return m_fullscreen;
+}
+
+/** Set the parameter to true if the main window coveres the full screen size. */
+void CProfile::setFullscreen( const bool fullscreen ) {
+ m_fullscreen = fullscreen;
+}
+
+/** Returns true if the main window was maximized as the profile was saved. */
+bool CProfile::maximized() const {
+ return m_maximized;
+}
+
+/** Set the parameter to true if the main window is maximized. */
+void CProfile::setMaximized( const bool maximized ) {
+ m_maximized = maximized;
+}
+
+/** Returns the geometry of the main window */
+const QRect CProfile::geometry() {
+ return m_geometry;
+}
+
+/** Stes the geoemtry of the main window */
+void CProfile::setGeometry( const QRect rect ) {
+ m_geometry = rect;
+}
+
+void CProfile::setMDIArrangementMode(const CMDIArea::MDIArrangementMode newArrangementMode)
+{
+ m_mdiArrangementMode = newArrangementMode;
+}
+
+CMDIArea::MDIArrangementMode CProfile::getMDIArrangementMode(void)
+{
+ return m_mdiArrangementMode;
+}
+
+void CProfile::setMainwindowState(const QByteArray& state)
+{
+ m_mainwindowState = state;
+}
+
+QByteArray CProfile::getMainwindowState()
+{
+ return m_mainwindowState;
+}
+
+
+} //end of namespace Profile
diff --git a/src/frontend/profile/cprofile.h b/src/frontend/profile/cprofile.h
new file mode 100644
index 0000000..6e375f9
--- /dev/null
+++ b/src/frontend/profile/cprofile.h
@@ -0,0 +1,120 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CPROFILE_H
+#define CPROFILE_H
+
+#include "cprofilewindow.h"
+#include "frontend/cmdiarea.h"
+
+//Qt includes
+#include <QList>
+#include <QByteArray>
+
+namespace Profile {
+
+/** Manages one profile file. Provides functions to save and restore settings of the available display windows.
+ * @author The BibleTime team
+ */
+class CProfile {
+public:
+ CProfile(const QString& fileName, const QString& name = QString::null);
+ ~CProfile();
+
+ /**
+ * Saves the profile to the file given in the constructor.
+ * @param windows The list of windows available in the profile.
+ */
+ bool save( QList<CProfileWindow*> windows );
+ /**
+ * Saves the profile to the file given in the constructor.
+ */
+ bool save();
+ /**
+ * Loads the profile from the file given in the constructor.
+ * @return The list of profiled window which exist in the profile.
+ */
+ QList<CProfileWindow*> load();
+ /**
+ * Returns the name of this profile.
+ */
+ const QString& name();
+ /**
+ * Returns the filename used for this profile.
+ */
+ const QString& filename();
+ /**
+ * Initializes the XML for the first time (use to create a new profile)
+ */
+ void init(const QString);
+ /**
+ * Chnages the name of this profile.
+ */
+ void setName( const QString& );
+ /**
+ * Returns true if the main window was in fullscreen mode as the profile was saved.
+ */
+ bool fullscreen() const;
+ /**
+ * Set the parameter to true if the main window coveres the full screen size.
+ */
+ void setFullscreen( const bool fullscreen );
+ /**
+ * Returns true if the main window was maximized as the profile was saved.
+ */
+ bool maximized() const;
+ /**
+ * Set the parameter to true if the main window is maximized.
+ */
+ void setMaximized( const bool maximized );
+ /**
+ * Sets the geoemtry of the main window
+ */
+ void setGeometry( const QRect rect );
+ /**
+ * Returns the geometry of the main window
+ */
+ const QRect geometry();
+ /**
+ * Sets the MDI arrangement mode
+ */
+ void setMDIArrangementMode(const CMDIArea::MDIArrangementMode);
+ /**
+ * Returns mdi arrangement mode
+ */
+ CMDIArea::MDIArrangementMode getMDIArrangementMode(void);
+ /**
+ * set mainwindow saveState - position of docking windows and toolbar
+ */
+ void setMainwindowState(const QByteArray& state);
+ /**
+ * Return mainwindow saveState - position of docking windows and toolbar
+ */
+ QByteArray getMainwindowState();
+
+private:
+ /**
+ * Loads the basic settings requires for proper operation.
+ */
+ void loadBasics();
+ void saveBasics();
+
+ QList<CProfileWindow*> m_profileWindows;
+ QString m_name;
+ QString m_filename;
+ bool m_fullscreen;
+ bool m_maximized;
+ QRect m_geometry;
+ CMDIArea::MDIArrangementMode m_mdiArrangementMode;
+ QByteArray m_mainwindowState;
+};
+
+} //end of namespace Profile
+
+#endif
diff --git a/src/frontend/profile/cprofilemgr.cpp b/src/frontend/profile/cprofilemgr.cpp
new file mode 100644
index 0000000..783e371
--- /dev/null
+++ b/src/frontend/profile/cprofilemgr.cpp
@@ -0,0 +1,130 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#include "cprofilemgr.h"
+#include "util/directoryutil.h"
+
+//Qt includes
+#include <QDir>
+#include <QFile>
+#include <QList>
+
+
+namespace Profile {
+
+CProfileMgr::CProfileMgr() : m_startupProfile(0) {
+ //m_profiles.setAutoDelete(true);
+
+ m_profilePath = util::filesystem::DirectoryUtil::getUserSessionsDir().absolutePath() + "/";
+
+ QDir d( m_profilePath );
+ QStringList files = d.entryList(QStringList("*.xml"));
+ for ( QStringList::Iterator it = files.begin(); it != files.end(); ++it ) {
+ if ((*it) != "_startup_.xml") {
+ m_profiles.append(new CProfile(m_profilePath + *it));
+ }
+ else {
+ m_startupProfile = new CProfile(m_profilePath + *it);
+ }
+ }
+}
+
+CProfileMgr::~CProfileMgr() {
+ qDeleteAll(m_profiles);
+ m_profiles.clear();
+ delete m_startupProfile;
+}
+
+/** Returns a list of available profiles. */
+const QList<CProfile*>& CProfileMgr::profiles() {
+ return m_profiles;
+}
+
+/** Creates a new profile with the name "name" (first parameter). @return The profile object */
+CProfile* CProfileMgr::create( const QString name ) {
+ CProfile* p = new CProfile(QString::null, name);
+ m_profiles.append(p);
+
+ return p;
+}
+
+/** Removes the profile from the list and from the directory containg the profile files. */
+bool CProfileMgr::remove( CProfile* p )
+{
+ bool ret = false;
+ QFile f( p->filename() );
+ if (f.exists())
+ f.remove();
+
+ int i = m_profiles.indexOf(p);
+ if (i != -1)
+ delete m_profiles.takeAt(i);
+
+ ret = true;
+ return ret;
+}
+
+bool CProfileMgr::remove( const QString& profile)
+{
+ bool ret = false;
+ QListIterator<CProfile*> it(m_profiles);
+ while (it.hasNext()) {
+ CProfile* p = it.next();
+ if (p->name() == profile) {
+ remove(p);
+ ret = true;
+ }
+ }
+ return ret;
+}
+
+/** Returns the profile with the desired name. If there's no such profile 0 is returned. */
+CProfile* CProfileMgr::profile(const QString& name) {
+ QListIterator<CProfile*> it(m_profiles);
+ while (it.hasNext()) {
+ CProfile* p = it.next();
+ if (p && p->name() == name) {
+ return p;
+ }
+ }
+
+ return 0;
+}
+
+/** Returns the startup profile if it exists, otherwise return 0. */
+CProfile* CProfileMgr::startupProfile() {
+ if (!m_startupProfile) {
+ m_startupProfile = new CProfile(QString::null, "_startup_");
+ }
+
+ return m_startupProfile;
+}
+
+/** Refreshes the profiles available on disk. Use this function to update the list of profiles after another instance of CProfileMgr created a new profile. */
+void CProfileMgr::refresh() {
+ qDeleteAll(m_profiles);
+ m_profiles.clear(); //delete all profiles
+ QDir d( m_profilePath );
+ QStringList files = d.entryList(QStringList("*.xml"));
+ for ( QStringList::Iterator it = files.begin(); it != files.end(); ++it ) {
+ CProfile p(m_profilePath + *it);
+ if (p.name() == "_startup_") { //new startup profile
+ if (!m_startupProfile) { //don't put this in the if clause above,it doesn't work!
+ m_startupProfile = new CProfile(m_profilePath + *it);
+ }
+ }
+ else if (!profile(p.name())) { //don't have it already
+ m_profiles.append(new CProfile(m_profilePath + *it));
+ }
+ }
+}
+
+} //end of namespace Profile
diff --git a/src/frontend/profile/cprofilemgr.h b/src/frontend/profile/cprofilemgr.h
new file mode 100644
index 0000000..934d09a
--- /dev/null
+++ b/src/frontend/profile/cprofilemgr.h
@@ -0,0 +1,68 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CPROFILEMGR_H
+#define CPROFILEMGR_H
+
+#include "cprofile.h"
+
+//Qt includes
+#include <QString>
+#include <QList>
+
+namespace Profile {
+/** The manager for profiles.
+ * Provides functions to create, delete, save and load profiles.
+ * @author The BibleTime team
+ */
+class CProfileMgr {
+public:
+ CProfileMgr();
+ ~CProfileMgr();
+
+ /** Creates a new profile with the name "name" (first parameter).
+ * @return The profile object
+ */
+ CProfile* create( const QString name );
+ /**
+ * @return a list of available profiles
+ */
+ const QList<CProfile*>& profiles();
+ /**
+ * Removes the profile from the list and from the directory containg the profile files.
+ */
+ bool remove( CProfile* p );
+ /**
+ * Removes the profile from the list and from the directory containg the profile files.
+ */
+ bool remove( const QString& );
+ /**
+ * Returns the profile with the desired name. If there's no such profile 0 is returned.
+ */
+ CProfile* profile(const QString&);
+ /**
+ * Returns the startup profile if it exists, otherwise return 0.
+ */
+ CProfile* startupProfile();
+ /**
+ * Refreshes the profiles available on disk. Use this function to update the list of profiles after another instance of CProfileMgr created a new profile.
+ */
+ void refresh();
+
+protected:
+ QList<CProfile*> m_profiles;
+ QString m_profilePath;
+ CProfile* m_startupProfile;
+};
+
+} //end of namespace Profile
+
+#endif
diff --git a/src/frontend/profile/cprofilewindow.cpp b/src/frontend/profile/cprofilewindow.cpp
new file mode 100644
index 0000000..f405923
--- /dev/null
+++ b/src/frontend/profile/cprofilewindow.cpp
@@ -0,0 +1,134 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#include "cprofilewindow.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/managers/cswordbackend.h"
+
+
+#include <QString>
+#include <QRect>
+#include <QStringList>
+
+
+namespace Profile {
+
+CProfileWindow::CProfileWindow(CSwordModuleInfo::ModuleType type)
+: m_type(type),
+m_windowGeometry(),
+m_moduleList(),
+m_key(QString::null),
+m_maximized(false),
+m_hasFocus(false),
+m_windowSettings(0),
+m_writeWindowType(0) {
+ m_scrollbarPos.horizontal = 0;
+ m_scrollbarPos.vertical = 0;
+}
+
+CProfileWindow::~CProfileWindow() {}
+
+/** Returns the size of the window including the x,y coordinates. */
+const QRect& CProfileWindow::geometry() const {
+ return m_windowGeometry;
+}
+
+/** Sets the size of the window. */
+void CProfileWindow::setGeometry( const QRect& rect ) {
+ m_windowGeometry = rect;
+}
+
+/** Returns the type of the managed window (bible window, commentary window or lexicon window). */
+CSwordModuleInfo::ModuleType CProfileWindow::type() const {
+ if (m_type != CSwordModuleInfo::Unknown)
+ return m_type;
+ return CSwordModuleInfo::Unknown;
+}
+
+/** Sets the modules. */
+void CProfileWindow::setModules( const QStringList& modules ) {
+ m_moduleList = modules; //copy module pointers into our own list
+}
+
+/** Returns a list of module names which are chosen in the managed window profile. */
+const QStringList& CProfileWindow::modules() const {
+ return m_moduleList;
+}
+
+/** Returns the current key set in the modules. */
+const QString& CProfileWindow::key() const {
+ return m_key;
+}
+
+/** Set the key used in the modules. */
+void CProfileWindow::setKey( const QString& key ) {
+ m_key = key;
+}
+
+/** Sets the current position of the scrollbars. */
+void CProfileWindow::setScrollbarPositions(const int& horizontal, const int& vertical) {
+ // m_scrollbarPos = {x,y};
+ m_scrollbarPos.horizontal = horizontal;
+ m_scrollbarPos.vertical = vertical;
+}
+
+/** Returns tghe position of the scrollbars */
+const CProfileWindow::ScrollbarPos& CProfileWindow::scrollbarPositions() const {
+ return m_scrollbarPos;
+}
+
+/** Sets the type of the used modules. */
+void CProfileWindow::setType(const CSwordModuleInfo::ModuleType& type) {
+ m_type = type;
+}
+
+/** Returns true if the window is maximized. */
+const bool& CProfileWindow::maximized() const {
+ return m_maximized;
+}
+
+/** Sets the windows maximized state to true or false. */
+void CProfileWindow::setMaximized( const bool& maximized ) {
+ m_maximized = maximized;
+}
+
+/** Returns true if the window is maximized. */
+const bool& CProfileWindow::hasFocus() const {
+ return m_hasFocus;
+}
+
+/** Sets the windows maximized state to true or false. */
+void CProfileWindow::setFocus( const bool& hasFocus ) {
+ m_hasFocus = hasFocus;
+}
+
+/** Returns an integer with the window specific settings */
+const int& CProfileWindow::windowSettings() const {
+ return m_windowSettings;
+}
+
+/** Sets the window specific settings. */
+void CProfileWindow::setWindowSettings( const int& settings ) {
+ m_windowSettings = settings;
+}
+
+/** Tells this profile window to represent a write window. */
+void CProfileWindow::setWriteWindowType( const int& writeWindowType ) {
+ m_writeWindowType = writeWindowType;
+}
+
+/** Returns whether this profile window represents a write window. */
+const int& CProfileWindow::writeWindowType() const {
+ return m_writeWindowType;
+}
+
+} //end of namespace Profile
diff --git a/src/frontend/profile/cprofilewindow.h b/src/frontend/profile/cprofilewindow.h
new file mode 100644
index 0000000..090d991
--- /dev/null
+++ b/src/frontend/profile/cprofilewindow.h
@@ -0,0 +1,126 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CPROFILEWINDOW_H
+#define CPROFILEWINDOW_H
+
+class CSwordModuleInfo;
+#include "backend/managers/cswordbackend.h"
+
+//Qt includes
+#include <QString>
+#include <QRect>
+#include <QStringList>
+//#include <QList>
+
+namespace Profile {
+
+/** Contains the settings for one window saved in the profile.
+ * @author The BibleTime team
+ */
+class CProfileWindow {
+public:
+ struct ScrollbarPos {
+ int horizontal; //the position of the horizontal scrollbar
+ int vertical; //the position of the vertical scrollbar
+ };
+
+ CProfileWindow(CSwordModuleInfo::ModuleType type = CSwordModuleInfo::Unknown);
+ ~CProfileWindow();
+ /**
+ * Sets the modules.
+ */
+ void setModules( const QStringList& modules );
+ /**
+ * Returns the type of the managed window (bible window, commentary window or lexicon window).
+ */
+ CSwordModuleInfo::ModuleType type() const;
+ /**
+ * Sets the type of the used modules.
+ */
+ void setType(const CSwordModuleInfo::ModuleType& type);
+ /**
+ * Sets the size of the window.
+ */
+ void setGeometry( const QRect& s );
+ /**
+ * Returns the size of the window including the x,y coordinates.
+ */
+ const QRect& geometry() const;
+ /**
+ * Returns a list of module names which are chosen in the managed window profile.
+ */
+ const QStringList& modules() const;
+ /**
+ * Set the key used in the modules.
+ */
+ void setKey( const QString& );
+ /**
+ * Returns the current key set in the modules.
+ */
+ const QString& key() const;
+ /**
+ * Sets the current position of the scrollbars.
+ */
+ void setScrollbarPositions(const int& x, const int& y);
+ /**
+ * Sets the windows maximized state to true or false.
+ */
+ void setMaximized( const bool& maximized );
+ /**
+ * Sets the windows hasFocus state to true or false.
+ */
+ void setFocus( const bool& hasFocus );
+ /**
+ * Sets the window specific settings.
+ */
+ void setWindowSettings( const int& settings );
+ /**
+ * Returns an integer with the window specific settings
+ */
+ const int& windowSettings() const;
+ /**
+ * Returns true if the window is maximized.
+ */
+ const bool& maximized() const;
+ /**
+ * Returns true if the window has the focus in the MDI area.
+ */
+ const bool& hasFocus() const;
+ /**
+ * Returns tghe position of the scrollbars
+ */
+ const CProfileWindow::ScrollbarPos& scrollbarPositions() const;
+ /**
+ * Returns whether this profile window represents a write window.
+ */
+ const int& writeWindowType() const;
+ /**
+ * Tells this profile window to represent a write window.
+ */
+ void setWriteWindowType( const int& writeWindowType );
+
+private:
+ CSwordModuleInfo::ModuleType m_type;
+ QRect m_windowGeometry;
+ QStringList m_moduleList;
+ QString m_key;
+ ScrollbarPos m_scrollbarPos;
+ bool m_maximized;
+ bool m_hasFocus;
+ int m_windowSettings;
+ int m_writeWindowType;
+};
+
+} //end of namespace Profile
+
+#endif
+
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp b/src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp
new file mode 100644
index 0000000..d37cb1d
--- /dev/null
+++ b/src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp
@@ -0,0 +1,84 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "csearchanalysisdialog.h"
+#include "csearchanalysisscene.h"
+#include "csearchanalysisview.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "util/dialogutil.h"
+
+#include <QDialog>
+#include <QAbstractButton>
+#include <QDialogButtonBox>
+#include <QVBoxLayout>
+#include <QApplication>
+#include <QDesktopWidget>
+
+namespace Search {
+
+static const int DIALOG_HEIGHT=400;
+static const int DIALOG_BORDER=30;
+
+CSearchAnalysisDialog::CSearchAnalysisDialog( QList<CSwordModuleInfo*> modules, QWidget* parentDialog )
+ : QDialog(parentDialog)
+{
+ initView();
+ m_analysis->reset();
+ m_analysis->analyse(modules);
+
+ // Set initial width based on the search data, but limit to the
+ // width of the desktop
+ int width = m_analysis->width()+DIALOG_BORDER;
+ int desktopWidth = QApplication::desktop()->screenGeometry(this).width();
+ if (width > desktopWidth)
+ width = desktopWidth;
+ resize(width, DIALOG_HEIGHT);
+
+}
+
+/** Initializes this dialog. */
+void CSearchAnalysisDialog::initView()
+{
+
+ QVBoxLayout *vboxLayout = new QVBoxLayout(this);
+
+ m_analysis = new CSearchAnalysisScene(this);
+ m_analysisView = new CSearchAnalysisView(m_analysis, this);
+//// m_analysisView->show();
+ vboxLayout->addWidget(m_analysisView);
+
+ m_buttonBox = new QDialogButtonBox(this);
+ m_buttonBox->setOrientation(Qt::Horizontal);
+ m_buttonBox->setStandardButtons(QDialogButtonBox::Close);
+ m_buttonBox->addButton(QDialogButtonBox::Save);
+ //tr("Save as HTML"),
+ util::prepareDialogBox(m_buttonBox);
+ vboxLayout->addWidget(m_buttonBox);
+
+ bool ok = QObject::connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+ Q_ASSERT(ok);
+ ok = QObject::connect(m_buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
+ Q_ASSERT(ok);
+}
+
+void CSearchAnalysisDialog::buttonClicked(QAbstractButton* button)
+{
+ if (m_buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
+ m_analysis->saveAsHTML();
+ }
+}
+
+void CSearchAnalysisDialog::resizeEvent(QResizeEvent* event)
+{
+ QDialog::resizeEvent(event);
+ m_analysis->resizeHeight(height());
+}
+
+}
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisdialog.h b/src/frontend/searchdialog/analysis/csearchanalysisdialog.h
new file mode 100644
index 0000000..c24c554
--- /dev/null
+++ b/src/frontend/searchdialog/analysis/csearchanalysisdialog.h
@@ -0,0 +1,58 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef SEARCHCSEARCHANALYSISDIALOG_H
+#define SEARCHCSEARCHANALYSISDIALOG_H
+
+
+class CSwordModuleInfo;
+
+#include <QDialog>
+#include <QObject>
+
+class QAbstractButton;
+class QDialogButtonBox;
+
+namespace Search {
+
+class CSearchAnalysisView;
+class CSearchAnalysisScene;
+
+
+
+/**
+ @author The BibleTime team <info@bibletime.info>
+*/
+class CSearchAnalysisDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ CSearchAnalysisDialog(QList<CSwordModuleInfo*> modules, QWidget* parentDialog);
+ ~CSearchAnalysisDialog() {}
+
+protected: // Protected methods
+ /**
+ * Initializes this dialog.
+ */
+ void initView();
+ void resizeEvent(QResizeEvent* event);
+
+private slots:
+ void buttonClicked(QAbstractButton* button);
+
+private:
+ CSearchAnalysisScene* m_analysis;
+ CSearchAnalysisView* m_analysisView;
+ QDialogButtonBox* m_buttonBox;
+};
+
+}
+
+#endif
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisitem.cpp b/src/frontend/searchdialog/analysis/csearchanalysisitem.cpp
new file mode 100644
index 0000000..713a98b
--- /dev/null
+++ b/src/frontend/searchdialog/analysis/csearchanalysisitem.cpp
@@ -0,0 +1,169 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "csearchanalysisitem.h"
+#include "csearchanalysisscene.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+
+#include <QGraphicsRectItem>
+#include <QPainter>
+#include <QFont>
+#include <QPen>
+#include <QPoint>
+#include <QRect>
+
+
+namespace Search {
+
+const int SPACE_BETWEEN_PARTS = 5;
+const int RIGHT_BORDER = 15;
+const int LEFT_BORDER = 15;
+const int LOWER_BORDER = 10;
+const int UPPER_BORDER = 10;
+
+const int ITEM_TEXT_SIZE = 8;
+const int LABEL_TEXT_SIZE = 6;
+
+//used for the shift between the bars
+const int BAR_DELTAX = 4;
+const int BAR_DELTAY = 2;
+const int BAR_WIDTH = 2 + (2*BAR_DELTAX); //should be equal or bigger than the label font size
+// Used for the text below the bars
+const int BAR_LOWER_BORDER = 100;
+
+const int LEGEND_INNER_BORDER = 5;
+const int LEGEND_DELTAY = 4;
+const int LEGEND_WIDTH = 85;
+
+CSearchAnalysisItem::CSearchAnalysisItem(const int moduleCount, const QString &bookname, double *scaleFactor, QList<CSwordModuleInfo*>* modules)
+ : QGraphicsRectItem(),
+ m_moduleList( modules ),
+ m_scaleFactor(scaleFactor),
+ m_bookName(bookname),
+ m_moduleCount(moduleCount),
+ m_bufferPixmap(0)
+{
+ m_resultCountArray.resize(m_moduleCount);
+ int index = 0;
+ for (index = 0; index < m_moduleCount; ++index) m_resultCountArray[index] = 0;
+}
+
+CSearchAnalysisItem::~CSearchAnalysisItem()
+{
+ delete m_bufferPixmap;
+}
+
+/** Sets the resultcount of this item for the given module */
+void CSearchAnalysisItem::setCountForModule( const int moduleIndex, const int count) {
+ m_resultCountArray[moduleIndex] = count;
+}
+
+/** Returns the resultcount of this item for the given module */
+int CSearchAnalysisItem::getCountForModule( const int moduleIndex) {
+ return m_resultCountArray[moduleIndex];
+}
+
+
+bool CSearchAnalysisItem::hasHitsInAnyModule() {
+ foreach (const int hits, m_resultCountArray){
+ if (hits) return true;
+ }
+ return false;
+}
+
+/** Reimplementation. Draws the content of this item. */
+void CSearchAnalysisItem::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) {
+ QFont f = painter->font();
+ f.setPointSize(ITEM_TEXT_SIZE);
+ painter->setFont(f);
+
+ /**
+ * We have to paint so many bars as we have modules available (we use m_moduleCount)
+ * We paint inside the area which is given by height and width of this rectangle item
+ */
+ int index = 0;
+ int drawn = 0;
+ int Value = 0;
+
+ //find out the biggest value
+ for (index=0;index < m_moduleCount; index++) {
+ if (m_resultCountArray[index] > Value) {
+ Value = m_resultCountArray[index];
+ }
+ };
+
+ while (drawn < m_moduleCount) {
+ for (index = 0; index < m_moduleCount; index++) {
+ if (m_resultCountArray[index] == Value) {
+ QPoint p1((int)rect().x() + (m_moduleCount-drawn-1)*BAR_DELTAX,
+ (int)rect().height() + (int)y() - BAR_LOWER_BORDER - (m_moduleCount-drawn)*BAR_DELTAY);
+ QPoint p2(p1.x() + BAR_WIDTH,
+ p1.y() - (int)( !m_resultCountArray[index] ? 0 : ((m_resultCountArray[index])*(*m_scaleFactor))) );
+ QRect r(p1, p2);
+ painter->fillRect(r, QBrush(CSearchAnalysisScene::getColor(index)) );
+ painter->drawRect(r);
+ drawn++;
+ }
+ }
+ //finds the next smaller value
+ int newValue = 0;
+ for (index=0;index < m_moduleCount; index++)
+ if (m_resultCountArray[index] < Value && m_resultCountArray[index] >= newValue)
+ newValue = m_resultCountArray[index];
+ Value = newValue;
+ }
+ if (!m_bufferPixmap) {
+ m_bufferPixmap = new QPixmap(width(),BAR_LOWER_BORDER);
+ //m_bufferPixmap->resize(width(),BAR_LOWER_BORDER);
+ m_bufferPixmap->fill();
+ QPainter p(m_bufferPixmap);
+ f = p.font();
+ f.setPointSize(ITEM_TEXT_SIZE);
+ p.setFont(f);
+ p.rotate(90);
+ p.drawText(QPoint(5,0), m_bookName);
+ }
+ painter->drawPixmap(QPoint(int(rect().x()),int(rect().height()+y()-BAR_LOWER_BORDER)), *m_bufferPixmap);
+}
+
+/** Returns the width of this item. */
+int CSearchAnalysisItem::width() {
+ return m_moduleCount*(m_moduleCount>1 ? BAR_DELTAX : 0) + BAR_WIDTH;
+}
+
+/** Returns the tooltip for this item. */
+const QString CSearchAnalysisItem::getToolTip() {
+ QString toolTipString = QString("<center><b>%1</b></center><hr/>").arg(m_bookName);
+ toolTipString += "<table cellspacing=\"0\" cellpadding=\"3\" width=\"100%\" height=\"100%\" align=\"center\">";
+
+ //ToDo: Fix that loop
+ int i = 0;
+ QList<CSwordModuleInfo*>::iterator end_it = m_moduleList->end();
+
+ for (QList<CSwordModuleInfo*>::iterator it(m_moduleList->begin()); it != end_it; ++it) {
+ CSwordModuleInfo* info = (*it);
+ const QColor c = CSearchAnalysisScene::getColor(i);
+
+ toolTipString.append(
+ QString("<tr bgcolor=\"white\"><td><b><font color=\"#%1\">%2</font></b></td><td>%3 (%4%)</td></tr>")
+ .arg(QString().sprintf("%02X%02X%02X",c.red(),c.green(),c.blue()))
+ .arg(info ? info->name() : QString::null)
+ .arg( m_resultCountArray[i] )
+ .arg( (info && m_resultCountArray[i])? ((double)m_resultCountArray[i] / (double)info->searchResult().Count())*(double)100 : 0.0, 0, 'g', 2)
+ );
+ ++i;
+ }
+
+ toolTipString += "</table>";
+
+ return toolTipString;
+}
+
+}
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisitem.h b/src/frontend/searchdialog/analysis/csearchanalysisitem.h
new file mode 100644
index 0000000..5926f43
--- /dev/null
+++ b/src/frontend/searchdialog/analysis/csearchanalysisitem.h
@@ -0,0 +1,65 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef SEARCHCSEARCHANALYSISITEM_H
+#define SEARCHCSEARCHANALYSISITEM_H
+
+class CSwordModuleInfo;
+
+#include <QGraphicsRectItem>
+#include <QGraphicsScene>
+
+namespace Search {
+
+/**
+ @author The BibleTime team <info@bibletime.info>
+*/
+class CSearchAnalysisItem : public QGraphicsRectItem
+{
+public:
+
+ CSearchAnalysisItem(const int moduleCount, const QString& bookname, double *scaleFactor, QList<CSwordModuleInfo*>* modules);
+ ~CSearchAnalysisItem();
+ /**
+ * Sets the resultcount of this item
+ */
+ void setCountForModule( const int moduleIndex, const int count);
+
+ /**
+ * Returns the resultcount of this item
+ */
+ int getCountForModule( const int moduleIndex);
+ /**
+ * Does one of the modules contain hits?
+ */
+ bool hasHitsInAnyModule();
+ /**
+ * Returns the width of this item.
+ */
+ virtual int width();
+ /**
+ * Returns the tooltip for this item.
+ */
+ const QString getToolTip();
+
+private:
+ virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*);
+
+ QList<CSwordModuleInfo*>* m_moduleList;
+ double *m_scaleFactor;
+ QString m_bookName;
+ int m_moduleCount;
+ QVector<int> m_resultCountArray;
+ QPixmap* m_bufferPixmap;
+
+};
+
+}
+
+#endif
diff --git a/src/frontend/searchdialog/analysis/csearchanalysislegenditem.cpp b/src/frontend/searchdialog/analysis/csearchanalysislegenditem.cpp
new file mode 100644
index 0000000..be667e0
--- /dev/null
+++ b/src/frontend/searchdialog/analysis/csearchanalysislegenditem.cpp
@@ -0,0 +1,84 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "csearchanalysislegenditem.h"
+#include "csearchanalysisscene.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+
+#include <QPainter>
+#include <QPen>
+#include <QFont>
+
+namespace Search {
+
+const int SPACE_BETWEEN_PARTS = 5;
+const int RIGHT_BORDER = 15;
+const int LEFT_BORDER = 15;
+const int LOWER_BORDER = 10;
+const int UPPER_BORDER = 10;
+
+const int ITEM_TEXT_SIZE = 8;
+const int LABEL_TEXT_SIZE = 6;
+
+//used for the shift between the bars
+const int BAR_DELTAX = 4;
+const int BAR_DELTAY = 2;
+const int BAR_WIDTH = 2 + (2*BAR_DELTAX); //should be equal or bigger than the label font size
+// Used for the text below the bars
+const int BAR_LOWER_BORDER = 100;
+
+const int LEGEND_INNER_BORDER = 5;
+const int LEGEND_DELTAY = 4;
+const int LEGEND_WIDTH = 85;
+
+
+CSearchAnalysisLegendItem::CSearchAnalysisLegendItem(QList<CSwordModuleInfo*> *list )
+ : QGraphicsRectItem()
+{
+ m_moduleList = list;
+}
+
+/** Reimplementation. Draws the content of this item. */
+void CSearchAnalysisLegendItem::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) {
+ painter->save();
+
+ //the outer rectangle
+ QPoint p1( (int)(rect().x()), (int)(rect().y()) );
+ QPoint p2( (int)(rect().x()+rect().width()), (int)(rect().y()) + rect().height() );
+ QRect r(p1, p2);
+ r = r.normalized();
+ painter->drawRect(r);
+
+ QFont f = painter->font();
+ f.setPointSize(ITEM_TEXT_SIZE);
+ painter->setFont(f);
+
+ // for (unsigned int index=0; index < m_moduleList->count(); index++){
+ int moduleIndex = 0;
+ QList<CSwordModuleInfo*>::iterator end_it = m_moduleList->end();
+ for (QList<CSwordModuleInfo*>::iterator it(m_moduleList->begin()); it != end_it; ++it) {
+ // the module color indicators
+ QPoint p1( (int)(rect().x()) + LEGEND_INNER_BORDER, (int)(rect().y()) + LEGEND_INNER_BORDER + moduleIndex*(LEGEND_DELTAY + ITEM_TEXT_SIZE) );
+ QPoint p2(p1.x() + ITEM_TEXT_SIZE, p1.y() + ITEM_TEXT_SIZE);
+ QRect r(p1,p2);
+ painter->fillRect(r, QBrush(CSearchAnalysisScene::getColor(moduleIndex)) );
+ r = r.normalized();
+ painter->drawRect(r);
+
+ QPoint p3( p2.x() + LEGEND_INNER_BORDER, p2.y() );
+ painter->drawText(p3, (*it)->name() );
+
+ ++moduleIndex;
+ }
+ painter->restore();
+}
+
+
+}
diff --git a/src/frontend/searchdialog/analysis/csearchanalysislegenditem.h b/src/frontend/searchdialog/analysis/csearchanalysislegenditem.h
new file mode 100644
index 0000000..879f239
--- /dev/null
+++ b/src/frontend/searchdialog/analysis/csearchanalysislegenditem.h
@@ -0,0 +1,35 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef SEARCHCSEARCHANALYSISLEGENDITEM_H
+#define SEARCHCSEARCHANALYSISLEGENDITEM_H
+
+class CSwordModuleInfo;
+
+#include <QGraphicsRectItem>
+
+namespace Search {
+
+/**
+ @author The BibleTime team <info@bibletime.info>
+*/
+class CSearchAnalysisLegendItem : public QGraphicsRectItem
+{
+public:
+ CSearchAnalysisLegendItem(QList<CSwordModuleInfo*>* list );
+
+private:
+ virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*);
+ QList<CSwordModuleInfo*>* m_moduleList;
+
+};
+
+}
+
+#endif
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisscene.cpp b/src/frontend/searchdialog/analysis/csearchanalysisscene.cpp
new file mode 100644
index 0000000..7bc3ab2
--- /dev/null
+++ b/src/frontend/searchdialog/analysis/csearchanalysisscene.cpp
@@ -0,0 +1,292 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "csearchanalysisscene.h"
+#include "csearchanalysisitem.h"
+#include "csearchanalysislegenditem.h"
+
+#include "frontend/searchdialog/csearchdialog.h"
+
+#include "backend/keys/cswordversekey.h"
+#include "util/ctoolclass.h"
+
+#include <QHashIterator>
+#include <QFileDialog>
+#include <QTextCodec>
+#include <QApplication>
+
+
+
+namespace Search {
+
+const int SPACE_BETWEEN_PARTS = 5;
+const int RIGHT_BORDER = 15;
+const int LEFT_BORDER = 15;
+const int LOWER_BORDER = 10;
+const int UPPER_BORDER = 10;
+
+const int ITEM_TEXT_SIZE = 8;
+const int LABEL_TEXT_SIZE = 6;
+
+//used for the shift between the bars
+const int BAR_DELTAX = 4;
+const int BAR_DELTAY = 2;
+const int BAR_WIDTH = 2 + (2*BAR_DELTAX); //should be equal or bigger than the label font size
+// Used for the text below the bars
+const int BAR_LOWER_BORDER = 90;
+
+const int LEGEND_INNER_BORDER = 5;
+const int LEGEND_DELTAY = 4;
+const int LEGEND_WIDTH = 85;
+
+
+CSearchAnalysisScene::CSearchAnalysisScene(QObject *parent )
+ : QGraphicsScene(parent),
+ m_scaleFactor(0.0),
+ m_legend(0)
+{
+ setBackgroundBrush(QBrush(Qt::white));
+ setSceneRect(0,0,1,1);
+}
+
+
+QHash<QString, CSearchAnalysisItem*>* CSearchAnalysisScene::getSearchAnalysisItemList() {
+ // Returns pointer to the search analysis items
+ return &m_itemList;
+}
+
+/** Starts the analysis of the search result. This should be called only once because QCanvas handles the updates automatically. */
+void CSearchAnalysisScene::analyse(QList<CSwordModuleInfo*> modules) {
+ /**
+ * Steps of analysing our search result;
+ * -Create the items for all available books ("Genesis" - "Revelation")
+ * -Iterate through all modules we analyse
+ * -Go through all books of this module
+ * -Find out how many times we found the book
+ * -Set the count to the items which belongs to the book
+ */
+ setModules(modules);
+
+ m_lastPosList.clear();
+ const int numberOfModules = m_moduleList.count();
+ if (!numberOfModules)
+ return;
+ m_legend = new CSearchAnalysisLegendItem(&m_moduleList);
+ addItem(m_legend);
+ m_legend->setRect(LEFT_BORDER, UPPER_BORDER,
+ LEGEND_WIDTH, LEGEND_INNER_BORDER*2 + ITEM_TEXT_SIZE*numberOfModules + LEGEND_DELTAY*(numberOfModules-1) );
+ m_legend->show();
+
+ int xPos = (int)(LEFT_BORDER + m_legend->rect().width() + SPACE_BETWEEN_PARTS);
+ int moduleIndex = 0;
+ m_maxCount = 0;
+ int count = 0;
+ CSwordVerseKey key(0);
+ key.key("Genesis 1:1");
+
+ CSearchAnalysisItem* analysisItem = m_itemList[key.book()];
+ bool ok = true;
+ while (ok && analysisItem) {
+ moduleIndex = 0;
+ QList<CSwordModuleInfo*>::iterator end_it = m_moduleList.end();
+ for (QList<CSwordModuleInfo*>::iterator it(m_moduleList.begin()); it != end_it; ++it) {
+ qApp->processEvents( QEventLoop::AllEvents );
+ if (!m_lastPosList.contains(*it)) {
+ m_lastPosList.insert(*it,0);
+ }
+
+ analysisItem->setCountForModule(moduleIndex, (count = getCount(key.book(), *it)));
+ m_maxCount = (count > m_maxCount) ? count : m_maxCount;
+
+ ++moduleIndex;
+ }
+ if (analysisItem->hasHitsInAnyModule())
+ {
+ analysisItem->setRect(xPos, UPPER_BORDER, analysisItem->rect().width(), analysisItem->rect().height());
+ QString tip = analysisItem->getToolTip();
+ analysisItem->setToolTip(tip);
+ analysisItem->show();
+ xPos += (int)analysisItem->width() + SPACE_BETWEEN_PARTS;
+ }
+ ok = key.next(CSwordVerseKey::UseBook);
+ analysisItem = m_itemList[key.book()];
+ }
+ setSceneRect(0,0, xPos+BAR_WIDTH+(m_moduleList.count()-1)*BAR_DELTAX+RIGHT_BORDER, height() );
+ slotResized();
+}
+
+/** Sets the module list used for the analysis. */
+void CSearchAnalysisScene::setModules(QList<CSwordModuleInfo*> modules) {
+ m_moduleList.clear();
+ foreach (CSwordModuleInfo * mod, modules) {
+ if ( (mod->type() == CSwordModuleInfo::Bible) || (mod->type() == CSwordModuleInfo::Commentary) ) { //a Bible or an commentary
+ m_moduleList.append(mod);
+ }
+ }
+
+ m_itemList.clear();
+ CSearchAnalysisItem* analysisItem = 0;
+ CSwordVerseKey key(0);
+ key.key("Genesis 1:1");
+ do {
+ analysisItem = new CSearchAnalysisItem(m_moduleList.count(), key.book(), &m_scaleFactor, &m_moduleList);
+ addItem(analysisItem);
+ analysisItem->hide();
+ m_itemList.insert(key.book(), analysisItem);
+ }
+ while (key.next(CSwordVerseKey::UseBook));
+ update();
+}
+
+/** Sets back the items and deletes things to cleanup */
+void CSearchAnalysisScene::reset() {
+ m_scaleFactor = 0.0;
+
+ QHashIterator<QString, CSearchAnalysisItem*> it( m_itemList ); // iterator for items
+ while ( it.hasNext() ) {
+ it.next();
+ if (it.value()) it.value()->hide();
+ }
+ m_lastPosList.clear();
+
+ if (m_legend) m_legend->hide();
+
+ delete m_legend;
+ m_legend = 0;
+
+ update();
+}
+
+/** No descriptions */
+void CSearchAnalysisScene::slotResized() {
+ m_scaleFactor = (double)( (double)(height()-UPPER_BORDER-LOWER_BORDER-BAR_LOWER_BORDER-100-(m_moduleList.count()-1)*BAR_DELTAY)
+ /(double)m_maxCount);
+ QHashIterator<QString, CSearchAnalysisItem*> it( m_itemList );
+ while ( it.hasNext() ) {
+ it.next();
+ if (it.value()) {
+ it.value()->setRect(it.value()->rect().x(), UPPER_BORDER, BAR_WIDTH + (m_moduleList.count()-1)*BAR_DELTAX, height()-LOWER_BORDER-BAR_LOWER_BORDER);
+ }
+ }
+ update();
+}
+
+/** This function returns a color for each module */
+QColor CSearchAnalysisScene::getColor(int index) {
+ switch (index) {
+ case 0:
+ return Qt::red;
+ case 1:
+ return Qt::darkGreen;
+ case 2:
+ return Qt::blue;
+ case 3:
+ return Qt::cyan;
+ case 4:
+ return Qt::magenta;
+ case 5:
+ return Qt::darkRed;
+ case 6:
+ return Qt::darkGray;
+ case 7:
+ return Qt::black;
+ case 8:
+ return Qt::darkCyan;
+ case 9:
+ return Qt::darkMagenta;
+ default:
+ return Qt::red;
+ }
+}
+
+/** Returns the count of the book in the module */
+unsigned int CSearchAnalysisScene::getCount( const QString book, CSwordModuleInfo* module ) {
+ sword::ListKey& result = module->searchResult();
+ const int length = book.length();
+ unsigned int i = m_lastPosList[module];
+ unsigned int count = 0;
+ const unsigned int resultCount = result.Count();
+ while (i < resultCount) {
+ if ( strncmp(book.toUtf8(), (const char*)*result.GetElement(i), length) )
+ break;
+ i++;
+ ++count;
+ }
+ m_lastPosList.insert(module,i);
+ return count;
+}
+
+void CSearchAnalysisScene::saveAsHTML() {
+ const QString fileName = QFileDialog::getSaveFileName(0, tr("Save Search Analysis"), QString::null, tr("HTML files (*.html;*.HTML;*.HTM;*.htm)") );
+ if (fileName.isEmpty()) return;
+
+ int count = 0;
+ QString countStr = "";
+ QString m_searchAnalysisHTML = "";
+ QString tableTitle = "";
+ QString tableTotals = "";
+ QString VerseRange = "";
+ const QString txtCSS = QString("<style type=\"text/css\">\ntd {border:1px solid black;}\nth {font-size: 130%; text-align:left; vertical-align:top;}\n</style>\n");
+ const QString metaEncoding = QString("<META http-equiv=Content-Type content=\"text/html; charset=utf-8\">");
+ CSwordVerseKey key(0);
+ sword::ListKey searchResult;
+
+ key.key("Genesis 1:1");
+
+ CSearchAnalysisItem* analysisItem = m_itemList.value( key.book() );
+
+ QString text = "<html>\n<head>\n<title>" + tr("BibleTime Search Analysis") + "</title>\n" + txtCSS + metaEncoding + "</head>\n<body>\n";
+ text += "<table>\n<tr><th>" + tr("Search text :") + "</th><th>" + CSearchDialog::getSearchDialog()->searchText() + "</th></tr>\n";
+
+ tableTitle = "<tr><th align=\"left\">" + tr("Book") + "</th>";
+ tableTotals = "<tr><td align=\"left\">" + tr("Total hits") + "</td>";
+
+ foreach (CSwordModuleInfo* mod, m_moduleList) {
+ tableTitle += QString("<th align=\"left\">") + mod->name() + QString("</th>");
+ searchResult = mod->searchResult();
+ countStr.setNum(searchResult.Count());
+
+ tableTotals += QString("<td align=\"right\">") + countStr + QString("</td>");
+ }
+ tableTitle += QString("</tr>\n");
+ tableTotals += QString("</tr>\n");
+
+ m_searchAnalysisHTML = "";
+ bool ok = true;
+ while (ok) {
+ m_searchAnalysisHTML += QString("<tr><td>") + key.book() + QString("</td>");
+ analysisItem = m_itemList.value( key.book() );
+
+ int moduleIndex = 0;
+ QList<CSwordModuleInfo*>::iterator end_it = m_moduleList.end();
+ for (QList<CSwordModuleInfo*>::iterator it(m_moduleList.begin()); it != end_it; ++it) {
+ count = analysisItem->getCountForModule(moduleIndex);
+ countStr.setNum(count);
+ m_searchAnalysisHTML += QString("<td align=\"right\">") + countStr + QString("</td>");
+
+ ++moduleIndex;
+ }
+ m_searchAnalysisHTML += QString("</tr>\n");
+ ok = key.next(CSwordVerseKey::UseBook);
+ }
+
+ text += QString("<table>\n") + tableTitle + tableTotals + m_searchAnalysisHTML + QString("</table>\n");
+ text += QString("<center>") + tr("Created by <a href=\"http://www.bibletime.info/\">BibleTime</a>") + QString("</center>");
+ text += QString("</body></html>");
+
+ CToolClass::savePlainFile(fileName, text, false, QTextCodec::codecForName("UTF8"));
+}
+
+void CSearchAnalysisScene::resizeHeight(int height)
+{
+ setSceneRect(0,0, sceneRect().width(), height);
+ slotResized();
+}
+
+}
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisscene.h b/src/frontend/searchdialog/analysis/csearchanalysisscene.h
new file mode 100644
index 0000000..755dacf
--- /dev/null
+++ b/src/frontend/searchdialog/analysis/csearchanalysisscene.h
@@ -0,0 +1,88 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef SEARCHCSEARCHANALYSISSCENE_H
+#define SEARCHCSEARCHANALYSISSCENE_H
+
+#include "csearchanalysisitem.h"
+
+class CSwordModuleInfo;
+
+
+#include <QGraphicsScene>
+#include <QColor>
+#include <QMap>
+#include <QHash>
+
+namespace Search {
+
+class CSearchAnalysisLegendItem;
+
+/**
+ @author The BibleTime team <info@bibletime.info>
+*/
+class CSearchAnalysisScene : public QGraphicsScene {
+ Q_OBJECT
+public:
+ CSearchAnalysisScene(QObject* parent);
+
+ virtual ~CSearchAnalysisScene() {}
+
+ /**
+ * Starts the analysis of the search result.
+ * This should be called only once because
+ * QCanvas handles the updates automatically.
+ */
+ void analyse(QList<CSwordModuleInfo*> modules);
+ /**
+ * This function returns a color for each module
+ * @return The color at position index in the list
+ */
+ static QColor getColor(int index);
+ /**
+ * This function returns a pointer to the list of AnalysisItems
+ */
+ QHash<QString, CSearchAnalysisItem*>* getSearchAnalysisItemList();
+ void reset();
+ /**
+ * resize the height of the scene
+ */
+ void resizeHeight(int height);
+
+public slots:
+ void saveAsHTML();
+
+protected slots: // Protected slots
+ /**
+ * No descriptions
+ */
+ void slotResized();
+
+protected:
+ void setModules(QList<CSwordModuleInfo*> modules);
+
+private:
+ /**
+ * Returns the count of the book in the module
+ */
+ unsigned int getCount( const QString book, CSwordModuleInfo* module );
+
+ QList<CSwordModuleInfo*> m_moduleList;
+ QHash<QString, CSearchAnalysisItem*> m_itemList;
+ QMap<CSwordModuleInfo*,unsigned int> m_lastPosList;
+ int m_maxCount;
+ double m_scaleFactor;
+ CSearchAnalysisLegendItem* m_legend;
+
+
+};
+
+}
+
+#endif
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisview.cpp b/src/frontend/searchdialog/analysis/csearchanalysisview.cpp
new file mode 100644
index 0000000..0d58c78
--- /dev/null
+++ b/src/frontend/searchdialog/analysis/csearchanalysisview.cpp
@@ -0,0 +1,50 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "csearchanalysisview.h"
+#include "csearchanalysisscene.h"
+
+#include <QWidget>
+#include <QGraphicsView>
+#include <QResizeEvent>
+
+
+namespace Search {
+
+CSearchAnalysisView::CSearchAnalysisView(CSearchAnalysisScene* scene, QWidget* parent)
+ : QGraphicsView(scene, parent)
+{
+ setFocusPolicy(Qt::WheelFocus);
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ resize(sizeHint());
+}
+
+
+/** Returns the sizeHint for this view */
+QSize CSearchAnalysisView::sizeHint() const {
+ return QGraphicsView::sizeHint();
+}
+
+/** No descriptions */
+void CSearchAnalysisView::resizeEvent( QResizeEvent* e) {
+ QGraphicsView::resizeEvent(e);
+ scene()->setSceneRect(0,0, scene()->sceneRect().width(), viewport()->height() );
+}
+
+
+/** Returns the item at position p. If there no item at that point return 0.
+Is needed?
+*/
+//CSearchAnalysisItem* CSearchAnalysisView::itemAt( const QPoint& p )
+//{
+//}
+
+
+
+}
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisview.h b/src/frontend/searchdialog/analysis/csearchanalysisview.h
new file mode 100644
index 0000000..35c4419
--- /dev/null
+++ b/src/frontend/searchdialog/analysis/csearchanalysisview.h
@@ -0,0 +1,54 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef SEARCHCSEARCHANALYSISVIEW_H
+#define SEARCHCSEARCHANALYSISVIEW_H
+
+#include <QGraphicsView>
+#include <QSize>
+
+class QResizeEvent;
+
+namespace Search {
+
+class CSearchAnalysisScene;
+
+/**
+ @author The BibleTime team <info@bibletime.info>
+*/
+class CSearchAnalysisView : public QGraphicsView
+{
+public:
+ CSearchAnalysisView(CSearchAnalysisScene* scene, QWidget* parent);
+
+ ~CSearchAnalysisView() {}
+
+/**
+ * Returns the sizeHint for this view
+ * We give back the size of the parent widgetas default.
+ * This is a reimplementation from QCanvasView::sizeHint().
+ */
+ virtual QSize sizeHint() const;
+
+ /**
+ * Returns the item at position p or 0 if there is no item.
+ */
+ //CSearchAnalysisItem* itemAt( const QPoint& p );
+
+protected:
+ /**
+ * Reimplementation.
+ */
+ virtual void resizeEvent(QResizeEvent* e);
+
+};
+
+}
+
+#endif
diff --git a/src/frontend/searchdialog/btsearchoptionsarea.cpp b/src/frontend/searchdialog/btsearchoptionsarea.cpp
new file mode 100644
index 0000000..a4dbfd4
--- /dev/null
+++ b/src/frontend/searchdialog/btsearchoptionsarea.cpp
@@ -0,0 +1,530 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btsearchoptionsarea.h"
+#include "csearchmodulechooserdialog.h"
+#include "crangechooserdialog.h"
+
+#include "util/directoryutil.h"
+#include "util/cresmgr.h"
+#include "util/ctoolclass.h"
+#include "util/cpointers.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/config/cbtconfig.h"
+#include "frontend/htmldialogs/bttabhtmldialog.h"
+
+#include <QHBoxLayout>
+#include <QGroupBox>
+#include <QGridLayout>
+#include <QLabel>
+#include <QPushButton>
+#include <QRadioButton>
+#include <QDebug>
+#include <QLineEdit>
+#include <QMessageBox>
+#include <QEvent>
+
+
+namespace Search {
+
+BtSearchOptionsArea::BtSearchOptionsArea(QWidget *parent )
+ : QWidget(parent)
+{
+ initView();
+ initConnections();
+ readSettings();
+}
+
+BtSearchOptionsArea::~BtSearchOptionsArea() {
+ saveSettings();
+}
+
+QString BtSearchOptionsArea::searchText() const {
+ return m_searchTextCombo->currentText();
+}
+
+BtSearchOptionsArea::SearchType BtSearchOptionsArea::searchType()
+{
+ if (m_typeAndButton->isChecked()) {
+ return BtSearchOptionsArea::AndType;
+ }
+ if (m_typeOrButton->isChecked()) {
+ return BtSearchOptionsArea::OrType;
+ }
+ return BtSearchOptionsArea::FullType;
+}
+
+QPushButton* BtSearchOptionsArea::searchButton() const {
+ return m_searchButton;
+}
+
+void BtSearchOptionsArea::setSearchText(const QString& text) {
+ bool found = false;
+ int i = 0;
+ for (i = 0; !found && i < m_searchTextCombo->count(); ++i) {
+ if (m_searchTextCombo->itemText(i) == text) {
+ found = true;
+ }
+ }
+ // This is needed because in the for loop i is incremented before the comparison (++i)
+ // As a result the index i is actually one greater than expected.
+ i--;
+ if (!found) {
+ i = 0;
+ m_searchTextCombo->insertItem(0, text );
+ }
+
+ m_searchTextCombo->setCurrentIndex(i);
+ m_searchTextCombo->setFocus();
+}
+
+void BtSearchOptionsArea::initView()
+{
+ QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+ this->setSizePolicy(sizePolicy);
+ hboxLayout = new QHBoxLayout(this);
+
+ searchGroupBox = new QGroupBox(this);
+
+ gridLayout = new QGridLayout(searchGroupBox);
+
+ gridLayout->setHorizontalSpacing(3);
+
+ // ******** label for search text editor***********
+ m_searchTextLabel = new QLabel(tr("Search for:"), searchGroupBox);
+ m_searchTextLabel->setWordWrap(false);
+ gridLayout->addWidget(m_searchTextLabel, 0, 0);
+
+ // **********Buttons******************
+
+ m_searchButton = new QPushButton(this);
+ m_searchButton->setText(tr("&Search"));
+ m_searchButton->setIcon( util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::icon));
+ m_searchButton->setToolTip(tr("Start to search the text in the chosen works"));
+ gridLayout->addWidget(m_searchButton, 0, 2);
+
+ m_chooseModulesButton = new QPushButton(tr("Ch&oose..."), searchGroupBox);
+ m_chooseModulesButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::chooseworks_icon));
+ m_chooseModulesButton->setToolTip( tr("Choose works for the search"));
+ gridLayout->addWidget(m_chooseModulesButton, 2, 2);
+
+ m_chooseRangeButton = new QPushButton(tr("S&etup..."), searchGroupBox);
+ m_chooseRangeButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::setupscope_icon));
+ m_chooseRangeButton->setToolTip(tr("Configure predefined scopes for search"));
+ gridLayout->addWidget(m_chooseRangeButton, 3, 2);
+
+ // ************* Search type (AND/OR) selector ***************************************
+ QHBoxLayout* typeSelectorLayout = new QHBoxLayout();
+ int tsLeft, tsTop, tsRight, tsBottom;
+ // Added space looks nicer and enhances readability
+ typeSelectorLayout->getContentsMargins(&tsLeft, &tsTop, &tsRight, &tsBottom);
+ typeSelectorLayout->setContentsMargins(tsLeft, 0, tsRight, tsBottom + CToolClass::mWidth(this,1) );
+ typeSelectorLayout->setSpacing(typeSelectorLayout->spacing()+CToolClass::mWidth(this,1));
+ QHBoxLayout* fullButtonLayout = new QHBoxLayout();
+ fullButtonLayout->setSpacing(CToolClass::mWidth(this,1)/2);
+ m_typeAndButton = new QRadioButton(tr("All words"));
+ m_typeAndButton->setChecked(true);
+ m_typeOrButton = new QRadioButton(tr("Some words"));
+ m_typeFreeButton = new QRadioButton(tr("Free"));
+
+ m_typeAndButton->setToolTip(tr("All of the words (AND is added between the words)"));
+ m_typeOrButton->setToolTip(tr("Some of the words (OR is added between the words)"));
+ m_typeFreeButton->setToolTip(tr("Full lucene syntax"));
+
+ m_helpLabel = new QLabel(tr(" (<a href='syntax_help'>full syntax</a>)"));
+ m_helpLabel->setToolTip(tr("Click the link to get help for search syntax"));
+
+ typeSelectorLayout->addWidget(m_typeAndButton);
+ typeSelectorLayout->addWidget(m_typeOrButton);
+ fullButtonLayout->addWidget(m_typeFreeButton);
+ fullButtonLayout->addWidget(m_helpLabel);
+ typeSelectorLayout->addLayout(fullButtonLayout);
+ gridLayout->addLayout(typeSelectorLayout, 1,1, 1,-1, Qt::AlignLeft|Qt::AlignTop);
+
+ // ************* Label for search range/scope selector *************
+ m_searchScopeLabel = new QLabel(tr("Scope:"), searchGroupBox);
+ m_searchScopeLabel->setWordWrap(false);
+ gridLayout->addWidget(m_searchScopeLabel, 3, 0);
+
+ // ***********Range/scope selector combo box***********
+ m_rangeChooserCombo = new QComboBox(searchGroupBox);
+ QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Fixed);
+ sizePolicy2.setHorizontalStretch(0);
+ sizePolicy2.setVerticalStretch(0);
+ sizePolicy2.setHeightForWidth(m_rangeChooserCombo->sizePolicy().hasHeightForWidth());
+ m_rangeChooserCombo->setSizePolicy(sizePolicy2);
+ m_rangeChooserCombo->setToolTip(tr("Choose the scope (books/chapters/verses to search in).<br />Applicable for Bibles and commentaries."));
+ gridLayout->addWidget(m_rangeChooserCombo, 3, 1);
+
+ // ************* Search text combo box *******************
+ m_searchTextCombo = new CHistoryComboBox(searchGroupBox);
+ sizePolicy2.setHeightForWidth(m_searchTextCombo->sizePolicy().hasHeightForWidth());
+ m_searchTextCombo->setSizePolicy(sizePolicy2);
+ m_searchTextCombo->setFocusPolicy(Qt::WheelFocus);
+ m_searchTextCombo->setProperty("sizeLimit", QVariant(25));
+ m_searchTextCombo->setProperty("duplicatesEnabled", QVariant(false));
+ m_searchTextCombo->setToolTip(tr("The text you want to search for"));
+ m_searchTextCombo->setInsertPolicy(QComboBox::NoInsert);
+ gridLayout->addWidget(m_searchTextCombo, 0, 1);
+
+ m_modulesLabel = new QLabel(tr("Works:"), searchGroupBox);
+ gridLayout->addWidget(m_modulesLabel, 2, 0);
+
+ m_modulesCombo = new QComboBox(searchGroupBox);
+ m_modulesCombo->setDuplicatesEnabled(false);
+ gridLayout->addWidget(m_modulesCombo, 2, 1);
+
+ hboxLayout->addWidget(searchGroupBox);
+
+ // Set the minimum size before the widgets are populated with data.
+ // Otherwise we will get problems with sizing.
+ setMinimumSize(minimumSizeHint());
+
+ refreshRanges();
+ //set the initial focus
+ m_searchTextCombo->setFocus();
+ // event filter to prevent the Return/Enter presses in the combo box doing something
+ // in the parent widget
+ m_searchTextCombo->installEventFilter(this);
+}
+
+void BtSearchOptionsArea::initConnections()
+{
+ QObject::connect( m_searchTextCombo->lineEdit(), SIGNAL(returnPressed ()),
+ this, SLOT( slotSearchTextEditReturnPressed() )
+ );
+ connect(m_chooseModulesButton, SIGNAL(clicked()), this, SLOT(chooseModules()));
+ connect(m_chooseRangeButton, SIGNAL(clicked()), this, SLOT(setupRanges()));
+ connect(m_modulesCombo, SIGNAL(activated(int)), this, SLOT(moduleListTextSelected(int) ) );
+ connect(m_helpLabel, SIGNAL(linkActivated(QString)), this, SLOT(syntaxHelp()));
+ connect(m_searchTextCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotValidateText(const QString&)));
+}
+
+/** Sets the modules used by the search. */
+void BtSearchOptionsArea::setModules( QList<CSwordModuleInfo*> modules )
+{
+ qDebug("BtSearchOptionsArea::setModules");
+ qDebug() << modules;
+ QString t;
+
+ m_modules.clear(); //remove old modules
+ QList<CSwordModuleInfo*>::iterator end_it = modules.end();
+
+ for (QList<CSwordModuleInfo*>::iterator it(modules.begin()); it != end_it; ++it) {
+ //ToDo: Check for containsRef compat
+ if (*it == 0) { //don't operate on null modules.
+ continue;
+ }
+ qDebug() << "new module:" << (*it)->name();
+ if ( !m_modules.contains(*it) ) {
+ m_modules.append( *it );
+ t.append( (*it)->name() );
+ if (*it != modules.last()) {
+ t += QString::fromLatin1(", "); // so that it will become a readable list (WLC, LXX, GerLut...)
+ }
+ }
+ };
+ //m_modulesLabel->setText(t);
+ int existingIndex = m_modulesCombo->findText(t);
+ qDebug() << "index of the module list string which already exists in combobox:" << existingIndex;
+ if (existingIndex >= 0) {
+ m_modulesCombo->removeItem(existingIndex);
+ }
+ if (m_modulesCombo->count() > 10) {
+ m_modulesCombo->removeItem(m_modulesCombo->count()-1);
+ }
+ m_modulesCombo->insertItem(0, t);
+ m_modulesCombo->setItemData(0, t, Qt::ToolTipRole);
+ m_modulesCombo->setCurrentIndex(0);
+ m_modulesCombo->setToolTip(t);
+ //Save the list in config here, not when deleting, because the history may be used
+ // elsewhere while the dialog is still open
+ QStringList historyList;
+ for (int i = 0; i < m_modulesCombo->count(); ++i) {
+ historyList.append(m_modulesCombo->itemText(i));
+ }
+ CBTConfig::set(CBTConfig::searchModulesHistory, historyList);
+ emit( sigSetSearchButtonStatus( (modules.count() != 0) ) );
+}
+
+// Catch activated signal of module selector combobox
+void BtSearchOptionsArea::moduleListTextSelected(int index)
+{
+ qDebug("BtSearchOptionsArea::moduleListTextSelected");
+ //create the module list
+ QString text = m_modulesCombo->itemText(index);
+ qDebug() << text;
+ QStringList moduleNamesList = text.split(", ");
+ QList<CSwordModuleInfo*> moduleList;
+ foreach(QString name, moduleNamesList) {
+ moduleList.append(CPointers::backend()->findModuleByName(name));
+ }
+ //set the list and the combobox list and text
+ setModules(moduleList);
+}
+
+void BtSearchOptionsArea::chooseModules() {
+ QString title(tr("Works to Search in"));
+ QString label(tr("Select the works which should be searched."));
+ CSearchModuleChooserDialog* dlg = new CSearchModuleChooserDialog(this, title, label, modules());
+ connect(dlg, SIGNAL(modulesChanged(QList<CSwordModuleInfo*>, QTreeWidget*)), this, SLOT(setModules(QList<CSwordModuleInfo*>)));
+ dlg->exec();
+}
+
+QList<CSwordModuleInfo*> BtSearchOptionsArea::modules() const {
+ return m_modules;
+}
+
+void BtSearchOptionsArea::reset() {
+ m_rangeChooserCombo->setCurrentIndex(0);
+ m_searchTextCombo->clearEditText();
+}
+
+void BtSearchOptionsArea::saveSettings() {
+ CBTConfig::set(CBTConfig::searchTexts, m_searchTextCombo->historyItems());
+ SearchType t = FullType;
+ if (m_typeAndButton->isChecked()) {
+ t = AndType;
+ }
+ if (m_typeOrButton->isChecked()) {
+ t = OrType;
+ }
+ CBTConfig::set(CBTConfig::searchType, t);
+}
+
+void BtSearchOptionsArea::readSettings() {
+ QStringList texts = CBTConfig::get(CBTConfig::searchTexts);
+ //for some reason the slot was called when setting the upmost item
+ disconnect(m_searchTextCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotValidateText(const QString&)));
+ for (int i=0; i<texts.size(); i++)
+ {
+ if (texts.at(i).size() > 0)
+ m_searchTextCombo->addItem(texts.at(i));
+ }
+ connect(m_searchTextCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotValidateText(const QString&)));
+
+ m_modulesCombo->insertItems(0, CBTConfig::get(CBTConfig::searchModulesHistory));
+ for (int i = 0; i < m_modulesCombo->count(); ++i) {
+ m_modulesCombo->setItemData(i, m_modulesCombo->itemText(i), Qt::ToolTipRole);
+ }
+
+ int stype = CBTConfig::get(CBTConfig::searchType);
+ switch (stype) {
+ case AndType: m_typeAndButton->setChecked(true);
+ break;
+ case OrType: m_typeOrButton->setChecked(true);
+ break;
+ default: m_typeFreeButton->setChecked(true);
+ }
+}
+
+void BtSearchOptionsArea::aboutToShow() {
+ m_searchTextCombo->setFocus();
+}
+
+void BtSearchOptionsArea::setupRanges() {
+ CRangeChooserDialog* chooser = new CRangeChooserDialog(this);
+ chooser->exec();
+
+ refreshRanges();
+}
+
+void BtSearchOptionsArea::syntaxHelp() {
+
+ QString style = QString(
+ "<style type='text/css'>"
+ "h1 a {font-size: medium}"
+ "table {margin-left: 20px}"
+ "td {"
+ " border-width: 3px 3px 3px 3px;"
+ " border-style: solid solid solid solid;"
+ " border-color: white white white white;"
+ " background-color: #faf0e6;"
+ "}"
+ "p#links {margin-left: 20px}"
+ "</style>");
+
+ //: Don't translate words inside <> tags!
+ //: Translate 'All words' etc. indentically to the Search dialog options.
+ QString intro = tr(
+ "<p>"
+ "This help is mainly for 'Full syntax' option. 'All words' and 'Some words' options " "have more limited syntax; <a href='#wildcards'>wildcards</a> and <a " "href='#fields'>text fields</a> are supported for them. Some other syntax features " "may give strange or wrong results with All words/Some words."
+ "</p>");
+
+ QString links = tr(
+ "<p id='links'>"
+ "<A href='#allsome'>Which words to find</A><br />"
+ "<A href='#grouping'>Grouping and order</A><br />"
+ "<A href='#wildcards'>Wildcards (partial words)</A><br />"
+ "<A href='#fields'>Text fields (different parts of text)</A><br/>"
+ "<A href='#lucene'>Other syntax features</A><br/>"
+ "</p>");
+
+ //: Syntax words (AND, OR...) must not be translated.
+ QString whichwords = tr(
+ "<h1><A name='allsome'>Which words to find</A></h1>"
+ "<p>Search terms are separated by spaces. <strong>AND</strong> (all words), " "<strong>OR</strong> (some words) and <strong>NOT</strong> (not the following word) " "can be added between the words. If none is added explicitly OR is used " "automatically. '<strong>+</strong>word' means the word must be in the results, " "'<strong>-</strong>word' means it must not be in the results.</p>");
+
+ //: In examples words to be searched for may be translated, but syntax words (AND, OR...) must not be translated.
+ QString whichwordstable = tr(
+ "<p><table><tr>"
+ "<td>jesus AND god</td><td>Finds verses with both 'Jesus' and 'God'</td>"
+ "</tr><tr>"
+ "<td>jesus OR god</td><td>Finds verses with 'Jesus' or 'God' or both</td>"
+ "</tr><tr>"
+ "<td>jesus NOT god</td><td>Finds verses with 'Jesus' but with no 'God'</td>"
+ "</tr><tr>"
+ "<td>+jesus -god</td><td>Finds verses with 'Jesus' but with no 'God'</td>"
+ "</tr></table></p>");
+
+ QString grouping = tr(
+ "<h1><A name='grouping'>Grouping and order</A></h1>"
+ "<p>Words can be grouped with <strong>parenthesis</strong>. "
+ "Strict word order can be defined with <strong>quotes</strong>.</p>");
+
+ QString groupingtable = tr(
+ "<p><table><tr>"
+ "<td>(a AND b) OR c</td><td>Finds verses with both 'a' AND 'b', and verses with 'c'</td>"
+ "</tr><tr>"
+ "<td>\"says lord\"</td><td>Finds e.g. '...Isaiah says, \"Lord...' but not '...says the LORD'</td>"
+ "</tr><tr>"
+ "<td>\"says the lord\"</td><td>Finds all verses with 'says the LORD'</td>"
+ "</tr></table></p>");
+
+ QString wildcards = tr(
+ "<h1><A name='wildcards'>Wildcards (partial words)</A></h1>"
+ "<p>'<strong>*</strong>' matches any sequence of 0 or more characters, while '<strong>?</strong>' matches any single character. A wildcard can not be used in the beginning of a word.</p>");
+
+ QString wildcardstable = tr(
+ "<p><table><tr>"
+ "<td>a*</td><td>All words beginning with 'a'</td>"
+ "</tr><tr>"
+ "<td>a*a</td><td>'Assyria', 'aroma', 'abba' etc.</td>"
+ "</tr><tr>"
+ "<td>a?</td><td>'at' and 'an'</td>"
+ "</tr><tr>"
+ "<td>a??a</td><td>'abba', 'area', 'Asia' etc.</td>"
+ "</tr></table></p>");
+
+ QString fields = tr(
+ "<h1><A name='fields'>Text fields (different parts of text)</A></h1>"
+ "<p>Available text fields:<br /><table>"
+ "<tr><td>heading:</td><td>Searches headings</td></tr>"
+ "<tr><td>footnote:</td><td>Searches footnotes</td></tr>"
+ "<tr><td>strong:</td><td>Searches Strong's numbers</td></tr>"
+ "<tr><td>morph:</td><td>Searches morphology codes</td></tr></table></p>");
+
+ QString fieldstable = tr(
+ "<p>Examples:<br /><table>"
+ "<tr><td>heading:Jesus</td><td>Finds headings with 'Jesus'</td></tr>"
+ "<tr><td>footnote:Jesus AND footnote:said</td><td>Finds footnotes with 'Jesus' and 'said'</td></tr>"
+ "<tr><td>strong:G846</td><td>Finds verses with Strong's Greek number 846</td></tr>"
+ "<tr><td>morph:\"N-NSF\"</td><td>Finds verses with morphology code 'N-NSF'</td>"
+ "</tr></table></p>");
+
+ QString lucene = tr(
+ "<h1><A name='lucene'>Other syntax features</A></h1>"
+ "<p>BibleTime uses the CLucene search engine. You can read more on the <a href='http://lucene.apache.org/java/1_4_3/queryparsersyntax.html'>lucene syntax web page</a> (in external browser).</p>");
+
+ QString syntax = style + intro + links + whichwords + whichwordstable +
+ grouping + groupingtable + wildcards + wildcardstable +
+ fields + fieldstable + lucene;
+
+ BtTabHtmlDialog* dlg = new BtTabHtmlDialog(tr("Search Syntax Help"), 0, this);
+ dlg->setHtml(syntax);
+ dlg->show();
+}
+
+void BtSearchOptionsArea::refreshRanges() {
+ //the first option is fixed, the others can be edited using the "Setup ranges" button.
+ m_rangeChooserCombo->clear();
+ m_rangeChooserCombo->insertItem(0, QString("[") + tr("No search scope") + QString("]"));
+ //TODO: what about this?
+ //m_rangeChooserCombo->insertItem(tr("Last search result"));
+
+ //insert the user-defined ranges
+ m_rangeChooserCombo->insertItems(1, CBTConfig::get(CBTConfig::searchScopes).keys());
+
+}
+
+sword::ListKey BtSearchOptionsArea::searchScope() {
+ if (m_rangeChooserCombo->currentIndex() > 0) { //is not "no scope"
+ CBTConfig::StringMap map = CBTConfig::get(CBTConfig::searchScopes);
+ QString scope = map[ m_rangeChooserCombo->currentText() ];
+ if (!scope.isEmpty()) {
+ return sword::VerseKey().ParseVerseList( (const char*)scope.toUtf8(), "Genesis 1:1", true);
+ }
+ }
+ return sword::ListKey();
+}
+
+bool BtSearchOptionsArea::hasSearchScope() {
+ return (searchScope().Count() > 0);
+}
+
+void BtSearchOptionsArea::addToHistory(const QString& text)
+{
+ m_searchTextCombo->addToHistory(text);
+}
+
+void BtSearchOptionsArea::slotSearchTextEditReturnPressed()
+{
+ qDebug("BtSearchOptionsArea::slotSearchTextEditReturnPressed");
+ m_searchTextCombo->addToHistory( m_searchTextCombo->currentText() );
+ emit sigStartSearch();
+}
+
+bool BtSearchOptionsArea::eventFilter(QObject* obj, QEvent* event)
+{
+ if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
+ //qDebug() << "BtSearchOptionsArea::eventFilter" << obj << event;
+ if (obj == m_searchTextCombo->view() || obj == m_searchTextCombo || obj == m_searchTextCombo->lineEdit()) {
+ //qDebug() << "BtSearchOptionsArea::eventFilter" << obj << event;
+ obj->event(event);
+ // don't handle this event in parent
+ event->accept();
+ return true;
+ }
+ }
+ return QWidget::eventFilter(obj, event);
+}
+
+void BtSearchOptionsArea::slotValidateText(const QString& /*newText*/)
+{
+// static const QRegExp re("\\b(AND|OR)\\b");
+// qDebug() << "new text:" << newText;
+// qDebug() << "contains:" << (newText.contains(re));
+// if (newText.isEmpty() || !newText.contains(re) ) {
+// qDebug()<< "no AND/OR";
+// if (!m_typeAndButton->isEnabled()) {
+// m_typeOrButton->setEnabled(true);
+// m_typeAndButton->setEnabled(true);
+// m_typeAndButton->setToolTip(tr("All of the words (AND is added between the words)"));
+// m_typeOrButton->setToolTip(tr("Some of the words"));
+// }
+// }
+// else {
+// qDebug("AND/OR!");
+// if (m_typeAndButton->isEnabled()) {
+// m_typeOrButton->setChecked(true);
+// m_typeOrButton->setEnabled(false);
+// m_typeAndButton->setEnabled(false);
+// m_typeAndButton->setToolTip(tr("Full syntax is used because text includes AND or OR"));
+// m_typeOrButton->setToolTip(tr("Full syntax is used because text includes AND or OR"));
+// }
+// }
+}
+
+//bool BtSearchOptionsArea::isAndSearchType()
+//{
+//
+//}
+
+
+}
diff --git a/src/frontend/searchdialog/btsearchoptionsarea.h b/src/frontend/searchdialog/btsearchoptionsarea.h
new file mode 100644
index 0000000..30f6654
--- /dev/null
+++ b/src/frontend/searchdialog/btsearchoptionsarea.h
@@ -0,0 +1,150 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTSEARCHOPTIONSAREA_H
+#define BTSEARCHOPTIONSAREA_H
+
+#include "chistorycombobox.h"
+
+#include "backend/keys/cswordversekey.h"
+
+#include <QWidget>
+
+class CSwordModuleInfo;
+
+class QGroupBox;
+class QGridLayout;
+class QHBoxLayout;
+class QLabel;
+class QPushButton;
+class QRadioButton;
+class QComboBox;
+class QObject;
+class QEvent;
+
+
+namespace Search {
+
+class BtSearchOptionsArea : public QWidget
+{
+ Q_OBJECT
+public:
+
+ enum SearchType {AndType, OrType, FullType};
+
+ friend class CSearchDialog;
+
+ BtSearchOptionsArea(QWidget *parent=0);
+ ~BtSearchOptionsArea();
+ /*
+ * Add text to search combox box history
+ */
+ void addToHistory(const QString& text);
+ /**
+ * Sets the search text used in the page.
+ */
+ void setSearchText(const QString& text);
+ /**
+ * Returns the search text set in this page.
+ */
+ QString searchText() const;
+
+ SearchType searchType();
+
+ QPushButton* searchButton() const;
+
+ /**
+ * Returns the list of used modules.
+ */
+ QList<CSwordModuleInfo*> modules() const;
+
+ /**
+ * Sets all options back to the default.
+ */
+ void reset();
+ /**
+ * Returns the selected search scope if a search scope was selected.
+ */
+ sword::ListKey searchScope();
+
+ bool hasSearchScope();
+
+
+protected:
+ /**
+ * Initializes this page.
+ */
+ void initView();
+ void initConnections();
+ /**
+ * Reads the settings of the last searchdialog session.
+ */
+ void readSettings();
+ /**
+ * Reads the settings for the searchdialog from disk.
+ */
+ void saveSettings();
+ bool eventFilter(QObject* obj, QEvent* event);
+public slots:
+ /**
+ * Sets the modules used by the search.
+ */
+ void setModules( QList<CSwordModuleInfo*> modules );
+
+ /** Sets the modules when user selects them from the combobox.*/
+ void moduleListTextSelected(int index);
+
+ /**
+ * Reimplementation.
+ */
+ void aboutToShow();
+ /**
+ * Refreshes the list of ranges and the range combobox.
+ */
+ void refreshRanges();
+ /**
+ * Opens the modules chooser dialog.
+ */
+ void chooseModules();
+
+protected slots:
+ void setupRanges();
+ void syntaxHelp();
+ void slotSearchTextEditReturnPressed();
+ void slotValidateText(const QString& newText);
+
+signals:
+ void sigSetSearchButtonStatus(bool);
+ void sigStartSearch();
+
+private:
+ QList<CSwordModuleInfo*> m_modules;
+
+ QHBoxLayout *hboxLayout;
+ QGroupBox *searchGroupBox;
+ QGridLayout *gridLayout;
+ QLabel *m_searchTextLabel;
+ QPushButton* m_searchButton;
+ QLabel* m_helpLabel;
+ QRadioButton* m_typeAndButton;
+ QRadioButton* m_typeOrButton;
+ QRadioButton* m_typeFreeButton;
+ QPushButton *m_chooseModulesButton;
+ QPushButton *m_chooseRangeButton;
+ QLabel *m_searchScopeLabel;
+ QComboBox *m_rangeChooserCombo;
+ CHistoryComboBox *m_searchTextCombo;
+ QLabel *m_modulesLabel;
+ QComboBox* m_modulesCombo;
+
+};
+
+}
+
+#endif
diff --git a/src/frontend/searchdialog/btsearchresultarea.cpp b/src/frontend/searchdialog/btsearchresultarea.cpp
new file mode 100644
index 0000000..585d5d3
--- /dev/null
+++ b/src/frontend/searchdialog/btsearchresultarea.cpp
@@ -0,0 +1,659 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btsearchresultarea.h"
+#include "cmoduleresultview.h"
+#include "csearchresultview.h"
+#include "csearchdialog.h"
+#include "frontend/searchdialog/analysis/csearchanalysisdialog.h"
+
+#include "util/ctoolclass.h"
+#include "frontend/display/cdisplay.h"
+#include "frontend/display/creaddisplay.h"
+#include "backend/rendering/cdisplayrendering.h"
+#include "backend/keys/cswordversekey.h"
+
+#include <QWidget>
+#include <QStringList>
+#include <QVBoxLayout>
+#include <QSize>
+#include <QSplitter>
+#include <QFrame>
+#include <QApplication>
+#include <QProgressDialog>
+#include <QPushButton>
+
+#include <QDebug>
+
+namespace Search {
+
+BtSearchResultArea::BtSearchResultArea(QWidget *parent)
+ : QWidget(parent)
+{
+ qDebug("BtSearchResultArea::BtSearchResultArea");
+ initView();
+ initConnections();
+ qDebug("BtSearchResultArea::BtSearchResultArea end");
+}
+
+BtSearchResultArea::~BtSearchResultArea()
+{
+ saveDialogSettings();
+}
+
+void BtSearchResultArea::initView()
+{
+ QVBoxLayout *mainLayout;
+ QWidget *resultListsWidget;
+ QVBoxLayout *resultListsWidgetLayout;
+
+ //Size is calculated from the font rather than set in pixels,
+ // maybe this is better in different kinds of displays?
+ int mWidth = CToolClass::mWidth(this, 1);
+ this->setMinimumSize(QSize(mWidth*40, mWidth*15));
+ mainLayout = new QVBoxLayout(this);
+ mainSplitter = new QSplitter(this);
+ mainSplitter->setOrientation(Qt::Horizontal);
+
+ resultListsWidget = new QWidget(mainSplitter);
+
+ resultListsWidgetLayout = new QVBoxLayout(resultListsWidget);
+ resultListsWidgetLayout->setContentsMargins(0, 0, 0, 0);
+
+ //Splitter for two result lists
+ resultListSplitter = new QSplitter(resultListsWidget);
+ resultListSplitter->setOrientation(Qt::Vertical);
+ m_moduleListBox = new CModuleResultView(resultListSplitter);
+ resultListSplitter->addWidget(m_moduleListBox);
+ m_resultListBox = new CSearchResultView(resultListSplitter);
+ resultListSplitter->addWidget(m_resultListBox);
+ resultListsWidgetLayout->addWidget(resultListSplitter);
+
+ mainSplitter->addWidget(resultListsWidget);
+
+ //Preview ("info") area
+ m_displayFrame = new QFrame(mainSplitter);
+ m_displayFrame->setFrameShape(QFrame::NoFrame);
+ m_displayFrame->setFrameShadow(QFrame::Plain);
+ mainSplitter->addWidget(m_displayFrame);
+
+ mainLayout->addWidget(mainSplitter);
+
+ QVBoxLayout* frameLayout = new QVBoxLayout(m_displayFrame);
+ frameLayout->setContentsMargins(0,0,0,0);
+ m_previewDisplay = CDisplay::createReadInstance(0, m_displayFrame);
+ m_previewDisplay->view()->setToolTip(tr("Text of the selected search result item"));
+ frameLayout->addWidget(m_previewDisplay->view());
+
+ loadDialogSettings();
+}
+
+void BtSearchResultArea::setSearchResult(QList<CSwordModuleInfo*> modules)
+{
+ const QString searchedText = CSearchDialog::getSearchDialog()->searchText();
+ reset(); //clear current modules
+
+ m_modules = modules;
+ //pre-select the first module in the list
+ //this will pre-select and display the first hit of that module
+ m_moduleListBox->setupTree(modules, searchedText);
+ m_moduleListBox->setCurrentItem(m_moduleListBox->topLevelItem(0), 0);
+
+ qobject_cast<CSearchDialog*>(parent())->m_analyseButton->setEnabled(true);
+}
+
+void BtSearchResultArea::reset()
+{
+ m_moduleListBox->clear();
+ m_resultListBox->clear();
+ m_previewDisplay->setText("<html><head/><body></body></html>");
+ qobject_cast<CSearchDialog*>(parent())->m_analyseButton->setEnabled(false);
+ m_modules.clear();
+}
+
+void BtSearchResultArea::clearPreview(){
+ m_previewDisplay->setText("<html><head/><body></body></html>");
+}
+
+void BtSearchResultArea::updatePreview(const QString& key)
+{
+ using namespace Rendering;
+
+ CSwordModuleInfo* module = m_moduleListBox->activeModule();
+ if ( module ) {
+ const QString searchedText = CSearchDialog::getSearchDialog()->searchText();
+
+ QString text;
+ CDisplayRendering render;
+
+ QList<CSwordModuleInfo*> modules;
+ modules.append(module);
+
+ CTextRendering::KeyTreeItem::Settings settings;
+
+ //for bibles render 5 context verses
+ if (module->type() == CSwordModuleInfo::Bible) {
+ CSwordVerseKey vk(module);
+ vk.Headings(1);
+ vk.key(key);
+
+ ((sword::VerseKey*)(module->module()->getKey()))->Headings(1); //HACK: enable headings for VerseKeys
+
+ //first go back and then go forward the keys to be in context
+ vk.previous(CSwordVerseKey::UseVerse);
+ vk.previous(CSwordVerseKey::UseVerse);
+
+ //include Headings in display, they are indexed and searched too
+ if (vk.Verse() == 1){
+ if (vk.Chapter() == 1){
+ vk.Chapter(0);
+ }
+ vk.Verse(0);
+ }
+
+ const QString startKey = vk.key();
+
+ vk.key(key);
+
+ vk.next(CSwordVerseKey::UseVerse);
+ vk.next(CSwordVerseKey::UseVerse);
+ const QString endKey = vk.key();
+
+ settings.keyRenderingFace = CTextRendering::KeyTreeItem::Settings::CompleteShort;
+ text = render.renderKeyRange(startKey, endKey, modules, key, settings);
+ }
+ //for commentaries only one verse, but with heading
+ else if (module->type() == CSwordModuleInfo::Commentary) {
+ CSwordVerseKey vk(module);
+ vk.Headings(1);
+ vk.key(key);
+
+ ((sword::VerseKey*)(module->module()->getKey()))->Headings(1); //HACK: enable headings for VerseKeys
+
+ //include Headings in display, they are indexed and searched too
+ if (vk.Verse() == 1){
+ if (vk.Chapter() == 1){
+ vk.Chapter(0);
+ }
+ vk.Verse(0);
+ }
+ const QString startKey = vk.key();
+
+ vk.key(key);
+ const QString endKey = vk.key();
+
+ settings.keyRenderingFace = CTextRendering::KeyTreeItem::Settings::NoKey;
+ text = render.renderKeyRange(startKey, endKey, modules, key, settings);
+ }
+ else {
+ text = render.renderSingleKey(key, modules, settings);
+ }
+
+ m_previewDisplay->setText( highlightSearchedText(text, searchedText) );
+ m_previewDisplay->moveToAnchor( CDisplayRendering::keyToHTMLAnchor(key) );
+ }
+}
+
+QStringList BtSearchResultArea::QueryParser(const QString& queryString) {
+ QString token;
+ QStringList tokenList;
+ int cnt, pos;
+
+ token = "";
+ cnt = 0;
+ while(cnt < queryString.length()) {
+ // add to token
+ if ((queryString[cnt]).isLetterOrNumber() || (queryString[cnt] == '*')) {
+ token = token + queryString[cnt];
+ cnt++;
+ }
+ // token break
+ else if (queryString[cnt] == ' ') {
+ token = token.simplified();
+ if ((token != "*") && (token != ""))
+ tokenList.append(token);
+ token = "";
+ cnt++;
+ }
+ // clucene appears to ignore quoted strings in the sence
+ // that it treats all the words within quoted strings as
+ // regular tokens and not as a single token.
+ else if (queryString[cnt] == '"') {
+ cnt++;
+ }
+ // wild card - treat as a special token break
+ //else if (queryString[cnt] == '*') {
+ // token = token + queryString[cnt];
+ // token = token.simplified();
+ // if ((token != "*") && (token != ""))
+ // tokenList.append(token);
+ // // start next token with wildcard (kin*m -> kin* *m)
+ // token = "*";
+ // cnt++;
+ //}
+ // the ! token is also a token break
+ else if (queryString[cnt] == '!') {
+ // store away current token
+ token = token.simplified();
+ if ((token != "*") && (token != ""))
+ tokenList.append(token);
+ // add the ! token
+ tokenList.append("!");
+ token = "";
+ cnt++;
+ }
+ // the - token is also a token break
+ else if (queryString[cnt] == '-') {
+ // store away current token
+ token = token.simplified();
+ if ((token != "*") && (token != ""))
+ tokenList.append(token);
+ // add the ! token
+ tokenList.append("-");
+ token = "";
+ cnt++;
+ }
+ // the + token is also a token break
+ else if (queryString[cnt] == '+') {
+ // store away current token
+ token = token.simplified();
+ if ((token != "*") && (token != ""))
+ tokenList.append(token);
+ // add the + token
+ tokenList.append("+");
+ token = "";
+ cnt++;
+ }
+ // the || token is also a token break
+ else if ((queryString[cnt] == '|') && (queryString[cnt+1] == '|')) {
+ // store away current token
+ token = token.simplified();
+ if ((token != "*") && (token != ""))
+ tokenList.append(token);
+ // add the || token
+ tokenList.append("||");
+ token = "";
+ cnt += 2;
+ }
+ // the && token is also a token break
+ else if ((queryString[cnt] == '&') && (queryString[cnt+1] == '&')) {
+ // store away current token
+ token = token.simplified();
+ if ((token != "*") && (token != ""))
+ tokenList.append(token);
+ // add the || token
+ tokenList.append("&&");
+ token = "";
+ cnt += 2;
+ }
+ else cnt++;
+ }
+ token = token.simplified();
+ if ((token != "*") && (token != ""))
+ tokenList.append(token);
+
+ cnt = 0;
+ QStringList::iterator it;
+ for ( it = tokenList.begin(); it != tokenList.end(); it++ ) {
+ //-----------------------------------------------------------
+ // remove all the NOT(!) tokens - these do not need to be
+ // highlighted in the highlighter
+ //-----------------------------------------------------------
+ if (((*it) == "!") || ((*it) == "NOT") || ((*it) == "-")) {
+ it = tokenList.erase(it);
+ if (it == tokenList.end())
+ break;
+ it = tokenList.erase(it);
+ if (it == tokenList.end())
+ break;
+ it--;
+ }
+ //-----------------------------------------------------------
+ // remove all the operator tokens - these do not need to be
+ // highlighted in the highlighter
+ //-----------------------------------------------------------
+ else if ( ((*it) == "||") || ((*it) == "OR") || ((*it) == "+") ||
+ ((*it) == "AND") || ((*it) == "&&") )
+ {
+ it = tokenList.erase(it);
+ if (it == tokenList.end())
+ break;
+ it--;
+ }
+ // if the token contains a ^ then trim the remainder of the
+ // token from the ^
+ //What??? error: invalid conversion from ‘const void*’ to ‘int’
+ // and how come "contains" returns bool but is used as int?
+ //else if ( (pos = (*it).contains("^")) >= 0 ) {
+ else if ( (pos = (*it).indexOf("^") ) >= 0 ) {
+ (*it) = (*it).left(pos - 1);
+ }
+ // if the token contains a ~ then trim the remainder of the
+ // token from the ~
+ else if ( (pos = (*it).indexOf("~") ) >= 0 ) {
+ (*it) = (*it).left(pos - 2) + "*";
+ }
+ }
+ return(tokenList);
+}
+
+QString BtSearchResultArea::highlightSearchedText(const QString& content, const QString& searchedText) {
+ QString ret = content;
+
+ const Qt::CaseSensitivity cs = Qt::CaseInsensitive;
+
+ // int index = 0;
+ int index = ret.indexOf("<body", 0);
+ int matchLen = 0;
+ int length = searchedText.length();
+
+ // Highlighting constants -
+ // TODO: We need to make the highlight color configurable.
+ const QString rep1("<span style=\"background-color:#FFFF66;\">");
+ const QString rep2("</span>");
+ const unsigned int repLength = rep1.length() + rep1.length();
+ const QString rep3("style=\"background-color:#FFFF66;\" ");
+ const unsigned int rep3Length = rep3.length();
+
+
+ QString newSearchText;
+
+ newSearchText = searchedText;
+
+ // find the strongs search lemma and highlight it
+ // search the searched text for "strong:" until it is not found anymore
+ QStringList list;
+
+ // split the search string - some possibilities are "\\s|\\|", "\\s|\\+", or "\\s|\\|\\+"
+ // TODO: find all possible seperators
+ QString regExp = "\\s";
+ list = searchedText.split(QRegExp(regExp));
+ foreach (QString newSearchText, list) {
+ int sstIndex; // strong search text index for finding "strong:"
+ int idx1, idx2;
+ QString sNumber, lemmaText;
+
+ sstIndex = newSearchText.indexOf("strong:");
+ if (sstIndex == -1)
+ continue;
+
+ // set the start index to the start of <body>
+ int strongIndex = index;
+
+ // Get the strongs number from the search text.
+ // First, find the first space after "strong:"
+ sstIndex = sstIndex + 7;
+ // get the strongs number -> the text following "strong:" to the end of the string.
+ sNumber = newSearchText.mid(sstIndex, -1);
+ // find all the "lemma=" inside the the content
+ while((strongIndex = ret.indexOf("lemma=", strongIndex, cs)) != -1) {
+ // get the strongs number after the lemma and compare it with the
+ // strongs number we are looking for
+ idx1 = ret.indexOf("\"", strongIndex) + 1;
+ idx2 = ret.indexOf("\"", idx1 + 1);
+ lemmaText = ret.mid(idx1, idx2 - idx1);
+
+ // this is interesting because we could have a strongs number like: G3218|G300
+ // To handle this we will use some extra cpu cycles and do a partial match against
+ // the lemmaText
+ if (lemmaText.contains(sNumber)) {
+ // strongs number is found now we need to highlight it
+ // I believe the easiest way is to insert rep3 just before "lemma="
+ ret = ret.insert(strongIndex, rep3);
+ strongIndex += rep3Length;
+ }
+ strongIndex += 6; // 6 is the length of "lemma="
+ }
+ }
+ //---------------------------------------------------------------------
+ // now that the strong: stuff is out of the way continue with
+ // other search options
+ //---------------------------------------------------------------------
+
+ // try to figure out how to use the lucene query parser
+
+ //using namespace lucene::queryParser;
+ //using namespace lucene::search;
+ //using namespace lucene::analysis;
+ //using namespace lucene::util;
+
+ //wchar_t *buf;
+ //char buf8[1000];
+ //standard::WhitespaceAnalyzer analyzer;
+ //lucene_utf8towcs(m_wcharBuffer, searchedText.utf8(), MAX_CONV_SIZE);
+ //boost::scoped_ptr<Query> q( QueryParser::parse(m_wcharBuffer, _T("content"), &analyzer) );
+ //StringReader reader(m_wcharBuffer);
+ //TokenStream* tokenStream = analyzer.tokenStream( _T("field"), &reader);
+ //Token token;
+ //while(tokenStream->next(&token) != 0) {
+ // lucene_wcstoutf8(buf8, token.termText(), 1000);
+ // printf("%s\n", buf8);
+ //}
+
+ //===========================================================
+ // since I could not figure out the lucene query parser, I
+ // made a simple parser.
+ //===========================================================
+ QStringList words = QueryParser(newSearchText);
+ foreach (QString word, words) { //search for every word in the list
+ QRegExp findExp;
+ if (word.contains("*")) {
+ length = word.length() - 1;
+ word.replace('*', "\\S*"); //match within a word
+ findExp = QRegExp(word);
+ findExp.setMinimal(TRUE);
+ }
+ else {
+ length = word.length();
+ findExp = QRegExp("\\b" + word + "\\b");
+ }
+
+ // index = 0; //for every word start at the beginning
+ index = ret.indexOf("<body", 0);
+ findExp.setCaseSensitivity(cs);
+ //while ( (index = ret.find(findExp, index)) != -1 ) { //while we found the word
+ while ( (index = findExp.indexIn(ret, index)) != -1 ) { //while we found the word
+ matchLen = findExp.matchedLength();
+ if (!CToolClass::inHTMLTag(index, ret)) {
+ length = matchLen;
+ ret = ret.insert( index+length, rep2 );
+ ret = ret.insert( index, rep1 );
+ index += repLength;
+ }
+ index += length;
+ }
+ }
+ //qWarning("\n\n\n%s", ret.latin1());
+ return ret;
+}
+
+/** Initializes the signal slot conections of the child widgets, */
+void BtSearchResultArea::initConnections()
+{
+ connect(m_resultListBox, SIGNAL(keySelected(const QString&)), this, SLOT(updatePreview(const QString&)));
+ connect(m_resultListBox, SIGNAL(keyDeselected()), this, SLOT(clearPreview()));
+ connect(m_moduleListBox, SIGNAL(moduleSelected(CSwordModuleInfo*)), m_resultListBox, SLOT(setupTree(CSwordModuleInfo*)));
+ connect(m_moduleListBox, SIGNAL(moduleChanged()), m_previewDisplay->connectionsProxy(), SLOT(clear()));
+
+ // connect the strongs list
+ connect(m_moduleListBox, SIGNAL(strongsSelected(CSwordModuleInfo*, QStringList*)),
+ m_resultListBox, SLOT(setupStrongsTree(CSwordModuleInfo*, QStringList*)));
+}
+
+/** Shows a dialog with the search analysis of the current search. */
+void BtSearchResultArea::showAnalysis() {
+ CSearchAnalysisDialog dlg(m_modules, this);
+ dlg.exec();
+}
+
+/**
+* Load the settings from the resource file
+*/
+void BtSearchResultArea::loadDialogSettings()
+{
+ QList<int> mainSplitterSizes = CBTConfig::get(CBTConfig::searchMainSplitterSizes);
+ if (mainSplitterSizes.count() > 0) {
+ mainSplitter->setSizes(mainSplitterSizes);
+ } else {
+ int w = this->size().width();
+ int w2 = m_moduleListBox->sizeHint().width();
+ mainSplitterSizes << w2 << w - w2;
+ mainSplitter->setSizes(mainSplitterSizes);
+ }
+ QList<int> resultSplitterSizes = CBTConfig::get(CBTConfig::searchResultSplitterSizes);
+ if (resultSplitterSizes.count() > 0) resultListSplitter->setSizes(resultSplitterSizes);
+}
+
+/**
+* Save the settings to the resource file
+*/
+void BtSearchResultArea::saveDialogSettings()
+{
+ CBTConfig::set(CBTConfig::searchMainSplitterSizes, mainSplitter->sizes());
+ CBTConfig::set(CBTConfig::searchResultSplitterSizes, resultListSplitter->sizes());
+}
+
+StrongsResult::StrongsResult()
+{
+}
+
+StrongsResult::StrongsResult(const QString& text, const QString &keyName)
+ : text(text)
+{
+ //keyNameList.clear();
+ keyNameList.append(keyName);
+}
+
+QString StrongsResult::keyText() const {
+ return text;
+}
+
+int StrongsResult::keyCount() const {
+ return keyNameList.count();
+}
+
+void StrongsResult::addKeyName(const QString& keyName) {
+ if (keyNameList.indexOf(keyName) == -1)
+ keyNameList.append(keyName);
+}
+
+QStringList* StrongsResult::getKeyList() {
+ return & keyNameList;
+}
+
+
+
+/********************************************
+************ StrongsResultClass *************
+********************************************/
+void StrongsResultClass::initStrongsResults(void)
+{
+ using namespace Rendering;
+
+ CDisplayRendering render;
+ QList<CSwordModuleInfo*> modules;
+ CTextRendering::KeyTreeItem::Settings settings;
+ QString rText, lText, key;
+ bool found;
+ int sIndex;
+ int count;
+ int index;
+ QString text;
+
+ modules.append(srModule);
+ sword::ListKey& result = srModule->searchResult();
+
+ count = result.Count();
+ if (!count)
+ return;
+ qApp->processEvents( QEventLoop::AllEvents, 1 ); //1 ms only
+ srList.clear();
+ // for whatever reason the text "Parsing...translations." does not appear.
+ // this is not critical but the text is necessary to get the dialog box
+ // to be wide enough.
+ QProgressDialog* progress = new QProgressDialog(QObject::tr("Parsing Strong's Numbers"), 0, 0, count);
+ //0, "progressDialog", tr("Parsing Strong's Numbers"), tr("Parsing Strong's numbers for translations."), true);
+
+ //progress->setAllowCancel(false);
+ //progress->setMinimumDuration(0);
+ progress->show();
+ progress->raise();
+ for (index = 0; index < count; index++){
+ progress->setValue( index );
+ qApp->processEvents(QEventLoop::AllEvents, 1 ); //1 ms only
+
+ key = QString::fromUtf8(result.GetElement(index)->getText());
+ text = render.renderSingleKey(key, modules, settings);
+ sIndex = 0;
+ while ((rText = getStrongsNumberText(text, &sIndex)) != "")
+ {
+ StrongsResultList::iterator it;
+ found = FALSE;
+ for ( it = srList.begin(); it != srList.end(); ++it )
+ {
+ lText = (*it).keyText();
+ if (lText == rText)
+ {
+ found = TRUE;
+ (*it).addKeyName(key);
+ break;
+ }
+ }
+ if (found == FALSE)
+ srList.append( StrongsResult(rText, key) );
+ }
+ }
+ delete progress;
+ progress = 0;
+ //qHeapSort(srList);
+}
+
+QString StrongsResultClass::getStrongsNumberText(const QString& verseContent, int *startIndex) {
+ // get the strongs text
+ int idx1, idx2, index;
+ QString sNumber, strongsText;
+ //const bool cs = CSwordModuleSearch::caseSensitive;
+ const Qt::CaseSensitivity cs = Qt::CaseInsensitive;
+
+ if (*startIndex == 0) {
+ index = verseContent.indexOf("<body");
+ }
+ else {
+ index = *startIndex;
+ }
+
+ // find all the "lemma=" inside the the content
+ while((index = verseContent.indexOf("lemma=", index, cs)) != -1) {
+ // get the strongs number after the lemma and compare it with the
+ // strongs number we are looking for
+ idx1 = verseContent.indexOf("\"", index) + 1;
+ idx2 = verseContent.indexOf("\"", idx1 + 1);
+ sNumber = verseContent.mid(idx1, idx2 - idx1);
+ if (sNumber == lemmaText) {
+ // strongs number is found now we need to get the text of this node
+ // search right until the ">" is found. Get the text from here to
+ // the next "<".
+ index = verseContent.indexOf(">", index, cs) + 1;
+ idx2 = verseContent.indexOf("<", index, cs);
+ strongsText = verseContent.mid(index, idx2 - index);
+ index = idx2;
+ *startIndex = index;
+
+ return(strongsText);
+ }
+ else {
+ index += 6; // 6 is the length of "lemma="
+ }
+ }
+ return QString::null;
+}
+
+
+
+} //namespace Search
diff --git a/src/frontend/searchdialog/btsearchresultarea.h b/src/frontend/searchdialog/btsearchresultarea.h
new file mode 100644
index 0000000..82eb2d4
--- /dev/null
+++ b/src/frontend/searchdialog/btsearchresultarea.h
@@ -0,0 +1,201 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTSEARCHRESULTAREA_H
+#define BTSEARCHRESULTAREA_H
+
+
+#include "backend/managers/cswordbackend.h"
+#include "backend/cswordmodulesearch.h"
+
+#include <QSplitter>
+#include <QList>
+#include <QStringList>
+#include <QWidget>
+
+//forward declarations
+class CReadDisplay;
+class CSwordModuleInfo;
+namespace Search {
+ class CModuleResultView;
+ class CSearchResultView;
+}
+
+class QHBoxLayout;
+class QTreeWidget;
+class QFrame;
+
+namespace Search {
+
+/**
+* This class is used to keep track of the text strongs results.
+* It only keeps track of one instance of a strongs text result.
+*
+* The functions of the class are:
+* - Store an instance of a strongs text result.
+* - Each strongs text result will contain a list of verses (keyNames).
+* - The number of verses (keyNames) is returned by keyCount().
+* - The text for the strongs text result is returned by keyText().
+* - The list of verses (keyNames) is returned by getKeyList() [as QStringList].
+*
+* To add a new verse to a strongs text result use addKeyName.
+*/
+class StrongsResult {
+public:
+ StrongsResult();
+ StrongsResult(const QString& text, const QString &keyName);
+
+ QString keyText() const;
+ int keyCount() const;
+ void addKeyName(const QString& keyName);
+ QStringList* getKeyList();
+
+ /* ????
+ bool operator==(const StrongsResult &l, const StrongsResult &r)
+ { return (l.keyText() == r.keyText()); }
+
+ bool operator<(const StrongsResult &l, const StrongsResult &r)
+ { return (l->keyText() < r->keyText()); }
+
+ bool operator>(const StrongsResult &l, const StrongsResult &r)
+ { return (l->keyText() > r->keyText()); }
+ */
+private:
+ QString text;
+ QStringList keyNameList;
+};
+
+typedef QList<StrongsResult> StrongsResultList;
+
+/**
+* This class is used to keep track of the text strongs results.
+* It keeps track of all instances of all strongs text results.
+* This class makes use of the above class StrongsResult.
+*
+* The functions of the class are:
+* - Store an instance of a strongs text result.
+* - Each strongs text result will contain a list of verses (keyNames).
+* - The number of verses (keyNames) is returned by keyCount().
+* - The text for the strongs text result is returned by keyText().
+* - The list of verses (keyNames) is returned by getKeyList() [as QStringList].
+*
+* To add a new verse to a strongs text result use addKeyName.
+*/
+class StrongsResultClass {
+public:
+ StrongsResultClass(CSwordModuleInfo* module, const QString& strongsNumber)
+ : srModule(module), lemmaText(strongsNumber)
+ {
+ initStrongsResults();
+ }
+
+ QString keyText(int index) const {
+ return srList[index].keyText();
+ }
+ int keyCount(int index) const {
+ return srList[index].keyCount();
+ }
+ QStringList* getKeyList(int index) {
+ return srList[index].getKeyList();
+ }
+ int Count() const {
+ return srList.count();
+ }
+
+private:
+ void initStrongsResults(void);
+ QString getStrongsNumberText(const QString& verseContent, int *startIndex);
+
+ StrongsResultList srList;
+ CSwordModuleInfo* srModule;
+ QString lemmaText;
+};
+
+
+/** The page of the search dialog which contains the search result part.
+ * @author The BibleTime team
+ */
+class BtSearchResultArea : public QWidget
+{
+ Q_OBJECT
+public:
+ BtSearchResultArea(QWidget *parent=0);
+ ~BtSearchResultArea();
+ /**
+ * Sets the modules which contain the result of each.
+ */
+ void setSearchResult(QList<CSwordModuleInfo*> modules);
+
+ QSize sizeHint() const { return baseSize(); }
+ QSize minimumSizeHint() const { return minimumSize(); }
+
+public slots:
+ /**
+ * Resets the current list of modules and the displayed list of found entries.
+ */
+ void reset();
+
+protected:
+ /**
+ * Initializes the view of this widget.
+ */
+ void initView();
+ /**
+ * Initializes the signal slot conections of the child widgets
+ */
+ void initConnections();
+ /**
+ * This function breakes the queryString into clucene tokens
+ */
+ QStringList QueryParser(const QString& queryString);
+ /**
+ * This function highlights the searched text in the content using the search type given by search flags
+ */
+ QString highlightSearchedText(const QString& content, const QString& searchedText);
+
+ /**
+ * Load the settings from the resource file
+ */
+ void loadDialogSettings();
+ /**
+ * Save the settings to the resource file
+ */
+ void saveDialogSettings();
+
+protected slots:
+ /**
+ * Update the preview of the selected key.
+ */
+ void updatePreview(const QString& key);
+ /**
+ * Clear the preview of the selected key.
+ */
+ void clearPreview();
+ /**
+ * Shows a dialog with the search analysis of the current search.
+ */
+ void showAnalysis();
+
+private:
+
+ CModuleResultView* m_moduleListBox;
+ CSearchResultView* m_resultListBox;
+
+ QFrame *m_displayFrame;
+ CReadDisplay* m_previewDisplay;
+
+ QList<CSwordModuleInfo*> m_modules;
+
+ QSplitter *mainSplitter;
+ QSplitter *resultListSplitter;
+};
+
+} //namespace Search
+
+#endif
diff --git a/src/frontend/searchdialog/chistorycombobox.cpp b/src/frontend/searchdialog/chistorycombobox.cpp
new file mode 100644
index 0000000..953d9f3
--- /dev/null
+++ b/src/frontend/searchdialog/chistorycombobox.cpp
@@ -0,0 +1,48 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "chistorycombobox.h"
+#include <QString>
+#include <QCompleter>
+
+namespace Search {
+
+CHistoryComboBox::CHistoryComboBox( QWidget* parent)
+ : QComboBox(parent)
+{
+ setEditable(true);
+ completer()->setCompletionMode(QCompleter::PopupCompletion);
+}
+
+CHistoryComboBox::~CHistoryComboBox()
+{
+}
+
+void CHistoryComboBox::addToHistory(const QString& text)
+{
+ int index = findText(text);
+ if ( index >= 0)
+ removeItem(index);
+ insertItem(1, text);
+ setCurrentIndex(1);
+}
+
+QStringList CHistoryComboBox::historyItems() const
+{
+ QStringList items;
+ for (int i=0; i<count(); i++)
+ {
+ QString text = itemText(i);
+ if (text.size() > 0)
+ items << text;
+ }
+ return items;
+}
+} //end of namespace Search
+
diff --git a/src/frontend/searchdialog/chistorycombobox.h b/src/frontend/searchdialog/chistorycombobox.h
new file mode 100644
index 0000000..967c045
--- /dev/null
+++ b/src/frontend/searchdialog/chistorycombobox.h
@@ -0,0 +1,33 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CHISTORYCOMBOBOX_H
+#define CHISTORYCOMBOBOX_H
+
+#include <QComboBox>
+
+namespace Search {
+
+class CHistoryComboBox : public QComboBox
+{
+ Q_OBJECT
+public:
+ CHistoryComboBox(QWidget* parent = 0);
+ ~CHistoryComboBox();
+ void addToHistory(const QString& item);
+ QStringList historyItems() const;
+
+protected:
+
+private:
+};
+
+} //end of namespace Search
+
+#endif
diff --git a/src/frontend/searchdialog/cmoduleresultview.cpp b/src/frontend/searchdialog/cmoduleresultview.cpp
new file mode 100644
index 0000000..6c3053f
--- /dev/null
+++ b/src/frontend/searchdialog/cmoduleresultview.cpp
@@ -0,0 +1,297 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#include "cmoduleresultview.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+
+#include "frontend/cexportmanager.h"
+
+#include "util/cresmgr.h"
+#include "util/ctoolclass.h"
+#include "util/directoryutil.h"
+
+//Qt includes
+#include <QTreeWidget>
+#include <QAction>
+#include <QStringList>
+#include <QMenu>
+#include <QContextMenuEvent>
+#include <QHeaderView>
+
+namespace Search {
+
+
+/********************************************
+************ ModuleResultList **************
+********************************************/
+
+CModuleResultView::CModuleResultView(QWidget* parent)
+ : QTreeWidget(parent),
+ strongsResults(0)
+{
+ initView();
+ initConnections();
+}
+
+CModuleResultView::~CModuleResultView()
+{}
+
+
+/** Initializes this widget. */
+void CModuleResultView::initView()
+{
+ // see also csearchresultview.cpp
+ setToolTip(tr("Works chosen for the search and the number of the hits in each work"));
+ setHeaderLabels( QStringList(tr("Work")) << tr("Hits") );
+
+ setColumnWidth(0, CToolClass::mWidth(this, 8));
+ setColumnWidth(1, CToolClass::mWidth(this, 4));
+ QSize sz(CToolClass::mWidth(this, 13), CToolClass::mWidth(this, 5));
+ //setMinimumSize(sz);
+ m_size = sz;
+ //TODO: sorting
+ //setSorting(0, true);
+ //setSorting(1, true);
+
+ //setup the popup menu
+ m_popup = new QMenu(this);
+
+ m_actions.copyMenu = new QMenu(tr("Copy..."), m_popup);
+ m_actions.copyMenu->setIcon(util::filesystem::DirectoryUtil::getIcon( CResMgr::searchdialog::result::moduleList::copyMenu::icon) );
+ m_actions.copy.result = new QAction(tr("Reference only"), this);
+ QObject::connect(m_actions.copy.result, SIGNAL(triggered()), this, SLOT(copyResult()) );
+ m_actions.copyMenu->addAction(m_actions.copy.result);
+ m_actions.copy.resultWithText = new QAction(tr("Reference with text"), this);
+ QObject::connect(m_actions.copy.resultWithText, SIGNAL(triggered()), this, SLOT(copyResultWithText()) );
+ m_actions.copyMenu->addAction(m_actions.copy.resultWithText);
+ m_popup->addMenu(m_actions.copyMenu);
+
+ m_actions.saveMenu = new QMenu(tr("Save..."), m_popup);
+ m_actions.saveMenu->setIcon(util::filesystem::DirectoryUtil::getIcon( CResMgr::searchdialog::result::moduleList::saveMenu::icon) );
+ m_actions.save.result = new QAction(tr("Reference only"), this);
+ QObject::connect(m_actions.save.result, SIGNAL(triggered()), this, SLOT(saveResult()) );
+ m_actions.saveMenu->addAction(m_actions.save.result);
+ m_actions.save.resultWithText = new QAction(tr("Reference with text"), this);
+ QObject::connect(m_actions.save.resultWithText, SIGNAL(triggered()), this, SLOT(saveResultWithText()) );
+ m_actions.saveMenu->addAction(m_actions.save.resultWithText);
+ m_popup->addMenu(m_actions.saveMenu);
+
+ m_actions.printMenu = new QMenu(tr("Print..."), m_popup);
+ m_actions.printMenu->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::result::moduleList::printMenu::icon));
+ m_actions.print.result = new QAction(tr("Reference with text"), this);
+ QObject::connect(m_actions.print.result, SIGNAL(triggered()), this, SLOT(printResult()) );
+ m_actions.printMenu->addAction(m_actions.print.result);
+ m_popup->addMenu(m_actions.printMenu);
+}
+
+/** Initializes the connections of this widget, */
+void CModuleResultView::initConnections()
+{
+ //TODO:
+ connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
+ this, SLOT(executed(QTreeWidgetItem*, QTreeWidgetItem*)));
+}
+
+/** Setups the tree using the given list of modules. */
+void CModuleResultView::setupTree( QList<CSwordModuleInfo*> modules, const QString& searchedText )
+{
+ clear();
+ //TODO: this class is for sorting
+ //util::CSortListViewItem* item = 0;
+ //util::CSortListViewItem* oldItem = 0;
+ QTreeWidgetItem* item = 0;
+ QTreeWidgetItem* oldItem = 0;
+
+ sword::ListKey result;
+
+ if (strongsResults) {
+ delete strongsResults;
+ strongsResults = 0;
+ }
+
+ bool strongsAvailable = false;
+
+ QList<CSwordModuleInfo*>::iterator end_it = modules.end();
+ for (QList<CSwordModuleInfo*>::iterator it(modules.begin()); it != end_it; ++it) {
+ // for (modules.first(); modules.current(); modules.next()) {
+ result = (*it)->searchResult();
+
+ item = new QTreeWidgetItem(this, QStringList((*it)->name()) << QString::number(result.Count()) );
+ //TODO: item->setColumnSorting(1, util::CSortListViewItem::Number);
+
+ item->setIcon(0,CToolClass::getIconForModule(*it) );
+ oldItem = item;
+ //----------------------------------------------------------------------
+ // we need to make a decision here. Either don't show any Strong's
+ // number translations, or show the first one in the search text, or
+ // figure out how to show them all.
+ // I choose option number 2 at this time.
+ //----------------------------------------------------------------------
+ int sstIndex, sTokenIndex; // strong search text index for finding "strong:"
+ if ((sstIndex = searchedText.indexOf("strong:", 0)) != -1) {
+ QString sNumber;
+ //--------------------------------------------------
+ // get the strongs number from the search text
+ //--------------------------------------------------
+ // first find the first space after "strong:"
+ // this should indicate a change in search token
+ sstIndex = sstIndex + 7;
+ sTokenIndex = searchedText.indexOf(" ", sstIndex);
+ sNumber = searchedText.mid(sstIndex, sTokenIndex - sstIndex);
+
+ setupStrongsResults((*it), item, sNumber);
+
+ //TODO: item->setOpen(true);
+ strongsAvailable = true;
+ }
+ };
+
+ //Allow to hide the module strongs if there are any available
+ setRootIsDecorated( strongsAvailable );
+}
+
+void CModuleResultView::setupStrongsResults(CSwordModuleInfo* module, QTreeWidgetItem* parent,
+ const QString& sNumber)
+{
+ QString lText;
+ //TODO:
+ //util::CSortListViewItem* item = 0;
+ QTreeWidgetItem* item = 0;
+
+ strongsResults = new StrongsResultClass(module, sNumber);
+
+ for (int cnt = 0; cnt < strongsResults->Count(); ++cnt) {
+ lText = strongsResults->keyText(cnt);
+
+ item = new QTreeWidgetItem(parent, QStringList(lText) << QString::number(strongsResults->keyCount(cnt)));
+ //TODO:
+ //item->setColumnSorting(1, util::CSortListViewItem::Number);
+ }
+}
+
+//TODO:
+/** Is executed when an item was selected in the list. */
+void CModuleResultView::executed( QTreeWidgetItem* i, QTreeWidgetItem*)
+{
+ QString itemText, lText;
+
+ if (!i){
+ //Clear list
+ emit moduleChanged();
+ return;
+ }
+ if (CSwordModuleInfo* m = CPointers::backend()->findModuleByName(i->text(0))) {
+ emit moduleChanged();
+ emit moduleSelected(m);
+ return;
+ }
+
+ if (!strongsResults) {
+ return;
+ }
+
+ itemText = i->text(0);
+ for (int cnt = 0; cnt < strongsResults->Count(); cnt++) {
+ lText = strongsResults->keyText(cnt);
+ if (lText == itemText) {
+ //clear the verses list
+ emit moduleChanged();
+ emit strongsSelected(activeModule(), strongsResults->getKeyList(cnt));
+ return;
+ }
+ }
+}
+
+/** Returns the currently active module. */
+CSwordModuleInfo* CModuleResultView::activeModule()
+{
+ Q_ASSERT(currentItem());
+
+ QTreeWidgetItem* item = currentItem();
+ if (!item) {
+ return 0;
+ }
+
+ // we need to find the parent most node because that is the node
+ // that is the module name.
+ while (item->parent()) {
+ item = item->parent();
+ }
+
+ if (item) {
+ return CPointers::backend()->findModuleByName(item->text(0));
+ }
+
+ return 0;
+}
+
+/** Reimplementation from QWidget. */
+void CModuleResultView::contextMenuEvent( QContextMenuEvent * event )
+{
+ qDebug("CModuleResultView::showPopup");
+ //make sure that all entries have the correct status
+ m_popup->exec(event->globalPos());
+}
+
+/** Copies the whole search result into the clipboard. */
+void CModuleResultView::copyResult()
+{
+ if (CSwordModuleInfo* m = activeModule()) {
+ sword::ListKey result = m->searchResult();
+ CExportManager mgr(tr("Copy search result..."), true, tr("Copying search result"));
+ mgr.copyKeyList(&result,m,CExportManager::Text,false);
+ };
+}
+
+/** Copies the whole search result with the text into the clipboard. */
+void CModuleResultView::copyResultWithText()
+{
+ if (CSwordModuleInfo* m = activeModule()) {
+ sword::ListKey result = m->searchResult();
+ CExportManager mgr(tr("Copy search result..."), true, tr("Copying search result"));
+ mgr.copyKeyList(&result,m,CExportManager::Text,true);
+ };
+}
+
+/** Saves the search result keys. */
+void CModuleResultView::saveResult()
+{
+ if (CSwordModuleInfo* m = activeModule()) {
+ sword::ListKey result = m->searchResult();
+ CExportManager mgr(tr("Save search result..."), true, tr("Saving search result"));
+ mgr.saveKeyList(&result,m,CExportManager::Text,false);
+ };
+}
+
+/** Saves the search result with it's text. */
+void CModuleResultView::saveResultWithText()
+{
+ if (CSwordModuleInfo* m = activeModule()) {
+ sword::ListKey result = m->searchResult();
+ CExportManager mgr(tr("Save search result..."), true, tr("Saving search result"));
+ mgr.saveKeyList(&result,m,CExportManager::Text,true);
+ };
+}
+
+/** Appends the whole search result to the printer queue. */
+void CModuleResultView::printResult()
+{
+ if (CSwordModuleInfo* m = activeModule()) {
+ sword::ListKey result = m->searchResult();
+ CExportManager mgr(tr("Print search result..."), true, tr("Printing search result"));
+ mgr.printKeyList(&result,m,CBTConfig::getDisplayOptionDefaults(), CBTConfig::getFilterOptionDefaults());
+ };
+}
+
+
+
+} //end of namespace Search
diff --git a/src/frontend/searchdialog/cmoduleresultview.h b/src/frontend/searchdialog/cmoduleresultview.h
new file mode 100644
index 0000000..c23d254
--- /dev/null
+++ b/src/frontend/searchdialog/cmoduleresultview.h
@@ -0,0 +1,136 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CMODULERESULTSVIEW_H
+#define CMODULERESULTSVIEW_H
+
+//BibleTime includes
+#include "btsearchresultarea.h"
+
+//Qt includes
+#include <QLabel>
+#include <QTreeWidget>
+
+
+//forward declarations
+class CSwordModuleInfo;
+
+class QPoint;
+class QMenu;
+class QAction;
+class QStringList;
+class QContextMenuEvent;
+
+class StrongsResultClass;
+
+
+namespace Search {
+
+
+class CModuleResultView : public QTreeWidget {
+ Q_OBJECT
+public:
+ CModuleResultView(QWidget* parent);
+ ~CModuleResultView();
+
+ /**
+ * Setups the tree using the given list of modules.
+ */
+ void setupTree( QList<CSwordModuleInfo*> modules, const QString& searchedText );
+ /**
+ * Returns the currently active module.
+ */
+ CSwordModuleInfo* activeModule();
+
+ virtual QSize sizeHint() {return m_size;}
+
+protected:
+ /**
+ * Initializes this widget.
+ */
+ void initView();
+ /**
+ * Initializes the connections of this widget
+ */
+ void initConnections();
+
+
+ void setupStrongsResults(CSwordModuleInfo* module, QTreeWidgetItem* parent, const QString& searchedText);
+
+protected slots:
+ /**
+ * Is executed when an item was selected in the list.
+ */
+ void executed(QTreeWidgetItem*, QTreeWidgetItem*);
+ /**
+ * Copies the whole search result with the text into the clipboard.
+ */
+ void copyResultWithText();
+ /**
+ * Copies the whole search result into the clipboard.
+ */
+ void copyResult();
+ /**
+ * This event handler (reimplemented from QWidget) opens the popup menu at the given position.
+ */
+ void contextMenuEvent( QContextMenuEvent * event );
+ /**
+ * Appends the whole search result to the printer queue.
+ */
+ void printResult();
+ /**
+ * Saves the search result with it's text.
+ */
+ void saveResultWithText();
+ /**
+ * Saves the search result keys.
+ */
+ void saveResult();
+
+signals:
+ void moduleSelected(CSwordModuleInfo*);
+ void moduleChanged();
+ void strongsSelected(CSwordModuleInfo*, QStringList*);
+
+private:
+ struct {
+ QMenu* saveMenu;
+ struct {
+ QAction* result;
+ QAction* resultWithText;
+ }
+ save;
+
+ QMenu* printMenu;
+ struct {
+ QAction* result;
+ }
+ print;
+
+ QMenu* copyMenu;
+ struct {
+ QAction* result;
+ QAction* resultWithText;
+ }
+ copy;
+
+ } m_actions;
+
+ QMenu* m_popup;
+
+ StrongsResultClass* strongsResults;
+ QSize m_size;
+};
+
+
+} //end of namespace Search
+
+#endif
diff --git a/src/frontend/searchdialog/crangechooserdialog.cpp b/src/frontend/searchdialog/crangechooserdialog.cpp
new file mode 100644
index 0000000..92a8dc0
--- /dev/null
+++ b/src/frontend/searchdialog/crangechooserdialog.cpp
@@ -0,0 +1,330 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#include "crangechooserdialog.h"
+
+#include "backend/config/cbtconfig.h"
+#include "util/dialogutil.h"
+
+//sword
+#include "versekey.h"
+#include "listkey.h"
+
+
+
+
+#include <QListWidget>
+#include <QListWidgetItem>
+#include <QString>
+#include <QLabel>
+#include <QPushButton>
+#include <QTextEdit>
+#include <QLineEdit>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QFrame>
+#include <QDialogButtonBox>
+
+namespace Search {
+
+
+/********** RangeItem ******************/
+CRangeChooserDialog::RangeItem::RangeItem(QListWidget* view, QListWidgetItem* /*afterThis*/, const QString caption, const QString range)
+ : QListWidgetItem(view)
+{
+ setCaption(caption);
+ setRange(range);
+}
+
+CRangeChooserDialog::RangeItem::~RangeItem() {}
+
+const QString& CRangeChooserDialog::RangeItem::range() const
+{
+ // qWarning("range is %s", (const char*)m_range.utf8());
+ return m_range;
+}
+
+void CRangeChooserDialog::RangeItem::setRange(QString newRange) {
+ m_range = newRange;
+}
+
+QString CRangeChooserDialog::RangeItem::caption() const {
+ return text();
+}
+
+void CRangeChooserDialog::RangeItem::setCaption(const QString newCaption) {
+ setText(newCaption);
+}
+
+
+/*********** Dialog ***************/
+
+CRangeChooserDialog::CRangeChooserDialog( QWidget* parentDialog )
+ : QDialog(parentDialog)
+{
+ //Set the flag to destroy when closed - otherwise eats memory
+ setAttribute(Qt::WA_DeleteOnClose);
+ initView();
+ initConnections();
+
+ //add the existing scopes
+ CBTConfig::StringMap map = CBTConfig::get
+ (CBTConfig::searchScopes);
+ CBTConfig::StringMap::Iterator it;
+ for (it = map.begin(); it != map.end(); ++it) {
+ new RangeItem(m_rangeList, 0, it.key(), it.value());
+ };
+
+ editRange(0);
+ if (RangeItem* i = dynamic_cast<RangeItem*>(m_rangeList->currentItem())
+ ) {
+ nameChanged(i->caption());
+ }
+}
+
+/** Initializes the view of this object. */
+void CRangeChooserDialog::initView()
+{
+ setWindowTitle(tr("Setup Search Scopes"));
+
+ QVBoxLayout* vboxLayout = new QVBoxLayout(this);
+
+ QHBoxLayout* hboxLayout = new QHBoxLayout();
+ QVBoxLayout* vboxLayout1 = new QVBoxLayout();
+ QLabel* rangeListLabel = new QLabel(tr("S&earch range:"), this);
+ vboxLayout1->addWidget(rangeListLabel);
+
+ m_rangeList = new QListWidget(this);
+ m_rangeList->setToolTip(tr("Select a scope from the list to edit the search ranges"));
+ vboxLayout1->addWidget(m_rangeList);
+
+ QHBoxLayout* hboxLayout1 = new QHBoxLayout();
+ m_newRangeButton = new QPushButton(tr("&Add new scope"), this);
+ m_newRangeButton->setToolTip(tr("Add a new search scope. First enter an appropriate name, then edit the search ranges."));
+ hboxLayout1->addWidget(m_newRangeButton);
+ m_deleteRangeButton = new QPushButton(tr("Delete current &scope"), this);
+ m_deleteRangeButton->setToolTip(tr("Delete the selected search scope"));
+ hboxLayout1->addWidget(m_deleteRangeButton);
+
+ vboxLayout1->addLayout(hboxLayout1);
+ hboxLayout->addLayout(vboxLayout1);
+
+ QVBoxLayout* vboxLayout2 = new QVBoxLayout();
+ QHBoxLayout* hboxLayout2 = new QHBoxLayout();
+ QLabel* nameEditLabel = new QLabel(tr("&Name:"), this);
+ hboxLayout2->addWidget(nameEditLabel);
+
+ m_nameEdit = new QLineEdit(this);
+ m_nameEdit->setToolTip(tr("Change the name of the selected search scope"));
+ hboxLayout2->addWidget(m_nameEdit);
+ vboxLayout2->addLayout(hboxLayout2);
+
+ QLabel* rangeEditLabel = new QLabel(tr("Edi&t current range:"), this);
+ vboxLayout2->addWidget(rangeEditLabel);
+
+ m_rangeEdit = new QTextEdit(this);
+ m_rangeEdit->setToolTip(tr("Change the search ranges of the selected search scope item. Have a look at the predefined search scopes to see how search ranges are constructed."));
+
+ vboxLayout2->addWidget(m_rangeEdit);
+
+ QLabel* resultListLabel = new QLabel(tr("Parsed search range:"), this);
+ vboxLayout2->addWidget(resultListLabel);
+
+ m_resultList = new QListWidget(this);
+ m_resultList->setToolTip(tr("The search ranges which will be used for the search, parsed to the canonical form"));
+ vboxLayout2->addWidget(m_resultList);
+
+ hboxLayout->addLayout(vboxLayout2);
+ vboxLayout->addLayout(hboxLayout);
+
+ QFrame* line = new QFrame(this);
+ line->setFrameShape(QFrame::HLine);
+ line->setFrameShadow(QFrame::Sunken);
+ vboxLayout->addWidget(line);
+
+ m_buttonBox = new QDialogButtonBox(this);
+ m_buttonBox->setOrientation(Qt::Horizontal);
+ m_buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults);
+ util::prepareDialogBox(m_buttonBox);
+ vboxLayout->addWidget(m_buttonBox);
+
+ rangeListLabel->setBuddy(m_rangeList);
+ nameEditLabel->setBuddy(m_nameEdit);
+ rangeEditLabel->setBuddy(m_rangeEdit);
+ resultListLabel->setBuddy(m_resultList);
+}
+
+
+
+void CRangeChooserDialog::initConnections()
+{
+ // Signals from text/list widgets
+ QObject::connect(m_rangeList, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
+ this, SLOT(editRange(QListWidgetItem*)));
+
+ QObject::connect(m_rangeEdit, SIGNAL(textChanged()),
+ this, SLOT(parseRange()));
+ QObject::connect(m_rangeEdit, SIGNAL(textChanged()),
+ this, SLOT(rangeChanged()));
+
+ QObject::connect(m_nameEdit, SIGNAL(textChanged(const QString&)),
+ this, SLOT(nameChanged(const QString&)));
+
+ // Buttons
+ QObject::connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(slotOk()));
+ QObject::connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(close()));
+ QObject::connect(m_newRangeButton, SIGNAL(clicked()), this, SLOT(addNewRange()));
+ QObject::connect(m_deleteRangeButton, SIGNAL(clicked()), this, SLOT(deleteCurrentRange()));
+ //restore defaults!
+ QPushButton* defaultsButton = m_buttonBox->button(QDialogButtonBox::RestoreDefaults);
+ QObject::connect(defaultsButton, SIGNAL(clicked()), this, SLOT(slotDefault()));
+}
+
+/** Adds a new range to the list. */
+void CRangeChooserDialog::addNewRange()
+{
+ //qDebug("CRangeChooserDialog::addNewRange");
+ //RangeItem* i = new RangeItem(m_rangeList, m_rangeList->lastItem(), tr("New range"));
+ RangeItem* i = new RangeItem(m_rangeList, 0, tr("New range"));
+ //use just setCurrentItem... m_rangeList->setSelected(i, true);
+ m_rangeList->setCurrentItem(i);
+ editRange(i);
+
+ m_nameEdit->setFocus();
+}
+
+/** No descriptions */
+void CRangeChooserDialog::editRange(QListWidgetItem* item)
+{
+ //qDebug("CRangeChooserDialog::editRange");
+ RangeItem* const range = dynamic_cast<RangeItem*>(item);
+
+ m_nameEdit->setEnabled( range ); //only if an item is selected enable the edit part
+ m_rangeEdit->setEnabled( range );
+ m_resultList->setEnabled( range );
+ m_deleteRangeButton->setEnabled( range );
+
+ if (range) {
+ m_nameEdit->setText(range->caption());
+ m_rangeEdit->setText(range->range());
+ }
+}
+
+/** Parses the entered text and prints out the result in the list box below the edit area. */
+void CRangeChooserDialog::parseRange()
+{
+ //qDebug("CRangeChooserDialog::parseRange");
+ m_resultList->clear();
+
+ //TODO: remove this hack:
+ //HACK: repair range to work with Sword 1.5.6
+ QString range( m_rangeEdit->toPlainText() );
+ range.replace(QRegExp("\\s{0,}-\\s{0,}"), "-" );
+
+ sword::VerseKey key;
+ sword::ListKey verses = key.ParseVerseList((const char*)range.toUtf8(), "Genesis 1:1", true);
+ for (int i = 0; i < verses.Count(); ++i) {
+ new QListWidgetItem(QString::fromUtf8(verses.GetElement(i)->getRangeText()), m_resultList );
+ // qWarning("range=%s, text=%s",verses.GetElement(i)->getRangeText(), verses.GetElement(i)->getText() );
+ }
+
+}
+
+/** No descriptions */
+void CRangeChooserDialog::rangeChanged()
+{
+ //qDebug("CRangeChooserDialog::rangeChanged");
+ if (RangeItem* i = dynamic_cast<RangeItem*>(m_rangeList->currentItem())
+ ) {
+ QString range( m_rangeEdit->toPlainText() );
+ //TODO: remove this hack:
+ //HACK: repair range to work with Sword 1.5.6
+ range.replace(QRegExp("\\s{0,}-\\s{0,}"), "-" );
+ i->setRange(range);
+ };
+}
+
+/** No descriptions */
+void CRangeChooserDialog::nameChanged(const QString& newCaption)
+{
+ //qDebug("CRangeChooserDialog::nameChanged");
+ m_rangeEdit->setEnabled(!newCaption.isEmpty());
+ m_resultList->setEnabled(!newCaption.isEmpty());
+ //m_resultList->header()->setEnabled(!newCaption.isEmpty());
+
+ if (RangeItem* i = dynamic_cast<RangeItem*>(m_rangeList->currentItem())
+ ) {
+ if (!newCaption.isEmpty()) {
+ //enable some items (see "else" below)
+ m_newRangeButton->setEnabled(true);
+ m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
+ m_rangeList->setDisabled(false);
+ i->setCaption(newCaption);
+ }
+ else { //invalid name
+ i->setCaption(tr("<invalid name of search range>"));
+ //disable some items to prevent saving invalid range
+ m_newRangeButton->setEnabled(false);
+ m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
+ m_rangeList->setDisabled(true);
+ };
+ };
+}
+
+/** Deletes the selected range. */
+void CRangeChooserDialog::deleteCurrentRange()
+{
+ //qDebug("CRangeChooserDialog::deleteCurrentRange");
+ if (RangeItem* i = dynamic_cast<RangeItem*>(m_rangeList->currentItem()) ) {
+ int row = m_rangeList->row(i);
+ m_rangeList->takeItem(row);
+ delete i;
+ }
+ editRange(m_rangeList->currentItem());
+}
+
+void CRangeChooserDialog::slotOk()
+{
+ m_rangeList->sortItems(); //sorted first because the order will be saved
+ //save the new map of search scopes
+ CBTConfig::StringMap map;
+ for (int i = 0; i < m_rangeList->count(); i++){
+ if ( RangeItem* item = dynamic_cast<RangeItem*>(m_rangeList->item(i)) ) {
+ map[item->caption()] = item->range();
+ };
+ }
+ CBTConfig::set
+ (CBTConfig::searchScopes, map);
+
+ QDialog::accept();
+}
+
+void CRangeChooserDialog::slotDefault()
+{
+ //qDebug("CRangeChooserDialog::slotDefault");
+ m_rangeList->clear();
+ CBTConfig::StringMap map = CBTConfig::getDefault(CBTConfig::searchScopes);
+ CBTConfig::StringMap::Iterator it;
+ for (it = map.begin(); it != map.end(); ++it) {
+ new RangeItem(m_rangeList, 0, it.key(), it.value());
+ };
+ m_rangeList->setCurrentItem(0);
+
+ editRange(0);
+ if (RangeItem* i = dynamic_cast<RangeItem*>(m_rangeList->currentItem())
+ ) {
+ nameChanged(i->caption());
+ }
+
+}
+
+
+} //end of namespace Search
diff --git a/src/frontend/searchdialog/crangechooserdialog.h b/src/frontend/searchdialog/crangechooserdialog.h
new file mode 100644
index 0000000..4859b15
--- /dev/null
+++ b/src/frontend/searchdialog/crangechooserdialog.h
@@ -0,0 +1,89 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+
+#ifndef CRANGECHOOSERDIALOG_H
+#define CRANGECHOOSERDIALOG_H
+
+#include <QDialog>
+#include <QListWidgetItem>
+
+class QListWidget;
+class QLineEdit;
+class QTextEdit;
+class QPushButton;
+class QDialogButtonBox;
+
+
+namespace Search {
+
+class CRangeChooserDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ CRangeChooserDialog(QWidget* parentDialog);
+ ~CRangeChooserDialog(){};
+
+protected: // Protected methods
+class RangeItem : public QListWidgetItem {
+public:
+ RangeItem(QListWidget*, QListWidgetItem* afterThis = 0, const QString caption = QString::null, const QString range = QString::null);
+ ~RangeItem();
+ const QString& range() const;
+ QString caption() const;
+ void setRange(QString range);
+ void setCaption(const QString);
+private:
+ QString m_range;
+ };
+
+ /**
+ * Initializes the connections of this widget.
+ */
+ void initConnections();
+ /**
+ * Initializes the view of this object.
+ */
+ void initView();
+
+protected slots: // Protected slots
+ /**
+ * Adds a new range to the list.
+ */
+ void addNewRange();
+ void editRange(QListWidgetItem*);
+ /**
+ * Parses the entered text and prints out the result in the list box below the edit area.
+ */
+ void parseRange();
+ void nameChanged(const QString&);
+ void rangeChanged();
+ /**
+ * Deletes the selected range.
+ */
+ void deleteCurrentRange();
+ virtual void slotDefault();
+ virtual void slotOk();
+
+private:
+ QListWidget* m_rangeList;
+ QListWidget* m_resultList;
+ QLineEdit* m_nameEdit;
+ QTextEdit* m_rangeEdit;
+ QPushButton* m_newRangeButton;
+ QPushButton* m_deleteRangeButton;
+ QDialogButtonBox* m_buttonBox;
+};
+
+
+} //end of namespace Search
+
+
+#endif
diff --git a/src/frontend/searchdialog/csearchdialog.cpp b/src/frontend/searchdialog/csearchdialog.cpp
new file mode 100644
index 0000000..947e669
--- /dev/null
+++ b/src/frontend/searchdialog/csearchdialog.cpp
@@ -0,0 +1,304 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+#include "csearchdialog.h"
+#include "btsearchoptionsarea.h"
+#include "btsearchresultarea.h"
+
+#include "backend/cswordmodulesearch.h"
+#include "backend/keys/cswordkey.h"
+#include "backend/keys/cswordversekey.h"
+#include "backend/config/cbtconfig.h"
+
+#include "frontend/cmoduleindexdialog.h"
+
+#include "util/cresmgr.h"
+#include "util/ctoolclass.h"
+#include "util/directoryutil.h"
+
+//Qt includes
+#include <QString>
+#include <QWidget>
+#include <QMessageBox>
+#include <QVBoxLayout>
+#include <QLineEdit>
+#include <QSettings>
+#include <QDialogButtonBox>
+#include <QPushButton>
+#include <QSizePolicy>
+#include <QDebug>
+
+namespace Search {
+
+static CSearchDialog* m_staticDialog = 0;
+
+void CSearchDialog::openDialog(const QList<CSwordModuleInfo*> modules, const QString& searchText, QWidget* parentDialog)
+{
+ if (!m_staticDialog) {
+ m_staticDialog = new CSearchDialog(parentDialog);
+ };
+ m_staticDialog->reset();
+
+ if (modules.count()) {
+ m_staticDialog->setModules(modules);
+ }
+ else {
+ m_staticDialog->showModulesSelector();
+ }
+
+ m_staticDialog->setSearchText(searchText);
+ if (m_staticDialog->isHidden()) {
+ m_staticDialog->show();
+ }
+
+ if (modules.count() && !searchText.isEmpty()) {
+ m_staticDialog->startSearch();
+ }
+ // moved these to after the startSearch() because
+ // the progress dialog caused them to loose focus.
+ m_staticDialog->raise();
+ m_staticDialog->activateWindow();
+}
+
+CSearchDialog* CSearchDialog::getSearchDialog()
+{
+ Q_ASSERT(m_staticDialog);
+ return m_staticDialog;
+}
+
+CSearchDialog::CSearchDialog(QWidget *parent)
+ :QDialog(parent), /*m_searchButton(0),*/ m_closeButton(0),
+ m_searchResultArea(0), m_searchOptionsArea(0)
+{
+ setWindowIcon( util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::icon) );
+ setWindowTitle(tr("Search"));
+ setAttribute(Qt::WA_DeleteOnClose);
+ m_searcher.connectFinished( this, SLOT(searchFinished()));
+ initView();
+ initConnections();
+}
+
+CSearchDialog::~CSearchDialog()
+{
+ saveDialogSettings();
+ m_staticDialog = 0;
+}
+
+/** Starts the search with the set modules and the set search text. */
+void CSearchDialog::startSearch()
+{
+ QString originalSearchText(m_searchOptionsArea->searchText());
+ QString searchText("");
+
+ if (originalSearchText.isEmpty()) {
+ return;
+ }
+
+ searchText = prepareSearchText(originalSearchText);
+
+ // Insert search text into history list of combobox
+ m_searchOptionsArea->addToHistory(originalSearchText);
+
+ // check that we have the indices we need for searching
+ if (!m_searcher.modulesHaveIndices( modules() ) ) {
+ int result = QMessageBox::question(this, tr("Missing indices"),
+ tr("One or more works need indexing before they can be searched.\n"
+ "This could take a long time. Proceed with indexing?"),
+ QMessageBox::Yes | QMessageBox::Default,
+ QMessageBox::No | QMessageBox::Escape);
+ // In SuSE 10.0 the result is the logical or of the button type, just like it is
+ // inputed into the QMessageBox.
+ if ( (result == (QMessageBox::Yes | QMessageBox::Default)) ||
+ (result == QMessageBox::Yes) || (result == QMessageBox::Default) ) {
+ CModuleIndexDialog* dlg = CModuleIndexDialog::getInstance();
+ dlg->indexUnindexedModules( modules() );
+ }
+ else {
+ return;
+ }
+ }
+
+ if (m_searchOptionsArea->hasSearchScope()) {
+ m_searcher.setSearchScope( m_searchOptionsArea->searchScope() );
+ }
+ else {
+ m_searcher.resetSearchScope();
+ }
+
+ m_searcher.setModules( modules() );
+ m_searcher.setSearchedText(searchText);
+
+
+ //Just to be sure that it can't be clicked again, if the search happens to be a bit slow.
+ m_searchOptionsArea->searchButton()->setEnabled(false);
+ m_searchOptionsArea->m_searchTextCombo->setEnabled(false);
+
+ m_searcher.startSearch();
+
+ m_searchOptionsArea->searchButton()->setEnabled(true);
+ m_searchOptionsArea->m_searchTextCombo->setEnabled(true);
+ m_searchOptionsArea->m_searchTextCombo->setFocus();
+}
+
+QString CSearchDialog::prepareSearchText(const QString& orig)
+{
+ qDebug() << "Original search text:" << orig;
+ static const QRegExp syntaxCharacters("[+\\-()!\"~]");
+ static const QRegExp andWords("\\band\\b", Qt::CaseInsensitive);
+ static const QRegExp orWords("\\bor\\b", Qt::CaseInsensitive);
+ QString text("");
+ if (m_searchOptionsArea->searchType() == BtSearchOptionsArea::AndType) {
+ qDebug() << "AND type";
+ text = orig.simplified();
+ text.remove(syntaxCharacters);
+ qDebug() << "After syntax characters removed:" << text;
+ text.replace(andWords, "\"and\"");
+ text.replace(orWords, "\"or\"");
+ qDebug() << "After andor repclaced:" << text;
+ text.replace(" ", " AND ");
+ }
+ if (m_searchOptionsArea->searchType() == BtSearchOptionsArea::OrType) {
+ text = orig.simplified();
+ text.remove(syntaxCharacters);
+ text.replace(andWords, "\"and\"");
+ text.replace(orWords, "\"or\"");
+ }
+ if (m_searchOptionsArea->searchType() == BtSearchOptionsArea::FullType) {
+ text = orig;
+ }
+ qDebug() << "The final search string:" << text;
+ return text;
+}
+
+/** Starts the search with the given module list and given search text. */
+void CSearchDialog::startSearch( const QList<CSwordModuleInfo*> modules, const QString& searchText)
+{
+ m_searchResultArea->reset();
+ m_searchOptionsArea->reset();
+ setModules(modules);
+ setSearchText(searchText);
+
+ startSearch();
+}
+
+/** Returns the list of used modules. */
+QList<CSwordModuleInfo*> CSearchDialog::modules() const
+{
+ return m_searchOptionsArea->modules();
+}
+
+/** Sets the list of modules for the search. */
+void CSearchDialog::setModules( const QList<CSwordModuleInfo*> modules )
+{
+ m_searchOptionsArea->setModules(modules);
+}
+
+/** Returns the search text which is set currently. */
+QString CSearchDialog::searchText() const
+{
+ return m_searchOptionsArea->searchText();
+}
+
+sword::ListKey CSearchDialog::searchScope()
+{
+ return m_searchOptionsArea->searchScope();
+}
+
+/** Sets the search text which is used for the search. */
+void CSearchDialog::setSearchText( const QString searchText )
+{
+ m_searchOptionsArea->setSearchText(searchText);
+}
+
+/** Initializes this object. */
+void CSearchDialog::initView()
+{
+ QVBoxLayout* verticalLayout = new QVBoxLayout(this);
+ setLayout(verticalLayout);
+
+ m_searchOptionsArea = new BtSearchOptionsArea(this);
+ verticalLayout->addWidget(m_searchOptionsArea);
+
+ m_searchResultArea = new BtSearchResultArea(this);
+ verticalLayout->addWidget(m_searchResultArea);
+
+ QHBoxLayout* horizontalLayout = new QHBoxLayout();
+
+ m_analyseButton = new QPushButton(tr("&Analyze results..."), 0);
+ m_analyseButton->setToolTip(tr("Show a graphical analyzis of the search result"));
+ QSpacerItem* spacerItem = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum);
+ horizontalLayout->addWidget(m_analyseButton);
+ horizontalLayout->addItem(spacerItem);
+
+ m_closeButton = new QPushButton(this);
+ m_closeButton->setText(tr("&Close"));
+ m_closeButton->setIcon( util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::close_icon));
+ horizontalLayout->addWidget(m_closeButton);
+
+ verticalLayout->addLayout(horizontalLayout);
+
+ loadDialogSettings();
+}
+
+void CSearchDialog::searchFinished() {
+ if ( m_searcher.foundItems() ) {
+ m_searchResultArea->setSearchResult(modules());
+ }
+ else {
+ m_searchResultArea->reset();
+ }
+ m_staticDialog->raise();
+ m_staticDialog->activateWindow();
+}
+
+void CSearchDialog::showModulesSelector() {
+ m_searchOptionsArea->chooseModules();
+}
+
+/** Initializes the signal slot connections */
+void CSearchDialog::initConnections() {
+ // Search button is clicked
+ bool ok = connect(m_searchOptionsArea->searchButton(), SIGNAL(pressed()),this, SLOT(startSearch()));
+ Q_ASSERT(ok);
+ // Return/Enter is pressed in the search text field
+ ok = connect(m_searchOptionsArea, SIGNAL(sigStartSearch()), this, SLOT(startSearch()) );
+ Q_ASSERT(ok);
+ ok = connect(m_closeButton, SIGNAL(pressed()), this, SLOT(closeButtonPressed()));
+ Q_ASSERT(ok);
+
+ connect(m_analyseButton, SIGNAL(clicked()), m_searchResultArea, SLOT(showAnalysis()));
+
+}
+
+/** Resets the parts to the default. */
+void CSearchDialog::reset() {
+ m_searchOptionsArea->reset();
+ m_searchResultArea->reset();
+}
+
+void CSearchDialog::closeButtonPressed() {
+ // With Qt::WA_DeleteOnClose set, the dialog will be deleted now
+ m_staticDialog->close();
+}
+
+void CSearchDialog::loadDialogSettings()
+{
+ resize(CBTConfig::get(CBTConfig::searchDialogWidth), CBTConfig::get(CBTConfig::searchDialogHeight));
+ move(CBTConfig::get(CBTConfig::searchDialogX), CBTConfig::get(CBTConfig::searchDialogY));
+}
+
+void CSearchDialog::saveDialogSettings()
+{
+ CBTConfig::set(CBTConfig::searchDialogWidth, size().width());
+ CBTConfig::set(CBTConfig::searchDialogHeight, size().height());
+ CBTConfig::set(CBTConfig::searchDialogX, x());
+ CBTConfig::set(CBTConfig::searchDialogY, y());
+}
+
+
+} //end of namespace Search
diff --git a/src/frontend/searchdialog/csearchdialog.h b/src/frontend/searchdialog/csearchdialog.h
new file mode 100644
index 0000000..639ca26
--- /dev/null
+++ b/src/frontend/searchdialog/csearchdialog.h
@@ -0,0 +1,134 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CSEARCHDIALOG_H
+#define CSEARCHDIALOG_H
+
+//BibleTime includes
+#include "backend/managers/cswordbackend.h"
+#include "backend/cswordmodulesearch.h"
+
+#include "util/cpointers.h"
+
+//Qt includes
+#include <QString>
+#include <QDialog>
+
+
+//forward declarations
+namespace Search {
+ class BtSearchResultArea;
+ class BtSearchOptionsArea;
+}
+
+class QWidget;
+class QPushButton;
+
+
+namespace Search {
+
+/**
+ *@author The BibleTime team
+ */
+class CSearchDialog : public QDialog {
+ Q_OBJECT
+
+public:
+ static void openDialog(const QList<CSwordModuleInfo*> modules, const QString& searchText = QString::null, QWidget* parentDialog = 0);
+
+protected:
+ friend class CSearchAnalysisScene;
+ friend class CSearchResultArea;
+ friend class BtSearchResultArea;
+ friend class BibleTime;
+
+ /**
+ * Only interesting for the class members! Useful to get the searched text etc.
+ */
+ static CSearchDialog* getSearchDialog();
+
+ /**
+ * The constructor of the dialog. It's protected because you should use the static public function openDialog.
+ * The dialog destroys itself if it was closed.
+ */
+ CSearchDialog(QWidget *parent);
+ ~CSearchDialog();
+
+ /**
+ * Initializes this object.
+ */
+ void initView();
+ /**
+ * Starts the search with the given module list and given search text.
+ * Doesn't wait for the start button press, starts immediately
+ */
+ void startSearch( const QList<CSwordModuleInfo*> modules, const QString& searchText);
+ /**Prepares the search string given by user for a specific search type */
+ QString prepareSearchText(const QString& orig);
+ /**
+ * Sets the list of modules for the search.
+ */
+ void setModules( const QList<CSwordModuleInfo*> modules );
+ /**
+ * Returns the list of used modules.
+ */
+ QList<CSwordModuleInfo*> modules() const;
+ /**
+ * Sets the search text which is used for the search.
+ */
+ void setSearchText( const QString searchText );
+ /**
+ * Returns the search text which is set currently.
+ */
+ QString searchText() const;
+ /**
+ * Returns the used search scope as a list key
+ */
+ sword::ListKey searchScope();
+
+ /**
+ * Resets the parts to the default.
+ */
+ void reset();
+ /**
+ * Load the settings from the resource file
+ */
+ void loadDialogSettings();
+ /**
+ * Save the settings to the resource file
+ */
+ void saveDialogSettings();
+
+protected slots:
+ /**
+ * Starts the search with the set modules and the set search text.
+ */
+ void startSearch();
+ void searchFinished();
+ void showModulesSelector();
+ /**
+ * Initializes the signal slot connections
+ */
+ void initConnections();
+
+ void closeButtonPressed();
+
+private:
+ QPushButton* m_analyseButton;
+ QPushButton* m_closeButton;
+ BtSearchResultArea* m_searchResultArea;
+ BtSearchOptionsArea* m_searchOptionsArea;
+
+ CSwordModuleSearch m_searcher;
+};
+
+
+} //end of namespace Search
+
+#endif
diff --git a/src/frontend/searchdialog/csearchmodulechooserdialog.cpp b/src/frontend/searchdialog/csearchmodulechooserdialog.cpp
new file mode 100644
index 0000000..cf68f6e
--- /dev/null
+++ b/src/frontend/searchdialog/csearchmodulechooserdialog.cpp
@@ -0,0 +1,61 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2007 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "csearchmodulechooserdialog.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/managers/cswordbackend.h"
+#include "backend/btmoduletreeitem.h"
+
+#include "util/cpointers.h"
+#include "util/cresmgr.h"
+#include "util/ctoolclass.h"
+#include "util/directoryutil.h"
+
+#include <QDialog>
+#include <QButtonGroup>
+#include <QDialogButtonBox>
+#include <QHBoxLayout>
+#include <QSpacerItem>
+#include <QTreeWidget>
+#include <QVBoxLayout>
+#include <QStringList>
+#include <QDebug>
+#include <QHeaderView>
+
+namespace Search {
+
+CSearchModuleChooserDialog::CSearchModuleChooserDialog( QWidget* parent, QString title, QString label,
+ QList<CSwordModuleInfo*> selectedModules)
+ : CModuleChooserDialog(parent, title, label),
+ m_selectedModules(selectedModules)
+{
+ m_hiddenFilter = new BTModuleTreeItem::HiddenOff();
+ QList<BTModuleTreeItem::Filter*> filters;
+ filters.append(m_hiddenFilter);
+ setFilters(filters);
+ init();
+}
+
+CSearchModuleChooserDialog::~CSearchModuleChooserDialog()
+{
+ //see the ctor
+ delete m_hiddenFilter;
+}
+
+void CSearchModuleChooserDialog::initModuleItem(BTModuleTreeItem* btItem, QTreeWidgetItem* widgetItem)
+{
+ widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
+ if (m_selectedModules.contains(btItem->moduleInfo()))
+ widgetItem->setCheckState(0, Qt::Checked);
+ else
+ widgetItem->setCheckState(0, Qt::Unchecked);
+}
+
+} //end of namespace Search
diff --git a/src/frontend/searchdialog/csearchmodulechooserdialog.h b/src/frontend/searchdialog/csearchmodulechooserdialog.h
new file mode 100644
index 0000000..8d5e32c
--- /dev/null
+++ b/src/frontend/searchdialog/csearchmodulechooserdialog.h
@@ -0,0 +1,44 @@
+//
+// C++ Interface: cmodulechooserdialog
+//
+// Description:
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef CSEARCHMODULECHOOSERDIALOG_H
+#define CSEARCHMODULECHOOSERDIALOG_H
+
+class CSwordModuleInfo;
+
+#include "frontend/cmodulechooserdialog.h"
+
+class QTreeWidgetItem;
+
+class BTModuleTreeItem;
+
+
+namespace Search {
+
+class CSearchModuleChooserDialog : public CModuleChooserDialog
+{
+ Q_OBJECT
+public:
+ CSearchModuleChooserDialog(QWidget* parent, QString title, QString label, QList<CSwordModuleInfo*> selectedModules);
+ ~CSearchModuleChooserDialog();
+
+protected: // Protected methods
+ virtual void initModuleItem(BTModuleTreeItem* btItem, QTreeWidgetItem* widgetItem);
+
+private:
+ QList<CSwordModuleInfo*> m_selectedModules;
+ BTModuleTreeItem::HiddenOff* m_hiddenFilter;
+};
+
+} //end of namespace Search
+
+#endif
diff --git a/src/frontend/searchdialog/csearchresultview.cpp b/src/frontend/searchdialog/csearchresultview.cpp
new file mode 100644
index 0000000..74561d6
--- /dev/null
+++ b/src/frontend/searchdialog/csearchresultview.cpp
@@ -0,0 +1,295 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "csearchresultview.h"
+
+#include "backend/keys/cswordversekey.h"
+
+#include "frontend/cdragdrop.h"
+#include "frontend/cexportmanager.h"
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+
+#include <QWidget>
+#include <QMenu>
+#include <QList>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+#include <QContextMenuEvent>
+
+//KDE includes
+
+
+namespace Search {
+
+
+CSearchResultView::CSearchResultView(QWidget* parent)
+ : QTreeWidget(parent),
+ m_module(0)
+{
+ initView();
+ initConnections();
+}
+
+CSearchResultView::~CSearchResultView() {}
+
+/** Initializes the view of this widget. */
+void CSearchResultView::initView()
+{
+ setToolTip(tr("Search result of the selected work"));
+ setHeaderLabel(tr("Results"));
+ setDragEnabled(true);
+ setRootIsDecorated( false );
+ setSelectionMode(QAbstractItemView::ExtendedSelection);
+
+ //setup the popup menu
+ m_popup = new QMenu(this);
+
+ m_actions.copyMenu = new QMenu(tr("Copy..."), m_popup);
+ m_actions.copyMenu->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::result::foundItems::copyMenu::icon));
+
+ m_actions.copy.result = new QAction(tr("Reference only"), this);
+ QObject::connect(m_actions.copy.result, SIGNAL(triggered()), this, SLOT(copyItems()) );
+ m_actions.copyMenu->addAction(m_actions.copy.result);
+
+ m_actions.copy.resultWithText = new QAction(tr("Reference with text"), this);
+ QObject::connect(m_actions.copy.resultWithText, SIGNAL(triggered()),
+ this, SLOT(copyItemsWithText()));
+ m_actions.copyMenu->addAction(m_actions.copy.resultWithText);
+
+ m_popup->addMenu(m_actions.copyMenu);
+
+ m_actions.saveMenu = new QMenu(tr("Save..."), m_popup);
+ m_actions.saveMenu->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::result::foundItems::saveMenu::icon));
+
+ m_actions.save.result = new QAction(tr("Reference only"), this);
+ QObject::connect(m_actions.save.result, SIGNAL(triggered()), this, SLOT(saveItems()) );
+ m_actions.saveMenu->addAction(m_actions.save.result);
+
+ m_actions.save.resultWithText = new QAction(tr("Reference with text"), this);
+ m_actions.saveMenu->addAction(m_actions.save.resultWithText);
+ QObject::connect(m_actions.save.resultWithText, SIGNAL(triggered()), this, SLOT(saveItemsWithText()));
+ m_popup->addMenu(m_actions.saveMenu);
+
+ m_actions.printMenu = new QMenu(tr("Print..."), m_popup);
+ m_actions.printMenu->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::result::foundItems::printMenu::icon));
+
+ m_actions.print.result = new QAction(tr("Reference with text"), this);
+ QObject::connect(m_actions.print.result, SIGNAL(triggered()), this, SLOT(printItems()) );
+ m_actions.printMenu->addAction(m_actions.print.result);
+ m_popup->addMenu(m_actions.printMenu);
+}
+
+/** No descriptions */
+void CSearchResultView::initConnections() {
+ // connect(this, SIGNAL(executed(QListViewItem*)),
+ // this, SLOT(executed(QListViewItem*)));
+ //TODO: are these right after porting?
+ //items: current, previous
+ connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
+ this, SLOT(executed(QTreeWidgetItem*, QTreeWidgetItem*)));
+}
+
+/** Setups the list with the given module. */
+void CSearchResultView::setupTree(CSwordModuleInfo* m) {
+ clear();
+
+ if (!m) return;
+
+ m_module = m;
+ sword::ListKey& result = m->searchResult();
+ const int count = result.Count();
+ if (!count) return;
+
+ setUpdatesEnabled(false);
+
+ QTreeWidgetItem* oldItem = 0;
+ QTreeWidgetItem* item = 0;
+ for (int index = 0; index < count; index++) {
+ item = new QTreeWidgetItem(this, oldItem);
+ item->setText(0, QString::fromUtf8(result.GetElement(index)->getText()));
+ oldItem = item;
+ }
+
+ setUpdatesEnabled(true);
+ //pre-select the first item
+ this->setCurrentItem(this->topLevelItem(0), 0);
+}
+
+void CSearchResultView::setupStrongsTree(CSwordModuleInfo* m, QStringList* vList)
+{
+ clear();
+ if (!m) {
+ return;
+ }
+
+ m_module = m;
+
+ if (vList->count() <= 0) {
+ return;
+ }
+
+ setUpdatesEnabled(false);
+
+ QTreeWidgetItem* oldItem = 0;
+ QTreeWidgetItem* item = 0;
+
+ foreach (QString s, *vList) {
+ item = new QTreeWidgetItem(this, oldItem);
+ item->setText(0, (s));
+ oldItem = item;
+ }
+
+ setUpdatesEnabled(true);
+
+ //TODO:select the first item
+ //setSelected(firstChild(), true);
+ //executed(currentItem());
+}
+
+//TODO: is this still valid?
+/** Is connected to the signal executed, which is emitted when a mew item was chosen. */
+void CSearchResultView::executed(QTreeWidgetItem* current, QTreeWidgetItem*) {
+ if (current){
+ emit keySelected(current->text(0));
+ }
+ else{
+ emit keyDeselected();
+ }
+}
+
+//TODO: another function?
+/** Reimplementation to show the popup menu. */
+void CSearchResultView::contextMenuEvent(QContextMenuEvent* event)
+{
+ qDebug("CSearchResultView::showPopup");
+ m_popup->exec(event->globalPos());
+}
+
+void CSearchResultView::printItems() {
+ QList<QTreeWidgetItem*> items = selectedItems();
+ CExportManager mgr(tr("Print search result..."), true, tr("Printing search result"));
+
+ QStringList list;
+ foreach (QTreeWidgetItem* k, items) {
+ list.append( k->text(0) );
+ }
+ mgr.printKeyList( list, module(), CBTConfig::getDisplayOptionDefaults(), CBTConfig::getFilterOptionDefaults() );
+}
+
+void CSearchResultView::saveItems() {
+ CExportManager mgr(tr("Save search result..."), true, tr("Saving search result"));
+
+ CSwordModuleInfo* m = module();
+ CSwordKey* k = 0;
+ QList<QTreeWidgetItem*> items = selectedItems();
+ QList<CSwordKey*> keys;
+ foreach (QTreeWidgetItem* i, items) {
+ k = CSwordKey::createInstance( m );
+ k->key(i->text(0));
+ keys.append( k );
+ }
+ mgr.saveKeyList( keys, CExportManager::Text, false);
+
+ qDeleteAll(keys);
+ keys.clear(); //delete all the keys we created
+}
+
+void CSearchResultView::saveItemsWithText() {
+ CExportManager mgr(tr("Save search result..."), true, tr("Saving search result"));
+
+ CSwordModuleInfo* m = module();
+ CSwordKey* k = 0;
+ QList<QTreeWidgetItem*> items = selectedItems();
+ QList<CSwordKey*> keys;
+ foreach (QTreeWidgetItem* i, items) {
+ k = CSwordKey::createInstance( m );
+ k->key(i->text(0));
+ keys.append( k );
+ };
+ mgr.saveKeyList( keys, CExportManager::Text, true);
+
+ qDeleteAll(keys);
+ keys.clear(); //delete all the keys we created
+}
+
+void CSearchResultView::copyItems() {
+ CExportManager mgr(tr("Copy search result..."), true, tr("Copying search result"));
+
+ CSwordModuleInfo* m = module();
+ CSwordKey* k = 0;
+ QList<QTreeWidgetItem*> items = selectedItems();
+ QList<CSwordKey*> keys;
+ foreach (QTreeWidgetItem* i, items) {
+ k = CSwordKey::createInstance( m );
+ k->key(i->text(0));
+ keys.append( k );
+ };
+ mgr.copyKeyList( keys, CExportManager::Text, false);
+
+ qDeleteAll(keys);
+ keys.clear(); //delete all the keys we created
+}
+
+void CSearchResultView::copyItemsWithText() {
+ CExportManager mgr(tr("Copy search result..."), true, tr("Copying search result"));
+
+ CSwordModuleInfo* m = module();
+ CSwordKey* k = 0;
+ QList<QTreeWidgetItem*> items = selectedItems();
+ QList<CSwordKey*> keys;
+ foreach (QTreeWidgetItem* i, items) {
+ k = CSwordKey::createInstance( m );
+ k->key(i->text(0));
+ keys.append( k );
+ };
+ mgr.copyKeyList( keys, CExportManager::Text, true);
+
+ qDeleteAll(keys);
+ keys.clear(); //delete all the keys we created
+}
+
+CSwordModuleInfo* CSearchResultView::module() {
+ return m_module;
+}
+
+//TODO: port this to the new d'n'd
+// Q3DragObject* CSearchResultView::dragObject() {
+// //return a valid DragObject to make DnD possible!
+//
+// /*
+// * First get all selected items and fill with them the dndItems list. The return the QDragObject we got from CDRagDropMgr
+// */
+// CDragDropMgr::ItemList dndItems;
+//
+// Q3PtrList<Q3ListViewItem> items = selectedItems();
+// for (items.first(); items.current(); items.next()) {
+// dndItems.append( CDragDropMgr::Item(m_module->name(), items.current()->text(0), QString::null) ); //no description
+// };
+//
+// return CDragDropMgr::dragObject(dndItems, viewport());
+// }
+
+
+QMimeData * CSearchResultView::mimeData ( const QList<QTreeWidgetItem *> items ) const
+{
+ BTMimeData* mdata = new BTMimeData(m_module->name(), items.first()->text(0), QString::null);
+ foreach (QTreeWidgetItem* i, items) {
+ mdata->appendBookmark(m_module->name(), i->text(0), QString::null);
+ }
+ return mdata;
+}
+
+QStringList CSearchResultView::mimeTypes () const
+{
+ return QStringList("BibleTime/Bookmark");
+}
+
+} //end of namespace
+
diff --git a/src/frontend/searchdialog/csearchresultview.h b/src/frontend/searchdialog/csearchresultview.h
new file mode 100644
index 0000000..4d43bbf
--- /dev/null
+++ b/src/frontend/searchdialog/csearchresultview.h
@@ -0,0 +1,101 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CSEARCHRESULTSVIEW_H
+#define CSEARCHRESULTSVIEW_H
+
+class CSwordModuleInfo;
+
+#include <QTreeWidget>
+
+//forward declarations
+class QMenu;
+class QAction;
+class CReadDisplay;
+
+namespace Search {
+
+class CSearchResultView : public QTreeWidget {
+ Q_OBJECT
+public:
+ CSearchResultView(QWidget* parent);
+ virtual ~CSearchResultView();
+ /** Returns the module which is currently used. */
+ CSwordModuleInfo* module();
+
+protected: // Protected methods
+ /**
+ * Initializes the view of this widget.
+ */
+ void initView();
+ void initConnections();
+
+ //from QTreeWidget
+ virtual QMimeData * mimeData ( const QList<QTreeWidgetItem *> items ) const;
+ virtual QStringList mimeTypes () const;
+
+public slots: // Public slots
+ void saveItems();
+ /**
+ * Setups the list with the given module.
+ */
+ void setupTree(CSwordModuleInfo*);
+ void setupStrongsTree(CSwordModuleInfo*, QStringList*);
+ void copyItemsWithText();
+ void copyItems();
+ void saveItemsWithText();
+ /**
+ * Reimplementation to show the popup menu.
+ */
+ virtual void contextMenuEvent(QContextMenuEvent* event);
+
+protected slots: // Protected slots
+ void printItems();
+
+ /**
+ * Is connected to the signal which is emitted when a new item was chosen.
+ */
+ void executed(QTreeWidgetItem* current, QTreeWidgetItem*);
+
+private:
+ struct {
+ QMenu* saveMenu;
+ struct {
+ QAction* result;
+ QAction* resultWithText;
+ }
+ save;
+
+ QMenu* printMenu;
+ struct {
+ QAction* result;
+ }
+ print;
+
+ QMenu* copyMenu;
+ struct {
+ QAction* result;
+ QAction* resultWithText;
+ }
+ copy;
+ }
+ m_actions;
+
+ QMenu* m_popup;
+ CSwordModuleInfo* m_module;
+
+signals: // Signals
+ void keySelected(const QString&);
+ void keyDeselected();
+};
+
+} //end of namespace Search
+
+#endif
+
diff --git a/src/frontend/settingsdialogs/cacceleratorsettings.cpp.OFF b/src/frontend/settingsdialogs/cacceleratorsettings.cpp.OFF
new file mode 100644
index 0000000..66fa9dc
--- /dev/null
+++ b/src/frontend/settingsdialogs/cacceleratorsettings.cpp.OFF
@@ -0,0 +1,268 @@
+//
+// C++ Implementation: cacceleratorsettings
+//
+// Description:
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 1999-2008
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include "cacceleratorsettings.h"
+#include "cacceleratorsettings.moc"
+
+#include "backend/config/cbtconfig.h"
+
+#include "frontend/displaywindow/cbiblereadwindow.h"
+#include "frontend/displaywindow/ccommentaryreadwindow.h"
+#include "frontend/displaywindow/clexiconreadwindow.h"
+#include "frontend/displaywindow/cbookreadwindow.h"
+#include "frontend/displaywindow/creadwindow.h"
+
+#include <QWidget>
+#include <QComboBox>
+#include <QStackedWidget>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QLabel>
+#include <QList>
+
+#include <kactioncollection.h>
+
+
+
+CAcceleratorSettingsPage::CAcceleratorSettingsPage(QWidget *parent)
+ : QWidget(parent)
+{
+ qDebug("CAcceleratorSettingsPage::CAcceleratorSettingsPage");
+ //TODO: widget layout may not work. Maybe it would be easier to use .ui file.
+
+ QVBoxLayout* mainLayout = new QVBoxLayout(this);
+ this->setLayout(mainLayout);
+ //TODO: actionCollection must exist, but is this the right way?
+ m_application.actionCollection = new KActionCollection(this);
+ CBTConfig::setupAccelSettings(
+ CBTConfig::application,
+ m_application.actionCollection
+ );
+ qDebug("create layout for window type chooser");
+ QHBoxLayout* layoutForWindowTypeChooser = new QHBoxLayout(this);
+ mainLayout->addLayout(layoutForWindowTypeChooser);
+ QLabel* label = new QLabel(tr("Choose type:"), this);
+ layoutForWindowTypeChooser->addWidget(label);
+ m_typeChooser = new QComboBox(this);
+ layoutForWindowTypeChooser->addWidget(m_typeChooser);
+
+ connect(
+ m_typeChooser, SIGNAL(activated(const QString&)),
+ SLOT(slotKeyChooserTypeChanged(const QString&))
+ );
+ //too ugly! change!
+ //QLabel* dummy = new QLabel( this); // empty label for stretch
+ //hbox->addWidget(dummy);
+
+ //hbox->setStretchFactor(label, 0);
+ //hbox->setStretchFactor(m_typeChooser, 0);
+ //hbox->setStretchFactor(dummy, 1);
+
+ //mainLayout->setStretchFactor(hbox, 0);
+ qDebug("create stack");
+ m_keyChooserStack = new QStackedWidget(this);
+
+ //mainLayout->setStretchFactor(m_keyChooserStack, 5);
+
+ m_application.title = tr("BibleTime"); //don't set the app action collection to NULL
+ m_general = WindowType(tr("All text windows"));
+ m_bible = WindowType(tr("Bible windows"));
+ m_commentary = WindowType(tr("Commentary windows"));
+ m_lexicon = WindowType(tr("Lexicon windows"));
+ m_book = WindowType(tr("Book windows"));
+
+ m_typeChooser->addItem(m_application.title);
+ m_typeChooser->addItem(m_general.title);
+ m_typeChooser->addItem(m_bible.title);
+ m_typeChooser->addItem(m_commentary.title);
+ m_typeChooser->addItem(m_lexicon.title);
+ m_typeChooser->addItem(m_book.title);
+
+ qDebug("create shortcuteditors");
+ Q_ASSERT(m_application.actionCollection);
+ m_application.keyChooser = new KShortcutsEditor(
+ m_application.actionCollection,
+ m_keyChooserStack
+ );
+ qDebug("add first w");
+ m_keyChooserStack->addWidget(m_application.keyChooser);
+
+ // ----- All display windows ------ //
+ m_general.actionCollection = new KActionCollection(this);
+ CDisplayWindow::insertKeyboardActions( m_general.actionCollection);
+ CBTConfig::setupAccelSettings(
+ CBTConfig::allWindows,
+ m_general.actionCollection
+ );
+ m_general.keyChooser = new KShortcutsEditor(
+ m_general.actionCollection,
+ m_keyChooserStack
+ );
+ qDebug("add second w");
+ m_keyChooserStack->addWidget(m_general.keyChooser);
+
+ // ----- Bible windows ------ //
+ m_bible.actionCollection = new KActionCollection(this);
+ CBibleReadWindow::insertKeyboardActions( m_bible.actionCollection);
+ CBTConfig::setupAccelSettings(
+ CBTConfig::bibleWindow,
+ m_bible.actionCollection
+ );
+ //m_keyChooserStack->addWidget(m_bible.keyChooser);
+
+ // ----- Commentary windows ------ //
+ m_commentary.actionCollection = new KActionCollection(this);
+ CCommentaryReadWindow::insertKeyboardActions( m_commentary.actionCollection);
+ CBTConfig::setupAccelSettings(
+ CBTConfig::commentaryWindow,
+ m_commentary.actionCollection
+ );
+ //m_keyChooserStack->addWidget(m_commentary.keyChooser);
+
+ // ----- Lexicon windows ------ //
+ m_lexicon.actionCollection = new KActionCollection(this);
+ CLexiconReadWindow::insertKeyboardActions( m_lexicon.actionCollection );
+ CBTConfig::setupAccelSettings(
+ CBTConfig::lexiconWindow,
+ m_lexicon.actionCollection
+ );
+ //m_keyChooserStack->addWidget(m_lexicon.keyChooser);
+
+ // ----- Book windows ------ //
+ m_book.actionCollection= new KActionCollection(this);
+ CBookReadWindow::insertKeyboardActions( m_book.actionCollection);
+ CBTConfig::setupAccelSettings(
+ CBTConfig::bookWindow,
+ m_book.actionCollection
+ );
+ //m_keyChooserStack->addWidget(m_book.keyChooser);
+
+ mainLayout->addWidget(m_keyChooserStack);
+ slotKeyChooserTypeChanged(m_application.title);
+
+ qDebug("CAcceleratorSettingsPage::CAcceleratorSettingsPage end");
+}
+
+
+CAcceleratorSettingsPage::~CAcceleratorSettingsPage()
+{
+}
+
+void CAcceleratorSettingsPage::save()
+{
+ /* //TODO: does kde4 work without commitChanges?
+ if (m_general.keyChooser) {
+ m_general.keyChooser->commitChanges();
+ }
+
+ if (m_bible.keyChooser) {
+ m_bible.keyChooser->commitChanges();
+ }
+
+ if (m_commentary.keyChooser) {
+ m_commentary.keyChooser->commitChanges();
+ }
+
+ if (m_lexicon.keyChooser) {
+ m_lexicon.keyChooser->commitChanges();
+ }
+
+ if (m_book.keyChooser) {
+ m_book.keyChooser->commitChanges();
+ }
+ */
+ CBTConfig::saveAccelSettings( //application
+ CBTConfig::application,
+ m_application.actionCollection
+ );
+ CBTConfig::saveAccelSettings( //read display windows
+ CBTConfig::allWindows,
+ m_general.actionCollection
+ );
+ CBTConfig::saveAccelSettings( //bible
+ CBTConfig::bibleWindow,
+ m_bible.actionCollection
+ );
+ CBTConfig::saveAccelSettings( //commentary
+ CBTConfig::commentaryWindow,
+ m_commentary.actionCollection
+ );
+ CBTConfig::saveAccelSettings( //lexicon
+ CBTConfig::lexiconWindow,
+ m_lexicon.actionCollection
+ );
+ CBTConfig::saveAccelSettings( //book
+ CBTConfig::bookWindow,
+ m_book.actionCollection
+ );
+}
+
+
+void CAcceleratorSettingsPage::slotKeyChooserTypeChanged(const QString& title)
+{
+ qDebug("CAcceleratorSettingsPage::slotKeyChooserTypeChanged");
+ //delete all KShortcutsEditors which may not share accels, because this class checks in all instances for key conflicts
+ typedef QList<KShortcutsEditor*> KeyChooserList;
+ KeyChooserList list;
+ list.append(m_bible.keyChooser);
+ list.append(m_commentary.keyChooser);
+ list.append(m_lexicon.keyChooser);
+ list.append(m_book.keyChooser);
+
+ //commit all changes in the keychoosers
+ //for (KeyChooserList::iterator it(list.begin()); it != list.end(); ++it) {
+ // if (*it) { //the list may contain NULL pointers
+ // (*it)->commitChanges();
+ // }
+ //}
+
+ /* Delete all the keychoosers in the list,
+ * the keychoosers are set to NULL, because they are QGuardedPtr
+ */
+ //list.setAutoDelete(true);
+ qDeleteAll(list);
+ list.clear();
+
+ WindowType* t = 0;
+ if (title == m_application.title) { //Application wide
+ t = &m_application;
+ }
+ else if (title == m_general.title) { // All display windows
+ t = &m_general;
+ }
+ else if (title == m_bible.title) { // Bible windows
+ t = &m_bible;
+ }
+ else if (title == m_commentary.title) { // Commentary windows
+ t = &m_commentary;
+ }
+ else if (title == m_lexicon.title) { // Lexicon windows
+ t = &m_lexicon;
+ }
+ else if (title == m_book.title) { // Book windows
+ t = &m_book;
+ }
+
+ Q_ASSERT(t);
+ if (!t->keyChooser) { //was deleted, create a new one
+ t->keyChooser = new KShortcutsEditor(
+ m_keyChooserStack
+ );
+ t->keyChooser->addCollection(
+ t->actionCollection,
+ t->title
+ );
+ }
+
+ m_keyChooserStack->setCurrentWidget(t->keyChooser);
+ qDebug("CAcceleratorSettingsPage::slotKeyChooserTypeChanged end");
+}
diff --git a/src/frontend/settingsdialogs/cacceleratorsettings.h.OFF b/src/frontend/settingsdialogs/cacceleratorsettings.h.OFF
new file mode 100644
index 0000000..adf0b95
--- /dev/null
+++ b/src/frontend/settingsdialogs/cacceleratorsettings.h.OFF
@@ -0,0 +1,72 @@
+//
+// C++ Interface: cacceleratorsettings
+//
+// Description:
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 1999-2008
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef CACCELERATORSETTINGS_H
+#define CACCELERATORSETTINGS_H
+
+#include <QWidget>
+#include <QPointer>
+
+#include <kshortcutseditor.h>
+
+class QComboBox;
+class QStackedWidget;
+class KActionCollection;
+
+/**
+ @author The BibleTime team <info@bibletime.info>
+*/
+class CAcceleratorSettingsPage : public QWidget
+{
+ Q_OBJECT
+
+public:
+ CAcceleratorSettingsPage(QWidget *parent);
+
+ ~CAcceleratorSettingsPage();
+
+ void save();
+
+protected slots:
+
+ void slotKeyChooserTypeChanged(const QString& title);
+
+private:
+
+ struct WindowType {
+ QPointer<KShortcutsEditor> keyChooser;
+ KActionCollection* actionCollection;
+ QString title;
+
+ WindowType() {
+ keyChooser = 0;
+ actionCollection = 0;
+ };
+ WindowType(const QString& newTitle) {
+ title = newTitle;
+ keyChooser = 0;
+ actionCollection = 0;
+ }
+ };
+
+ WindowType m_application;
+ WindowType m_general;
+ WindowType m_bible;
+ WindowType m_commentary;
+ WindowType m_lexicon;
+ WindowType m_book;
+
+ QComboBox* m_typeChooser;
+ QStackedWidget* m_keyChooserStack;
+
+};
+
+#endif
diff --git a/src/frontend/settingsdialogs/cconfigurationdialog.cpp b/src/frontend/settingsdialogs/cconfigurationdialog.cpp
new file mode 100644
index 0000000..f3bf536
--- /dev/null
+++ b/src/frontend/settingsdialogs/cconfigurationdialog.cpp
@@ -0,0 +1,93 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cconfigurationdialog.h"
+
+#include "cdisplaysettings.h"
+#include "cswordsettings.h"
+#include "clanguagesettings.h"
+//#include "cacceleratorsettings.h"
+
+#include "util/cpointers.h"
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+#include "util/dialogutil.h"
+
+#include <QWidget>
+#include <QDialogButtonBox>
+#include <QAbstractButton>
+#include <QPushButton>
+#include <QLayout>
+
+CConfigurationDialog::CConfigurationDialog(QWidget * parent, BtActionCollection* actionCollection )
+ : BtConfigDialog(parent),
+ m_actionCollection(actionCollection),
+ m_displayPage(0),
+ m_swordPage(0),
+ m_acceleratorsPage(0),
+ m_languagesPage(0),
+ m_bbox(0)
+{
+ setWindowTitle(tr("Configure BibleTime"));
+ setAttribute(Qt::WA_DeleteOnClose);
+
+ // Add "Display" page
+ m_displayPage = new CDisplaySettingsPage(this);
+ addPage(m_displayPage);
+
+ // Add "Desk" (sword) page
+ m_swordPage = new CSwordSettingsPage(this);
+ addPage(m_swordPage);
+
+ // Add "Languages" (fonts) page
+ m_languagesPage = new CLanguageSettingsPage(this);
+ addPage(m_languagesPage);
+
+// // Add "Keyboard" (accelerators) page
+// m_acceleratorsPage = new CAcceleratorSettingsPage(this);
+// KPageWidgetItem* accelPage = new KPageWidgetItem(m_acceleratorsPage);
+// accelPage->setHeader( tr( "HotKeys" ) );
+// accelPage->setName( tr( "HotKeys" ) );
+// accelPage->setIcon( KIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::settings::keys::icon)) );
+// addPage(accelPage);
+
+ // Dialog buttons
+ m_bbox = new QDialogButtonBox(this);
+ m_bbox->addButton(QDialogButtonBox::Ok);
+ m_bbox->addButton(QDialogButtonBox::Apply);
+ m_bbox->addButton(QDialogButtonBox::Cancel);
+ util::prepareDialogBox(m_bbox);
+ addButtonBox(m_bbox);
+ bool ok = connect(m_bbox, SIGNAL(clicked(QAbstractButton *)), SLOT(slotButtonClicked(QAbstractButton *)));
+ Q_ASSERT(ok);
+
+ slotChangePage(0);
+}
+
+CConfigurationDialog::~CConfigurationDialog() {}
+
+/** Called if any button was clicked*/
+void CConfigurationDialog::slotButtonClicked(QAbstractButton* button)
+{
+ if (button == static_cast<QAbstractButton*>(m_bbox->button(QDialogButtonBox::Cancel)))
+ {
+ close();
+ return;
+ }
+
+// m_acceleratorsPage->save();
+ m_languagesPage->save();
+ m_swordPage->save();
+ m_displayPage->save();
+ emit signalSettingsChanged( );
+
+ if (button == static_cast<QAbstractButton*>(m_bbox->button(QDialogButtonBox::Ok)))
+ close();
+}
+
diff --git a/src/frontend/settingsdialogs/cconfigurationdialog.h b/src/frontend/settingsdialogs/cconfigurationdialog.h
new file mode 100644
index 0000000..f7a1718
--- /dev/null
+++ b/src/frontend/settingsdialogs/cconfigurationdialog.h
@@ -0,0 +1,49 @@
+//
+// C++ Interface: cconfigurationdialog
+//
+// Description: BibleTime Configuration dialog.
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 1999-2008
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef CCONFIGURATIONDIALOG_H
+#define CCONFIGURATIONDIALOG_H
+
+#include "frontend/bookshelfmanager/btconfigdialog.h"
+
+class QWidget;
+class QAbstractButton;
+
+class CDisplaySettingsPage;
+class CSwordSettingsPage;
+class CLanguageSettingsPage;
+class CAcceleratorSettingsPage;
+class QDialogButtonBox;
+class BtActionCollection;
+
+class CConfigurationDialog : public BtConfigDialog {
+ Q_OBJECT
+
+public:
+ CConfigurationDialog(QWidget *parent, BtActionCollection* actionCollection);
+ virtual ~CConfigurationDialog();
+protected slots:
+ void slotButtonClicked(QAbstractButton *);
+private:
+ BtActionCollection* m_actionCollection;
+ CDisplaySettingsPage* m_displayPage;
+ CSwordSettingsPage* m_swordPage;
+ CAcceleratorSettingsPage* m_acceleratorsPage;
+ CLanguageSettingsPage* m_languagesPage;
+ QDialogButtonBox* m_bbox;
+
+signals:
+ void signalSettingsChanged();
+};
+
+
+#endif
diff --git a/src/frontend/settingsdialogs/cdisplaysettings.cpp b/src/frontend/settingsdialogs/cdisplaysettings.cpp
new file mode 100644
index 0000000..f04006e
--- /dev/null
+++ b/src/frontend/settingsdialogs/cdisplaysettings.cpp
@@ -0,0 +1,199 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cdisplaysettings.h"
+
+#include "backend/config/cbtconfig.h"
+#include "backend/rendering/cdisplayrendering.h"
+#include "backend/managers/cdisplaytemplatemgr.h"
+
+#include "util/cresmgr.h"
+#include "util/ctoolclass.h"
+#include "util/cpointers.h"
+
+#include <QWebView>
+#include <QCheckBox>
+#include <QComboBox>
+#include <QVBoxLayout>
+#include <QLabel>
+
+// ***********************
+// Container for QWebView to control its size
+class CWebViewerWidget : public QWidget
+{
+ public:
+ CWebViewerWidget(QWidget* parent = 0);
+ ~CWebViewerWidget();
+ virtual QSize sizeHint () const;
+};
+
+CWebViewerWidget::CWebViewerWidget(QWidget* parent)
+ : QWidget(parent)
+{
+}
+
+CWebViewerWidget::~CWebViewerWidget()
+{
+}
+
+QSize CWebViewerWidget::sizeHint () const
+{
+ return QSize(100,100);
+}
+// ************************
+
+/** Initializes the startup section of the OD. */
+CDisplaySettingsPage::CDisplaySettingsPage(QWidget* /*parent*/)
+ : BtConfigPage()
+{
+ QVBoxLayout* layout = new QVBoxLayout(this);
+
+ { //startup logo
+ m_showLogoCheck = new QCheckBox(this);
+ m_showLogoCheck->setText(tr("Show startup logo"));
+ m_showLogoCheck->setToolTip(tr("Show the BibleTime logo on startup"));
+
+ m_showLogoCheck->setChecked(CBTConfig::get(CBTConfig::logo));
+ layout->addWidget(m_showLogoCheck);
+ }
+ layout->addSpacing(20);
+
+ layout->addWidget(
+ CToolClass::explanationLabel(
+ this,
+ tr("Display templates"),
+ tr("Display templates define how text is displayed.")
+ )
+ );
+
+ QHBoxLayout* hboxlayout = new QHBoxLayout();
+
+ m_styleChooserCombo = new QComboBox( this ); //create first to enable buddy for label
+ connect( m_styleChooserCombo, SIGNAL( activated( int ) ),
+ this, SLOT( updateStylePreview() ) );
+
+ QLabel* availableLabel = new QLabel(tr("Available display styles:"), this);
+ availableLabel->setBuddy(m_styleChooserCombo);
+ hboxlayout->addWidget(availableLabel);
+ hboxlayout->addWidget( m_styleChooserCombo );
+ hboxlayout->addStretch();
+ layout->addLayout( hboxlayout );
+
+ QWidget* webViewWidget = new CWebViewerWidget(this);
+ QLayout* webViewLayout = new QVBoxLayout(webViewWidget);
+ m_stylePreviewViewer = new QWebView(webViewWidget);
+ QLabel* previewLabel = new QLabel(tr("Style preview"), webViewWidget);
+ previewLabel->setBuddy(m_stylePreviewViewer);
+ webViewLayout->addWidget(previewLabel);
+ webViewLayout->addWidget(m_stylePreviewViewer);
+ webViewWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
+ layout->addWidget(webViewWidget);
+
+ m_styleChooserCombo->addItems(
+ CPointers::displayTemplateManager()->availableTemplates()
+ );
+
+ for (int i = 0; i < m_styleChooserCombo->count(); ++i)
+ {
+ if ( m_styleChooserCombo->itemText(i) == CBTConfig::get(CBTConfig::displayStyle) )
+ {
+ m_styleChooserCombo->setCurrentIndex( i );
+ break;
+ }
+ }
+
+ updateStylePreview(); //render it
+}
+
+
+void CDisplaySettingsPage::updateStylePreview()
+{
+ //update the style preview widget
+ qDebug("CDisplaySettingsPage::updateStylePreview");
+ using namespace Rendering;
+
+ const QString styleName = m_styleChooserCombo->currentText();
+ qDebug() << "style name: " << styleName;
+ CTextRendering::KeyTree tree;
+
+ CTextRendering::KeyTreeItem::Settings settings;
+ settings.highlight = false;
+
+ tree.append( new CTextRendering::KeyTreeItem(
+ QString("\n<span class=\"entryname\"><a name=\"John316\" href=\"sword://Bible/WEB/John 3:16\">16</a></span>%1")
+ .arg(tr("For God so loved the world, that he gave his one and only Son, that whoever believes in him should not perish, but have eternal life.")),
+ settings));
+
+ settings.highlight = true;
+
+ tree.append( new CTextRendering::KeyTreeItem(
+ QString("\n<span class=\"entryname\"><a name=\"John317\" href=\"sword://Bible/WEB/John 3:17\">17</a></span>%1")
+ .arg(tr("For God didn't send his Son into the world to judge the world, but that the world should be saved through him.")),
+ settings));
+
+ settings.highlight = false;
+
+ tree.append( new CTextRendering::KeyTreeItem(
+ QString("\n<span class=\"entryname\"><a name=\"John318\" href=\"sword://Bible/WEB/John 3:18\">18</a></span>%1")
+ .arg(tr("He who believes in him is not judged. He who doesn't believe has been judged already, because he has not believed in the name of the one and only Son of God.")),
+ settings) );
+
+ tree.append( new CTextRendering::KeyTreeItem(
+ QString("\n<span class=\"entryname\"><a name=\"John319\" href=\"sword://Bible/WEB/John 3:19\">19</a></span>%1")
+ .arg(tr("This is the judgment, that the light has come into the world, and men loved the darkness rather than the light; for their works were evil.")),
+ settings));
+
+ tree.append( new CTextRendering::KeyTreeItem(
+ QString("\n<span class=\"entryname\"><a name=\"John320\" href=\"sword://Bible/WEB/John 3:20\">20</a></span>%1<br/>")
+ .arg(tr("For everyone who does evil hates the light, and doesn't come to the light, lest his works would be exposed.")),
+ settings));
+
+ tree.append( new CTextRendering::KeyTreeItem(
+ QString("\n<span class=\"entryname\"><a name=\"John321\" href=\"sword://Bible/WEB/John 3:21\">21</a></span>%1")
+ .arg(tr("But he who does the truth comes to the light, that his works may be revealed, that they have been done in God.")),
+ settings));
+
+ const QString oldStyleName = CBTConfig::get
+ (CBTConfig::displayStyle);
+ //qDebug() << "old style name: " << oldStyleName;
+ CBTConfig::set
+ (CBTConfig::displayStyle, styleName);
+ //qDebug() << "new style name: " << CBTConfig::get(CBTConfig::displayStyle);
+ CDisplayRendering render;
+ m_stylePreviewViewer->setHtml( render.renderKeyTree(tree));
+
+ CBTConfig::set
+ (CBTConfig::displayStyle, oldStyleName);
+ qDebug("CDisplaySettingsPage::updateStylePreview end");
+}
+
+void CDisplaySettingsPage::save()
+{
+ CBTConfig::set
+ ( CBTConfig::logo, m_showLogoCheck->isChecked() );
+ CBTConfig::set
+ ( CBTConfig::displayStyle, m_styleChooserCombo->currentText() );
+}
+
+// implement the BtConfigPage methods
+
+QString CDisplaySettingsPage::iconName()
+{
+ return CResMgr::settings::startup::icon;
+}
+QString CDisplaySettingsPage::label()
+{
+ //: Empty string, don't translate
+ return tr("");
+}
+QString CDisplaySettingsPage::header()
+{
+ return tr("Display");
+}
+
diff --git a/src/frontend/settingsdialogs/cdisplaysettings.h b/src/frontend/settingsdialogs/cdisplaysettings.h
new file mode 100644
index 0000000..faa929b
--- /dev/null
+++ b/src/frontend/settingsdialogs/cdisplaysettings.h
@@ -0,0 +1,43 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+
+#ifndef CDISPLAYSETTINGS_H
+#define CDISPLAYSETTINGS_H
+
+#include "frontend/bookshelfmanager/btconfigdialog.h"
+
+#include <QWidget>
+
+class QCheckBox;
+class QComboBox;
+class QWebView;
+
+class CDisplaySettingsPage : public BtConfigPage
+{
+ Q_OBJECT
+
+public:
+ CDisplaySettingsPage(QWidget* parent);
+ void save();
+ QString iconName();
+ QString label();
+ QString header();
+
+protected slots:
+ /** Update the style preview widget. */
+ void updateStylePreview();
+
+private:
+ QCheckBox* m_showLogoCheck;
+ QComboBox* m_styleChooserCombo;
+ QWebView* m_stylePreviewViewer;
+};
+
+#endif
diff --git a/src/frontend/settingsdialogs/cfontchooser.cpp b/src/frontend/settingsdialogs/cfontchooser.cpp
new file mode 100644
index 0000000..f755e57
--- /dev/null
+++ b/src/frontend/settingsdialogs/cfontchooser.cpp
@@ -0,0 +1,359 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cfontchooser.h"
+#include "clistwidget.h"
+#include <QVBoxLayout>
+#include <QLabel>
+#include <QListWidget>
+#include <QFrame>
+#include <QFontDatabase>
+#include <QListWidgetItem>
+#include <QWebSettings>
+#include <QFrame>
+#include <QWebView>
+
+
+// ***********************
+// Container for KHTHMView to control its size
+class WebViewerWidget : public QWidget
+{
+ public:
+ WebViewerWidget(QWidget* parent = 0);
+ ~WebViewerWidget();
+ virtual QSize sizeHint () const;
+};
+
+WebViewerWidget::WebViewerWidget(QWidget* parent)
+ : QWidget(parent)
+{
+}
+
+WebViewerWidget::~WebViewerWidget()
+{
+}
+
+QSize WebViewerWidget::sizeHint () const
+{
+ return QSize(100,85);
+}
+// ************************
+
+
+
+CFontChooser::CFontChooser(QWidget* parent)
+ : QFrame(parent), m_fontWidget(0),
+ m_fontListWidget(0), m_styleListWidget(0), m_sizeListWidget(0)
+{
+ setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+ createLayout();
+ connectListWidgets();
+ loadFonts();
+ setFrameStyle(QFrame::Box);
+ setFrameShadow(QFrame::Raised);
+}
+
+
+CFontChooser::~CFontChooser()
+{
+}
+
+
+void CFontChooser::createFontAreaLayout()
+{
+ QHBoxLayout* fontStyleSizeHBoxLayout = new QHBoxLayout();
+
+ // font column
+ QVBoxLayout* fontLayout = new QVBoxLayout();
+ fontStyleSizeHBoxLayout->addLayout(fontLayout);
+
+ QLabel* fontLabel = new QLabel(tr("Font name:"));
+ fontLayout->addWidget(fontLabel);
+
+ m_fontListWidget = new CListWidget();
+ m_fontListWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
+ fontLayout->addWidget(m_fontListWidget);
+
+ // style column
+ QVBoxLayout* styleLayout = new QVBoxLayout();
+ fontStyleSizeHBoxLayout->addLayout(styleLayout);
+
+ QLabel* styleLabel = new QLabel(tr("Font style:"));
+ styleLayout->addWidget(styleLabel);
+
+ m_styleListWidget = new CListWidget();
+ m_styleListWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
+ m_styleListWidget->setCharWidth(12);
+ styleLayout->addWidget(m_styleListWidget);
+
+ // size column
+ QVBoxLayout* sizeLayout = new QVBoxLayout();
+ fontStyleSizeHBoxLayout->addLayout(sizeLayout);
+
+ QLabel* sizeLabel = new QLabel(tr("Size:"));
+ sizeLayout->addWidget(sizeLabel);
+
+ m_sizeListWidget = new CListWidget();
+ m_sizeListWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
+ m_sizeListWidget->setCharWidth(5);
+ sizeLayout->addWidget(m_sizeListWidget);
+
+ m_vBoxLayout->addLayout(fontStyleSizeHBoxLayout);
+}
+
+
+void CFontChooser::createLayout()
+{
+ m_vBoxLayout = new QVBoxLayout(this);
+ createFontAreaLayout();
+ createTextAreaLayout();
+}
+
+
+void CFontChooser::createTextAreaLayout()
+{
+ QWidget* webViewWidget = new WebViewerWidget(this);
+ QLayout* webViewLayout = new QVBoxLayout(webViewWidget);
+
+ m_webView = new QWebView(webViewWidget);
+ webViewLayout->addWidget(m_webView);
+ m_vBoxLayout->addWidget(webViewWidget);
+}
+
+
+void CFontChooser::connectListWidgets()
+{
+
+ bool ok = connect(
+ m_fontListWidget,
+ SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
+ this,
+ SLOT(fontChanged(QListWidgetItem *, QListWidgetItem *)));
+ Q_ASSERT(ok);
+
+ ok = connect(
+ m_styleListWidget,
+ SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
+ this,
+ SLOT(styleChanged(QListWidgetItem *, QListWidgetItem *)));
+ Q_ASSERT(ok);
+
+ ok = connect(
+ m_sizeListWidget,
+ SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
+ this,
+ SLOT(sizeChanged(QListWidgetItem *, QListWidgetItem *)));
+ Q_ASSERT(ok);
+}
+
+
+void CFontChooser::fontChanged(QListWidgetItem* current, QListWidgetItem* /*previous*/)
+{
+ if (current == 0)
+ return;
+ QString fontFamily = current->text();
+ m_font.setFamily(fontFamily);
+ loadStyles(fontFamily);
+ outputHtmlText();
+ emit fontSelected(m_font);
+}
+
+
+QString CFontChooser::formatAsHtml(const QString& text)
+{
+
+ QString htmlText;
+ htmlText.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+ htmlText.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");
+ htmlText.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n");
+ htmlText.append("<head>\n");
+ htmlText.append(" <style type=\"text/css\">\n");
+ htmlText.append(" *[lang=en] { font-family:#FONT-FAMILY#; font-size:#FONT-SIZE#pt; font-weight:#FONT-WEIGHT#; font-style:#FONT-STYLE#; }\n");
+ htmlText.append(" </style>\n");
+ htmlText.append("</head>\n");
+ htmlText.append("<body>\n");
+ htmlText.append(" <div>\n");
+ htmlText.append(" <div style=\"display: inline;\" lang=\"en\">\n");
+ htmlText.append(text);
+ htmlText.append(" </div>\n");
+ htmlText.append("</body>\n");
+ htmlText.append("</html>\n");
+ return htmlText;
+}
+
+
+void CFontChooser::loadFonts()
+{
+ m_fontListWidget->clear();
+ QFontDatabase database;
+ foreach (QString font, database.families()) {
+ m_fontListWidget->addItem(font);
+ }
+ // This triggers loading the styles for the first font
+ m_fontListWidget->setCurrentRow(0);
+}
+
+
+void CFontChooser::loadStyles(const QString& font)
+{
+ m_styleListWidget->clear();
+ QFontDatabase database;
+ foreach (QString style, database.styles(font))
+ {
+ m_styleListWidget->addItem(style);
+ // This triggers loading the sizes for the first style
+ restoreListWidgetValue(m_styleListWidget,m_choosenStyle);
+ }
+}
+
+
+void CFontChooser::loadSizes(const QString& font, const QString& style)
+{
+
+ QString saveText = saveListWidgetValue(m_sizeListWidget);
+
+ // Put new values into listWidget
+ m_sizeListWidget->clear();
+ QFontDatabase database;
+ foreach (int size, database.pointSizes(font, style))
+ {
+ m_sizeListWidget->addItem(QString::number(size));
+ }
+
+ restoreListWidgetValue(m_sizeListWidget, saveText);
+}
+
+
+void CFontChooser::outputHtmlText()
+{
+ QString text = formatAsHtml(m_htmlText);
+ text.replace("#FONT-FAMILY#", m_font.family());
+ text.replace("#FONT-SIZE#", QString::number(m_font.pointSize()));
+ text.replace("#FONT-WEIGHT#", (m_font.bold() ? "bold" : "normal") );
+ text.replace("#FONT-STYLE#", m_font.italic() ? "italic" : "normal");
+ m_webView->setHtml(text);
+}
+
+
+void CFontChooser::restoreListWidgetValue(QListWidget* listWidget, const QString& value)
+{
+ if (value == "") {
+ listWidget->setCurrentRow(0);
+ return;
+ }
+
+ for (int i=0; i< listWidget->count(); i++)
+ {
+ if (listWidget->item(i)->text() == value)
+ {
+ listWidget->setCurrentRow(i);
+ return;
+ }
+ }
+ listWidget->setCurrentRow(0);
+}
+
+
+QString CFontChooser::saveListWidgetValue(QListWidget* listWidget)
+{
+ QString saveText;
+ int row = listWidget->currentRow();
+ if (row >= 0) {
+ saveText = listWidget->item(row)->text();
+ }
+ return saveText;
+}
+
+
+void CFontChooser::setFont(const QFont& font)
+{
+ disconnect(m_fontListWidget, 0, 0, 0);
+ disconnect(m_styleListWidget, 0, 0, 0);
+ disconnect(m_sizeListWidget, 0, 0, 0);
+
+ // set the font
+ m_font = font;
+ restoreListWidgetValue(m_fontListWidget, m_font.family());
+
+ // set the style
+ loadStyles( m_font.family());
+ QFontDatabase database;
+ QString styleString = database.styleString(m_font);
+ m_choosenStyle = styleString;
+ restoreListWidgetValue(m_styleListWidget, styleString);
+
+ // set the size
+ loadSizes(m_font.family(), styleString);
+ restoreListWidgetValue(m_sizeListWidget, QString::number(m_font.pointSize()) );
+
+ outputHtmlText();
+ connectListWidgets();
+}
+
+
+void CFontChooser::setFontStyle(const QString& styleString, QFont* font)
+{
+ if (styleString.contains("bold",Qt::CaseInsensitive))
+ font->setBold(true);
+ else
+ font->setBold(false);
+
+ if (styleString.contains("italic",Qt::CaseInsensitive) || styleString.contains("oblique",Qt::CaseInsensitive) )
+ font->setItalic(true);
+ else
+ font->setItalic(false);
+}
+
+
+void CFontChooser::setSampleText(const QString& htmlText)
+{
+ m_htmlText = htmlText;
+ outputHtmlText();
+}
+
+
+void CFontChooser::sizeChanged(QListWidgetItem* current, QListWidgetItem* /*previous*/)
+{
+ if (current == 0)
+ return;
+
+ QString size = m_sizeListWidget->currentItem()->text();
+ m_font.setPointSize(size.toInt());
+
+ outputHtmlText();
+ emit fontSelected(m_font);
+}
+
+
+QSize CFontChooser::sizeHint() const
+{
+ return QSize(170,170);
+}
+
+void CFontChooser::styleChanged(QListWidgetItem* current, QListWidgetItem* /*previous*/)
+{
+ if (current == 0)
+ return;
+
+ QString styleString = current->text();
+ setFontStyle(styleString, &m_font);
+
+ // Save style if the user choose it
+ bool focus = m_styleListWidget->hasFocus();
+ if (focus)
+ m_choosenStyle = styleString;
+
+ QString font = m_fontListWidget->currentItem()->text();
+ loadSizes(font, styleString);
+
+ outputHtmlText();
+ emit fontSelected(m_font);
+}
+
+
diff --git a/src/frontend/settingsdialogs/cfontchooser.h b/src/frontend/settingsdialogs/cfontchooser.h
new file mode 100644
index 0000000..028fda9
--- /dev/null
+++ b/src/frontend/settingsdialogs/cfontchooser.h
@@ -0,0 +1,74 @@
+//
+// C++ Interface: CFontChooser
+//
+// Description: BibleTime font chooser
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 1999-2008
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef CFONTCHOOSER_H
+#define CFONTCHOOSER_H
+
+// These following two defines allow chosing between using KDE and
+// Qt only for rendering the preview text
+
+
+#include <QWidget>
+#include <QFrame>
+
+class QString;
+class QFrame;
+class QListWidget;
+class QListWidgetItem;
+class QVBoxLayout;
+class QWebView;
+class CListWidget;
+
+class CFontChooser : public QFrame {
+ Q_OBJECT
+
+public:
+ CFontChooser(QWidget* parent = 0);
+ ~CFontChooser();
+ void setFont(const QFont& font);
+ void setSampleText(const QString& text);
+ QSize sizeHint() const;
+
+private:
+ void createFontAreaLayout();
+ void createLayout();
+ void createTextAreaLayout();
+ void connectListWidgets();
+ QString formatAsHtml(const QString& text);
+ void loadFonts();
+ void loadSizes(const QString& font, const QString& style);
+ void loadStyles(const QString& font);
+ void outputHtmlText();
+ void restoreListWidgetValue(QListWidget* listWidget, const QString& value);
+ QString saveListWidgetValue(QListWidget* listWidget);
+
+ QFrame* m_fontWidget;
+ QWebView* m_webView;
+ CListWidget* m_fontListWidget;
+ CListWidget* m_styleListWidget;
+ CListWidget* m_sizeListWidget;
+ QString m_htmlText;
+ QFont m_font;
+ QVBoxLayout* m_vBoxLayout;
+ QString m_choosenStyle;
+
+private slots:
+ void fontChanged(QListWidgetItem* current, QListWidgetItem* previous);
+ void setFontStyle(const QString& styleString, QFont* font);
+ void sizeChanged(QListWidgetItem* current, QListWidgetItem* previous);
+ void styleChanged(QListWidgetItem* current, QListWidgetItem* previous);
+
+signals:
+ void fontSelected(const QFont&);
+};
+
+#endif
diff --git a/src/frontend/settingsdialogs/clanguagesettings.cpp b/src/frontend/settingsdialogs/clanguagesettings.cpp
new file mode 100644
index 0000000..30d6e6b
--- /dev/null
+++ b/src/frontend/settingsdialogs/clanguagesettings.cpp
@@ -0,0 +1,302 @@
+//
+// C++ Implementation: clanguagesettings
+//
+// Description:
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 1999-2008
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include "clanguagesettings.h"
+
+#include "util/cpointers.h"
+#include "util/ctoolclass.h"
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+
+#include <QWidget>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QComboBox>
+#include <QCheckBox>
+#include <QLabel>
+
+
+#include "cfontchooser.h"
+
+
+//Sword includes
+#include <localemgr.h>
+#include <swlocale.h>
+
+CLanguageSettingsPage::CLanguageSettingsPage(QWidget* /*parent*/)
+ : BtConfigPage()
+{
+
+ QVBoxLayout* layout = new QVBoxLayout(this);
+
+ //Sword locales
+ layout->addWidget(
+ CToolClass::explanationLabel(
+ this,
+ tr(""),
+ tr("Select the language in which the Biblical book names are displayed.")
+ ));
+
+ m_swordLocaleCombo = new QComboBox(this);
+ QLabel* label = new QLabel( tr("Language for names of Bible books:"), this);
+ label->setBuddy(m_swordLocaleCombo);
+ m_swordLocaleCombo->setToolTip(tr("The languages which can be used for the biblical booknames"));
+
+
+ QHBoxLayout* hBoxLayout = new QHBoxLayout();
+ hBoxLayout->addWidget(label);
+ hBoxLayout->addWidget(m_swordLocaleCombo);
+ hBoxLayout->addStretch();
+ layout->addLayout(hBoxLayout);
+
+ QStringList languageNames;
+ languageNames.append( languageMgr()->languageForAbbrev("en_US")->translatedName() );
+
+ std::list<sword::SWBuf> locales = sword::LocaleMgr::getSystemLocaleMgr()->getAvailableLocales();
+ for (std::list<sword::SWBuf>::const_iterator it = locales.begin(); it != locales.end(); it++)
+ {
+ // qWarning("working on %s", (*it).c_str());
+ const CLanguageMgr::Language* const l =
+ CPointers::languageMgr()->languageForAbbrev( sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str())->getName() );
+
+ if (l->isValid())
+ {
+ languageNames.append( l->translatedName() );
+ }
+ else
+ {
+ languageNames.append(
+ sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str())->getDescription()
+ );
+ }
+ } //for
+
+ languageNames.sort();
+ m_swordLocaleCombo->addItems( languageNames );
+
+ const CLanguageMgr::Language* const l =
+ CPointers::languageMgr()->languageForAbbrev( CBTConfig::get(CBTConfig::language) );
+
+ QString currentLanguageName;
+ if ( l->isValid() && languageNames.contains(l->translatedName()) )
+ { //tranlated language name is in the box
+ currentLanguageName = l->translatedName();
+ }
+ else
+ { //a language like "German Abbrevs" might be the language to set
+ sword::SWLocale* locale =
+ sword::LocaleMgr::getSystemLocaleMgr()->getLocale( CBTConfig::get(CBTConfig::language).toLocal8Bit() );
+ if (locale)
+ {
+ currentLanguageName = QString::fromLatin1(locale->getDescription());
+ }
+ }
+
+ if (currentLanguageName.isEmpty())
+ { // set english as default if nothing was chosen
+ Q_ASSERT(languageMgr()->languageForAbbrev("en_US"));
+ currentLanguageName = languageMgr()->languageForAbbrev("en_US")->translatedName();
+ }
+
+ //now set the item with the right name as current item
+ for (int i = 0; i < m_swordLocaleCombo->count(); ++i)
+ {
+ if (currentLanguageName == m_swordLocaleCombo->itemText(i))
+ {
+ m_swordLocaleCombo->setCurrentIndex(i);
+ break; //item found, finish the loop
+ }
+ }
+
+ layout->addSpacing(20);
+
+ //Font settings
+
+ layout->addWidget(
+ CToolClass::explanationLabel(
+ this,
+ tr("Fonts"),
+ tr("You can specify a custom font for each language.")
+ )
+ );
+ QHBoxLayout* hLayout = new QHBoxLayout();
+
+ m_usageCombo = new QComboBox(this);
+ m_usageCombo->setToolTip(tr("The font selection below will apply to all texts in this language"));
+
+ hLayout->addWidget(m_usageCombo);
+
+ CLanguageMgr::LangMap langMap = languageMgr()->availableLanguages();
+
+ for (CLanguageMgr::LangMapIterator it = langMap.constBegin() ; it != langMap.constEnd(); ++it )
+ {
+ const QString name =
+ (*it)->translatedName().isEmpty()
+ ? (*it)->abbrev()
+ : (*it)->translatedName();
+
+ m_fontMap.insert(name, CBTConfig::get(*it) );
+ }
+
+ for( QMap<QString, CBTConfig::FontSettingsPair>::Iterator it = m_fontMap.begin(); it != m_fontMap.end(); ++it )
+ {
+ if ( m_fontMap[it.key()].first )
+ { //show font icon
+ m_usageCombo->addItem(util::filesystem::DirectoryUtil::getIcon("fonts.svg"), it.key() );
+ }
+ else
+ { //don't show icon for font
+ m_usageCombo->addItem(it.key());
+ }
+ }
+
+ m_useOwnFontCheck = new QCheckBox(tr("Use custom font"), this);
+ m_useOwnFontCheck->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+ connect(m_useOwnFontCheck, SIGNAL(toggled(bool)), SLOT(useOwnFontClicked(bool)) );
+ hLayout->addWidget(m_useOwnFontCheck);
+
+ layout->addLayout(hLayout);
+ hLayout->setContentsMargins(0,0,0,0);
+ //#warning TODO: remember the last selected font and jump there.
+
+ m_fontChooser = new CFontChooser(this);
+
+ //TODO: Eeli's wishlist: why not show something relevant here, like a Bible verse in chosen (not tr()'ed!) language?
+ QString sampleText;
+ sampleText.append("1 In the beginning God created the heaven and the earth. ");
+ sampleText.append("2 And the earth was without form, and void; and darkness was on the face of the deep.");
+ sampleText.append(" And the Spirit of God moved on the face of the waters.");
+
+ m_fontChooser->setSampleText(sampleText);
+ layout->addWidget(m_fontChooser);
+
+ connect(m_fontChooser, SIGNAL(fontSelected(const QFont&)), SLOT(newDisplayWindowFontSelected(const QFont&)));
+ connect(m_usageCombo, SIGNAL(activated(const QString&)), SLOT(newDisplayWindowFontAreaSelected(const QString&)));
+
+ m_fontChooser->setFont( m_fontMap[m_usageCombo->currentText()].second );
+ useOwnFontClicked( m_fontMap[m_usageCombo->currentText()].first );
+ m_useOwnFontCheck->setChecked( m_fontMap[m_usageCombo->currentText()].first );
+ m_fontChooser->setMinimumSize(m_fontChooser->sizeHint());
+}
+
+
+CLanguageSettingsPage::~CLanguageSettingsPage()
+{
+}
+
+void CLanguageSettingsPage::save()
+{
+ for(QMap<QString, CBTConfig::FontSettingsPair>::Iterator it = m_fontMap.begin(); it != m_fontMap.end(); ++it )
+ {
+ const CLanguageMgr::Language* const lang = languageMgr()->languageForTranslatedName(it.key());
+ if (!lang->isValid())
+ { //we possibly use a language, for which we have only the abbrev
+ if (!lang->abbrev().isEmpty()) {
+ CLanguageMgr::Language l(it.key(), it.key(), it.key()); //create a temp language
+ CBTConfig::set(&l, it.value());
+ }
+ }
+ else
+ {
+ CBTConfig::set(lang, it.value());
+ }
+ }
+
+
+ QString languageAbbrev;
+
+ const QString currentLanguageName = m_swordLocaleCombo->currentText();
+ const CLanguageMgr::Language* const l = CPointers::languageMgr()->languageForTranslatedName( currentLanguageName );
+
+ if (l && l->isValid())
+ {
+ languageAbbrev = l->abbrev();
+ }
+ else
+ { //it can be the lang abbrev like de_abbrev or the Sword description
+ std::list <sword::SWBuf> locales = sword::LocaleMgr::getSystemLocaleMgr()->getAvailableLocales();
+
+ for (std::list <sword::SWBuf>::iterator it = locales.begin(); it != locales.end(); it++)
+ {
+ sword::SWLocale* locale = sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str());
+ Q_ASSERT(locale);
+
+ if ( locale && (QString::fromLatin1(locale->getDescription()) == currentLanguageName) )
+ {
+ languageAbbrev = QString::fromLatin1(locale->getName()); //we found the abbrevation for the current language
+ break;
+ }
+ }
+
+ if (languageAbbrev.isEmpty())
+ {
+ languageAbbrev = currentLanguageName; //probably a non-standard locale name like de_abbrev
+ }
+ }
+
+ if (!languageAbbrev.isEmpty())
+ {
+ CBTConfig::set(CBTConfig::language, languageAbbrev);
+ }
+}
+
+/** */
+void CLanguageSettingsPage::newDisplayWindowFontSelected(const QFont &newFont)
+{
+ //belongs to the languages/fonts page
+ CBTConfig::FontSettingsPair oldSettings = m_fontMap[ m_usageCombo->currentText() ];
+ m_fontMap.insert( m_usageCombo->currentText(), CBTConfig::FontSettingsPair(oldSettings.first, newFont) );
+}
+
+/** Called when the combobox contents is changed */
+void CLanguageSettingsPage::newDisplayWindowFontAreaSelected(const QString& usage)
+{
+ //belongs to fonts/languages
+ useOwnFontClicked( m_fontMap[usage].first );
+ m_useOwnFontCheck->setChecked( m_fontMap[usage].first );
+
+ m_fontChooser->setFont( m_fontMap[usage].second );
+}
+
+
+/** This slot is called when the "Use own font for language" bo was clicked. */
+void CLanguageSettingsPage::useOwnFontClicked( bool isOn )
+{
+ //belongs to fonts/languages
+
+ m_fontChooser->setEnabled(isOn);
+ m_fontMap[ m_usageCombo->currentText() ].first = isOn;
+
+ if (isOn)
+ { //show font icon
+ m_usageCombo->setItemIcon(m_usageCombo->currentIndex(), util::filesystem::DirectoryUtil::getIcon("fonts.svg") );
+ }
+ else
+ { //don't show
+ m_usageCombo->setItemText(m_usageCombo->currentIndex(), m_usageCombo->currentText() ); //TODO: should this change icon to empty?
+ }
+}
+
+
+QString CLanguageSettingsPage::iconName()
+{
+ return CResMgr::settings::fonts::icon;
+}
+QString CLanguageSettingsPage::label()
+{
+ //: Empty string, don't translate
+ return tr("");
+}
+QString CLanguageSettingsPage::header()
+{
+ return tr("Languages");
+}
diff --git a/src/frontend/settingsdialogs/clanguagesettings.h b/src/frontend/settingsdialogs/clanguagesettings.h
new file mode 100644
index 0000000..cf635d3
--- /dev/null
+++ b/src/frontend/settingsdialogs/clanguagesettings.h
@@ -0,0 +1,65 @@
+//
+// C++ Interface: clanguagesettings
+//
+// Description:
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 1999-2008
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef CLANGUAGESETTINGS_H
+#define CLANGUAGESETTINGS_H
+
+
+#include "util/cpointers.h"
+#include "backend/config/cbtconfig.h"
+#include "frontend/bookshelfmanager/btconfigdialog.h"
+
+#include <QWidget>
+#include <QMap>
+
+class QComboBox;
+class QCheckBox;
+class CFontChooser;
+
+
+/**
+ @author The BibleTime team <info@bibletime.info>
+*/
+class CLanguageSettingsPage : public BtConfigPage, CPointers
+{
+Q_OBJECT
+public:
+ CLanguageSettingsPage(QWidget *parent);
+ ~CLanguageSettingsPage();
+ void save();
+ QString iconName();
+ QString label();
+ QString header();
+
+protected slots:
+ /**
+ * This slot is called when the "Use own font for language" button was clicked.
+ */
+ void useOwnFontClicked(bool);
+ /**
+ * Called when a new font in the fonts page was selected.
+ */
+ void newDisplayWindowFontSelected(const QFont &);
+ /**
+ * Called when the combobox contents is changed
+ */
+ void newDisplayWindowFontAreaSelected(const QString&);
+
+private:
+ QComboBox* m_swordLocaleCombo;
+ QComboBox* m_usageCombo;
+ QCheckBox* m_useOwnFontCheck;
+ CFontChooser* m_fontChooser;
+
+ QMap<QString,CBTConfig::FontSettingsPair> m_fontMap;
+};
+
+#endif
diff --git a/src/frontend/settingsdialogs/clistwidget.cpp b/src/frontend/settingsdialogs/clistwidget.cpp
new file mode 100644
index 0000000..8fdc130
--- /dev/null
+++ b/src/frontend/settingsdialogs/clistwidget.cpp
@@ -0,0 +1,30 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "util/ctoolclass.h"
+#include "clistwidget.h"
+
+CListWidget::CListWidget(QWidget* parent)
+ : QListWidget(parent)
+{
+}
+
+CListWidget::~CListWidget()
+{
+}
+
+QSize CListWidget::sizeHint () const
+{
+ return QSize(100,120);
+}
+
+void CListWidget::setCharWidth(int width)
+{
+ setMaximumWidth(CToolClass::mWidth(this, width));
+}
diff --git a/src/frontend/settingsdialogs/clistwidget.h b/src/frontend/settingsdialogs/clistwidget.h
new file mode 100644
index 0000000..6afd232
--- /dev/null
+++ b/src/frontend/settingsdialogs/clistwidget.h
@@ -0,0 +1,28 @@
+//
+// C++ Interface: CListWidget
+//
+// Description: BibleTime font chooser
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 1999-2008
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef CLISTWIDGET_H
+#define CLISTWIDGET_H
+
+#include <QListWidget>
+
+class CListWidget : public QListWidget {
+ Q_OBJECT
+
+public:
+ CListWidget(QWidget* parent = 0);
+ ~CListWidget();
+ virtual QSize sizeHint () const;
+ void setCharWidth(int width);
+};
+
+#endif
diff --git a/src/frontend/settingsdialogs/cswordsettings.cpp b/src/frontend/settingsdialogs/cswordsettings.cpp
new file mode 100644
index 0000000..29afd17
--- /dev/null
+++ b/src/frontend/settingsdialogs/cswordsettings.cpp
@@ -0,0 +1,423 @@
+//
+// C++ Implementation: cswordsettings
+//
+// Description:
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 1999-2008
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include "cswordsettings.h"
+
+#include "backend/config/cbtconfig.h"
+
+#include "util/cresmgr.h"
+#include "util/ctoolclass.h"
+#include "util/cpointers.h"
+
+#include <QWidget>
+#include <QTabWidget>
+#include <QComboBox>
+#include <QCheckBox>
+#include <QString>
+#include <QGridLayout>
+#include <QVBoxLayout>
+#include <QList>
+#include <QStringList>
+#include <QLabel>
+
+
+
+CSwordSettingsPage::CSwordSettingsPage(QWidget* /*parent*/)
+ : BtConfigPage()
+{
+ QVBoxLayout* vbox = new QVBoxLayout(this);
+ QTabWidget* tabWidget = new QTabWidget();
+ vbox->addWidget(tabWidget);
+ setLayout(vbox);
+
+ m_worksTab = new StandardWorksTab();
+ m_filtersTab = new TextFiltersTab();
+ tabWidget->addTab(m_worksTab, tr("Standard works"));
+ tabWidget->addTab(m_filtersTab, tr("Text filters"));
+}
+
+//Standard works tab
+
+StandardWorksTab::StandardWorksTab()
+ : QWidget(0)
+{
+
+ // move: tabCtl->addTab(currentTab, tr("Standard works"));
+ QGridLayout* gridLayout = new QGridLayout(this); //the last row is for stretching available space
+ gridLayout->setSizeConstraint(QLayout::SetMinimumSize);
+
+ gridLayout->addWidget(
+ CToolClass::explanationLabel(
+ this,
+ tr(""),
+ tr("Standard works are used when no particular work is specified, \
+ for example when a hyperlink into a Bible or lexicon was clicked .")),
+ 0,0,1,2 /*fill the horizontal space*/
+ );
+
+ //Create selection boxes
+
+ m_standardBibleCombo = new QComboBox(this);
+ QLabel* label = new QLabel( tr("Bible:"), this);
+ label->setAlignment(Qt::AlignRight);
+ label->setBuddy(m_standardBibleCombo);
+ ////label->setAutoResize(true); //? not found in docs
+ m_standardBibleCombo->setToolTip(tr("The standard Bible is used when a hyperlink into a Bible is clicked"));
+
+ gridLayout->addWidget(label,1,0);
+ gridLayout->addWidget(m_standardBibleCombo, 1, 1);
+
+ m_standardCommentaryCombo = new QComboBox(this);
+ label = new QLabel( tr("Commentary:"), this);
+ label->setAlignment(Qt::AlignRight);
+ label->setBuddy(m_standardCommentaryCombo);
+ //label->setAutoResize(true);
+ m_standardCommentaryCombo->setToolTip(tr("The standard commentary is used when a hyperlink into a commentary is clicked"));
+
+ gridLayout->addWidget(label, 2, 0);
+ gridLayout->addWidget(m_standardCommentaryCombo, 2, 1);
+
+ m_standardLexiconCombo = new QComboBox(this);
+ label = new QLabel(tr("Lexicon:"), this);
+ label->setAlignment(Qt::AlignRight);
+ label->setBuddy(m_standardLexiconCombo);
+ //label->setAutoResize(true);
+ m_standardLexiconCombo->setToolTip(tr("The standard lexicon is used when a hyperlink into a lexicon is clicked"));
+
+ gridLayout->addWidget(label,3,0);
+ gridLayout->addWidget(m_standardLexiconCombo, 3, 1);
+
+ m_standardDailyDevotionalCombo = new QComboBox(this);
+ label = new QLabel(tr("Daily devotional:"), this);
+ label->setAlignment(Qt::AlignRight);
+ label->setBuddy(m_standardDailyDevotionalCombo);
+ //label->setAutoResize(true);
+ m_standardDailyDevotionalCombo->setToolTip(tr("The standard devotional will be used to display a short start up devotional"));
+
+ gridLayout->addWidget(label,4,0);
+ gridLayout->addWidget(m_standardDailyDevotionalCombo, 4, 1);
+
+ m_standardHebrewStrongCombo = new QComboBox(this);
+ label = new QLabel(tr("Hebrew Strong's lexicon:"), this);
+ label->setAlignment(Qt::AlignRight);
+ label->setBuddy(m_standardHebrewStrongCombo);
+ //label->setAutoResize(true);
+ m_standardHebrewStrongCombo->setToolTip(tr("The standard Hebrew lexicon is used when a hyperlink into a Hebrew lexicon is clicked"));
+
+ gridLayout->addWidget(label, 5, 0);
+ gridLayout->addWidget(m_standardHebrewStrongCombo, 5, 1);
+
+ m_standardGreekStrongCombo = new QComboBox(this);
+ label = new QLabel(tr("Greek Strong's lexicon:"), this);
+ label->setAlignment(Qt::AlignRight);
+ label->setBuddy(m_standardGreekStrongCombo);
+ //label->setAutoResize(true);
+ m_standardGreekStrongCombo->setToolTip(tr("The standard Greek lexicon is used when a hyperlink into a Greek lexicon is clicked"));
+
+ gridLayout->addWidget(label, 6, 0);
+ gridLayout->addWidget(m_standardGreekStrongCombo, 6, 1);
+
+ m_standardHebrewMorphCombo = new QComboBox(this);
+ label = new QLabel( tr("Hebrew morphological lexicon:"), this);
+ label->setAlignment(Qt::AlignRight);
+ label->setBuddy(m_standardHebrewMorphCombo);
+ //label->setAutoResize(true);
+ m_standardHebrewMorphCombo->setToolTip(tr("The standard morphological lexicon for Hebrew texts is used when a hyperlink of a morphological tag in a Hebrew text is clicked"));
+
+ gridLayout->addWidget(label, 7, 0);
+ gridLayout->addWidget(m_standardHebrewMorphCombo, 7, 1);
+
+ m_standardGreekMorphCombo = new QComboBox(this);
+ label = new QLabel(tr("Greek morphological lexicon:"), this);
+ label->setAlignment(Qt::AlignRight);
+ label->setBuddy(m_standardGreekMorphCombo);
+ //label->setAutoResize(true);
+ m_standardGreekMorphCombo->setToolTip(tr("The standard morphological lexicon for Greek texts is used when a hyperlink of a morphological tag in a Greek text is clicked"));
+
+ gridLayout->addWidget(label, 8, 0);
+ gridLayout->addWidget(m_standardGreekMorphCombo, 8, 1);
+
+ gridLayout->setRowStretch(9,5);
+
+ //fill the comboboxes with the right modules
+
+ QList<CSwordModuleInfo*>& modules = backend()->moduleList();
+ QString modDescript;
+ QList<CSwordModuleInfo*>::iterator end_it = modules.end();
+ for (QList<CSwordModuleInfo*>::iterator it(modules.begin()); it != end_it; ++it)
+ {
+ modDescript = (*it)->config(CSwordModuleInfo::Description);
+
+ switch ((*it)->type())
+ {
+ case CSwordModuleInfo::Bible:
+ m_standardBibleCombo->addItem(modDescript);
+ break;
+ case CSwordModuleInfo::Commentary:
+ m_standardCommentaryCombo->addItem(modDescript);
+ break;
+ case CSwordModuleInfo::Lexicon:
+ {
+ bool inserted = false;
+ if ((*it)->has(CSwordModuleInfo::HebrewDef))
+ {
+ m_standardHebrewStrongCombo->addItem(modDescript);
+ inserted = true;
+ }
+ if ((*it)->has(CSwordModuleInfo::GreekDef))
+ {
+ m_standardGreekStrongCombo->addItem(modDescript);
+ inserted = true;
+ }
+ if ((*it)->has(CSwordModuleInfo::HebrewParse))
+ {
+ m_standardHebrewMorphCombo->addItem(modDescript);
+ inserted = true;
+ }
+ if ((*it)->has(CSwordModuleInfo::GreekParse))
+ {
+ m_standardGreekMorphCombo->addItem(modDescript);
+ inserted = true;
+ }
+ if ((*it)->category() == CSwordModuleInfo::DailyDevotional)
+ {
+ m_standardDailyDevotionalCombo->addItem(modDescript);
+ inserted = true;
+ }
+
+ if (!inserted)
+ { //daily dvotionals, striong lexicons etc. are not very useful for word lookups
+ m_standardLexiconCombo->addItem(modDescript);
+ }
+ break;
+ }
+ default://unknown type
+ break;
+ } //switch
+ } //for
+
+ //using two lists and one loop is better than six loops with almost the same code :)
+ QList<QComboBox*> comboList;
+ QStringList moduleList;
+
+ for (int i = 0; i <= (int)CBTConfig::lastModuleType; ++i)
+ {
+ //fill the combobox list in the right order (i.e. same order as the CBTConfig::module enum list)
+ CBTConfig::modules moduleType = (CBTConfig::modules)(i);
+ switch (moduleType)
+ {
+ case CBTConfig::standardBible:
+ comboList.append(m_standardBibleCombo);
+ break;
+ case CBTConfig::standardCommentary:
+ comboList.append(m_standardCommentaryCombo);
+ break;
+ case CBTConfig::standardLexicon:
+ comboList.append(m_standardLexiconCombo);
+ break;
+ case CBTConfig::standardDailyDevotional:
+ comboList.append(m_standardDailyDevotionalCombo);
+ break;
+ case CBTConfig::standardHebrewStrongsLexicon:
+ comboList.append(m_standardHebrewStrongCombo);
+ break;
+ case CBTConfig::standardGreekStrongsLexicon:
+ comboList.append(m_standardGreekStrongCombo);
+ break;
+ case CBTConfig::standardHebrewMorphLexicon:
+ comboList.append(m_standardHebrewMorphCombo);
+ break;
+ case CBTConfig::standardGreekMorphLexicon:
+ comboList.append(m_standardGreekMorphCombo);
+ break;
+ }; //switch
+
+ //fill the module list
+ CSwordModuleInfo* const m = CBTConfig::get( (CBTConfig::modules)(i) );
+ if (m)
+ {
+ moduleList << m->config(CSwordModuleInfo::Description);
+ }
+ else
+ {
+ moduleList << QString::null;
+ }
+ } //for
+
+ QString module = QString::null;
+ int item = 0;
+ int count = 0;
+ QListIterator<QComboBox*> it(comboList);
+ while (it.hasNext())
+ {
+ //for (QComboBox* combo = comboList.first(); combo; combo = comboList.next() )
+ QComboBox* combo = it.next();
+ module = moduleList[comboList.indexOf(combo)];
+ count = combo->count();
+ combo->setMaximumWidth(300);
+
+ for (item = 0; item < count; item++)
+ {
+ if (combo->itemText(item) == module )
+ {
+ combo->setCurrentIndex(item);
+ break;
+ }
+ }
+ }
+}
+
+
+TextFiltersTab::TextFiltersTab()
+{
+ QVBoxLayout* layout = new QVBoxLayout(this);
+ layout->setMargin(5);
+ QWidget* eLabel = CToolClass::explanationLabel(
+ this,
+ tr(""),
+ tr("Filters control the appearance of text. \
+Here you can specify default settings for all filters. \
+You can override these settings in each display window.")
+ );
+ eLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
+ eLabel->setMaximumHeight(50);
+ eLabel->setMinimumWidth(300);
+ layout->setSpacing(2);
+ layout->addWidget(eLabel);
+
+ m_lineBreaksCheck = new QCheckBox(this);
+ m_lineBreaksCheck->setText(tr("Insert line break after each verse"));
+ m_lineBreaksCheck->setChecked(CBTConfig::get(CBTConfig::lineBreaks));
+ layout->addWidget(m_lineBreaksCheck);
+
+ m_verseNumbersCheck = new QCheckBox(this);
+ m_verseNumbersCheck->setText(tr("Show verse numbers"));
+ m_verseNumbersCheck->setChecked(CBTConfig::get(CBTConfig::verseNumbers));
+ layout->addWidget(m_verseNumbersCheck);
+
+ m_headingsCheck = new QCheckBox(this);
+ m_headingsCheck->setText(tr("Show section headings"));
+ m_headingsCheck->setChecked(CBTConfig::get(CBTConfig::headings));
+ layout->addWidget(m_headingsCheck);
+
+
+ m_scriptureReferencesCheck = new QCheckBox(this);
+ m_scriptureReferencesCheck->setText(tr("Show scripture cross-references"));
+ m_scriptureReferencesCheck->setChecked(CBTConfig::get(CBTConfig::scriptureReferences));
+ layout->addWidget(m_scriptureReferencesCheck);
+
+ m_greekAccentsCheck = new QCheckBox(this);
+ m_greekAccentsCheck->setText(tr("Show Greek accents"));
+ m_greekAccentsCheck->setChecked(CBTConfig::get(CBTConfig::greekAccents));
+ layout->addWidget(m_greekAccentsCheck);
+
+ m_hebrewPointsCheck = new QCheckBox(this);
+ m_hebrewPointsCheck->setText(tr("Show Hebrew vowel points"));
+ m_hebrewPointsCheck->setChecked(CBTConfig::get(CBTConfig::hebrewPoints));
+ layout->addWidget(m_hebrewPointsCheck);
+
+ m_hebrewCantillationCheck = new QCheckBox(this);
+ m_hebrewCantillationCheck->setText(tr("Show Hebrew cantillation marks"));
+ m_hebrewCantillationCheck->setChecked(CBTConfig::get(CBTConfig::hebrewCantillation));
+ layout->addWidget(m_hebrewCantillationCheck);
+
+ m_morphSegmentationCheck = new QCheckBox(this);
+ m_morphSegmentationCheck->setText(tr("Show morph segmentation"));
+ m_morphSegmentationCheck->setChecked(CBTConfig::get(CBTConfig::morphSegmentation));
+ layout->addWidget(m_morphSegmentationCheck);
+
+ m_textualVariantsCheck = new QCheckBox(this);
+ m_textualVariantsCheck->setText(tr("Use textual variants"));
+ m_textualVariantsCheck->setChecked(CBTConfig::get(CBTConfig::textualVariants));
+ layout->addWidget(m_textualVariantsCheck);
+
+ layout->addStretch(4);
+}
+
+void CSwordSettingsPage::save()
+{
+ m_worksTab->save();
+ m_filtersTab->save();
+}
+
+QString CSwordSettingsPage::iconName()
+{
+ return CResMgr::settings::sword::icon;
+}
+QString CSwordSettingsPage::label()
+{
+ //: Empty string, don't translate
+ return tr("");
+}
+QString CSwordSettingsPage::header()
+{
+ return tr("Desk");
+}
+
+void StandardWorksTab::save()
+{
+ for (int i = 0; i <= (int)CBTConfig::lastModuleType; ++i)
+ {
+ QString moduleDescription = QString::null;
+
+ CBTConfig::modules moduleType = (CBTConfig::modules)(i);
+ switch (moduleType)
+ {
+ case CBTConfig::standardBible:
+ moduleDescription = m_standardBibleCombo->currentText();
+ break;
+ case CBTConfig::standardCommentary:
+ moduleDescription = m_standardCommentaryCombo->currentText();
+ break;
+ case CBTConfig::standardLexicon:
+ moduleDescription = m_standardLexiconCombo->currentText();
+ break;
+ case CBTConfig::standardDailyDevotional:
+ moduleDescription = m_standardDailyDevotionalCombo->currentText();
+ break;
+ case CBTConfig::standardHebrewStrongsLexicon:
+ moduleDescription = m_standardHebrewStrongCombo->currentText();
+ break;
+ case CBTConfig::standardGreekStrongsLexicon:
+ moduleDescription = m_standardGreekStrongCombo->currentText();
+ break;
+ case CBTConfig::standardHebrewMorphLexicon:
+ moduleDescription = m_standardHebrewMorphCombo->currentText();
+ break;
+ case CBTConfig::standardGreekMorphLexicon:
+ moduleDescription = m_standardGreekMorphCombo->currentText();
+ break;
+ default:
+ qWarning("Unhandled module type.");
+ };
+
+ CSwordModuleInfo* const module = backend()->findModuleByDescription(moduleDescription);
+ CBTConfig::set
+ (moduleType, module);
+ }
+}
+
+
+void TextFiltersTab::save()
+{
+ CBTConfig::set(CBTConfig::lineBreaks, m_lineBreaksCheck->isChecked());
+ CBTConfig::set(CBTConfig::verseNumbers, m_verseNumbersCheck->isChecked());
+ CBTConfig::set(CBTConfig::headings, m_headingsCheck->isChecked());
+ CBTConfig::set(CBTConfig::scriptureReferences, m_scriptureReferencesCheck->isChecked());
+ CBTConfig::set(CBTConfig::hebrewPoints, m_hebrewPointsCheck->isChecked());
+ CBTConfig::set(CBTConfig::hebrewCantillation, m_hebrewCantillationCheck->isChecked());
+ CBTConfig::set(CBTConfig::morphSegmentation, m_morphSegmentationCheck->isChecked());
+ CBTConfig::set(CBTConfig::greekAccents, m_greekAccentsCheck->isChecked());
+ CBTConfig::set(CBTConfig::textualVariants, m_textualVariantsCheck->isChecked());
+}
+
+
diff --git a/src/frontend/settingsdialogs/cswordsettings.h b/src/frontend/settingsdialogs/cswordsettings.h
new file mode 100644
index 0000000..19db47b
--- /dev/null
+++ b/src/frontend/settingsdialogs/cswordsettings.h
@@ -0,0 +1,86 @@
+//
+// C++ Interface: cswordsettings
+//
+// Description: Widgets for "Sword" ("Desk") settings of configuration dialog.
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 1999-2008
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef CSWORDSETTINGS_H
+#define CSWORDSETTINGS_H
+
+#include "frontend/bookshelfmanager/btconfigdialog.h"
+
+#include "util/cpointers.h"
+
+#include <QTabWidget>
+
+
+class QComboBox;
+class QCheckBox;
+
+class StandardWorksTab;
+class TextFiltersTab;
+
+class CSwordSettingsPage : public BtConfigPage
+{
+ Q_OBJECT
+
+public:
+ CSwordSettingsPage(QWidget* parent);
+ void save();
+ QString iconName();
+ QString label();
+ QString header();
+
+private:
+ StandardWorksTab* m_worksTab;
+ TextFiltersTab* m_filtersTab;
+};
+
+//Tab pages. To be used only in Sword settings page.
+
+class StandardWorksTab : public QWidget, CPointers
+{
+ Q_OBJECT
+
+public:
+ StandardWorksTab();
+ void save();
+
+private:
+ QComboBox* m_standardBibleCombo;
+ QComboBox* m_standardCommentaryCombo;
+ QComboBox* m_standardLexiconCombo;
+ QComboBox* m_standardDailyDevotionalCombo;
+ QComboBox* m_standardHebrewStrongCombo;
+ QComboBox* m_standardGreekStrongCombo;
+ QComboBox* m_standardHebrewMorphCombo;
+ QComboBox* m_standardGreekMorphCombo;
+};
+
+class TextFiltersTab : public QWidget
+{
+ Q_OBJECT
+
+public:
+ TextFiltersTab();
+ void save();
+
+private:
+ QCheckBox* m_lineBreaksCheck;
+ QCheckBox* m_verseNumbersCheck;
+ QCheckBox* m_headingsCheck;
+ QCheckBox* m_hebrewPointsCheck;
+ QCheckBox* m_hebrewCantillationCheck;
+ QCheckBox* m_morphSegmentationCheck;
+ QCheckBox* m_greekAccentsCheck;
+ QCheckBox* m_textualVariantsCheck;
+ QCheckBox* m_scriptureReferencesCheck;
+};
+
+#endif
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..ee669d6
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,213 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+//own includes
+#include "bibletimeapp.h"
+#include "bibletime.h"
+#include "bibletime_dbus_adaptor.h"
+
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+#include "util/migrationutil.h"
+
+#include "backend/config/cbtconfig.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <signal.h>
+
+#include <boost/scoped_ptr.hpp>
+
+#include <QLocale>
+#include <QTranslator>
+#include <QDebug>
+#include <QTextCodec>
+#ifndef NO_DBUS
+#include <QDBusConnection>
+#endif
+
+#ifdef BT_ENABLE_TESTING
+#include <QtTest/QtTest>
+#include "tests/bibletime_test.h"
+#endif
+
+using namespace util::filesystem;
+
+bool showDebugMessages = false;
+BibleTime* bibletime_ptr = 0;
+
+void myMessageOutput( QtMsgType type, const char *msg ) {
+ //we use this messagehandler to switch debugging off in final releases
+ switch (type) {
+ case QtDebugMsg:
+ if (showDebugMessages) { //only show messages if they are enabled!
+ fprintf( stderr,"(BibleTime %s) Debug: %s\n", BT_VERSION, msg );
+ }
+ break;
+ case QtWarningMsg:
+ //if (showDebugMessages) //comment out for releases so users don't get our debug warnings
+ fprintf( stderr,"(BibleTime %s) WARNING: %s\n", BT_VERSION, msg );
+ break;
+ case QtFatalMsg:
+ case QtCriticalMsg:
+ fprintf( stderr,"(BibleTime %s) _FATAL_: %s\nPlease report this bug! (http://www.bibletime.info/development_help.html)", BT_VERSION, msg );
+ abort(); // dump core on purpose
+ }
+}
+
+// TODO - redo signal handler
+#if 0
+extern "C" {
+ static void setSignalHandler(void (*handler)(int));
+
+ // Crash recovery signal handler
+ static void signalHandler(int sigId) {
+ setSignalHandler(SIG_DFL);
+ fprintf(stderr, "*** BibleTime got signal %d (Exiting)\n", sigId);
+ // try to cleanup all windows
+ if (CBTConfig::get(CBTConfig::crashedLastTime)) {
+ //crashed this time and the execution before this one, probably a bug which occurs every time
+ CBTConfig::set(CBTConfig::crashedTwoTimes, true);
+ }
+ else {
+ //try to restore next time.
+ CBTConfig::set(CBTConfig::crashedLastTime, true);
+ }
+ if (bibletime_ptr) {
+ bibletime_ptr->saveSettings();
+ fprintf(stderr, "*** Saving seemed to be successful. If restoring does not work on next startup please use the option --ignore-session\n");
+ }
+ ::exit(-1); //exit BibleTime
+ }
+
+ // Crash recovery signal handler
+ static void crashHandler(int sigId) {
+ setSignalHandler(SIG_DFL);
+ fprintf(stderr, "*** BibleTime got signal %d (Crashing). Trying to save settings.\n", sigId);
+ if (CBTConfig::get(CBTConfig::crashedLastTime)) {
+ // crashed this time and the execution before this one,
+ // probably a bug which occurs every time
+ CBTConfig::set(CBTConfig::crashedTwoTimes, true);
+ }
+ else {
+ //try to restore next time.
+ CBTConfig::set(CBTConfig::crashedLastTime, true);
+ }
+ if (bibletime_ptr) {
+ bibletime_ptr->saveSettings();
+ fprintf(stderr, "*** Saving seemed to be successful. If restoring does not work on next startup please use the option --ignore-session\n");
+ }
+ // Return to DrKonqi.
+ }
+
+ static void setSignalHandler(void (*handler)(int)) {
+ signal(SIGKILL, handler);
+ signal(SIGTERM, handler);
+ signal(SIGHUP, handler);
+ KCrash::setEmergencySaveFunction(crashHandler);
+ }
+}
+#endif
+
+
+int main(int argc, char* argv[]) {
+ qInstallMsgHandler( myMessageOutput );
+
+#ifdef BT_ENABLE_TESTING
+ if (QString(argv[1]) == QString("--run-tests"))
+ {
+ BibleTimeTest testClass;
+ return QTest::qExec(&testClass);
+ }
+#endif
+
+#if 0
+ //TODO: port to QT
+ static KCmdLineOptions options;
+ options.add("debug", ki18n("Enable debug messages"),0);
+ options.add("ignore-session", ki18n("Ignore the startup session that was saved when BibleTime was closed the last time."),0);
+ options.add("open-default-bible <key>", ki18n("Open the standard Bible with the given key. Use <random> to open at a random position."),0);
+#endif
+
+
+ BibleTimeApp app(argc, argv); //for QApplication
+ app.setApplicationName("bibletime");
+ app.setApplicationVersion(BT_VERSION);
+
+ // This is needed for languagemgr language names to work, they use \uxxxx escape sequences in string literals
+ QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
+ //first install QT's own translations
+ QTranslator qtTranslator;
+ qtTranslator.load("qt_" + QLocale::system().name());
+ app.installTranslator(&qtTranslator);
+ //then our own
+ QTranslator BibleTimeTranslator;
+ BibleTimeTranslator.load( QString("bibletime_ui_").append(QLocale::system().name()), DirectoryUtil::getLocaleDir().canonicalPath());
+ app.installTranslator(&BibleTimeTranslator);
+
+#if 0
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+ // A binary option (on / off)
+ if (args->isSet("debug")) {
+ showDebugMessages = true;
+ app.setProperty("--debug", true);
+ }
+ if (!args->getOptionList("test").isEmpty()) {
+ QStringList testingFeatures = args->getOptionList("test");
+ foreach (QString feature, testingFeatures) {
+ app.setProperty(feature.toLatin1().data(), true);
+ }
+ }
+#endif
+
+ // This is the QT4 version, will only work if main App is QApplication
+ // A binary option (on / off)
+ if (app.QCoreApplication::arguments().contains("--debug"))
+ {
+ showDebugMessages = true;
+ app.setProperty("--debug", true);
+ }
+ else
+ {
+ app.setProperty("--debug", false);
+ }
+
+ //Migrate configuration data, if neccessary
+ util::MigrationUtil::checkMigration();
+
+// setSignalHandler(signalHandler);
+
+ bibletime_ptr = new BibleTime();
+
+ // a new BibleTime version was installed (maybe a completely new installation)
+ if (CBTConfig::get(CBTConfig::bibletimeVersion) != BT_VERSION) {
+
+ CBTConfig::set(CBTConfig::bibletimeVersion, BT_VERSION);
+ //TODO: unabled temporarily
+ //bibletime_ptr->slotSettingsOptions();
+ bibletime_ptr->slotSettingsOptions();
+ }
+
+ // restore the workspace and process command line options
+ //app.setMainWidget(bibletime_ptr); //no longer used in qt4 (QApplication)
+ bibletime_ptr->show();
+ bibletime_ptr->processCommandline(); //must be done after the bibletime window is visible
+
+#ifndef NO_DBUS
+ new BibleTimeDBusAdaptor(bibletime_ptr);
+ // connect to D-Bus and register as an object:
+ QDBusConnection::sessionBus().registerObject("/BibleTime", bibletime_ptr);
+#endif
+
+ const int ret = app.exec();
+
+ delete bibletime_ptr;
+ return ret;
+}
+
diff --git a/src/tests/backend/config/cbtconfig_test.cpp b/src/tests/backend/config/cbtconfig_test.cpp
new file mode 100644
index 0000000..8fe76d5
--- /dev/null
+++ b/src/tests/backend/config/cbtconfig_test.cpp
@@ -0,0 +1,36 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "tests/bibletime_test.h"
+
+#include "backend/config/cbtconfig.h"
+
+#include <QtTest/QtTest>
+
+
+void BibleTimeTest::frontend_cbtconfig_test()
+{
+ QList<int> value1;
+ value1 << -1 << 0 << 1 << 993738;
+ QString value1String("-1,0,1,993738");
+ QList<int> emptyValue;
+ QString emptyValueString("");
+
+ //conversion checks int-string
+ QCOMPARE(CBTConfig::IntListToString(value1), value1String);
+ QCOMPARE(CBTConfig::IntListToString(emptyValue), emptyValueString);
+
+ //conversion checks string-int
+ QCOMPARE(CBTConfig::StringToIntList(value1String), value1);
+ QCOMPARE(CBTConfig::StringToIntList(emptyValueString), emptyValue);
+
+ //roundtrip checks
+ QCOMPARE(CBTConfig::StringToIntList(CBTConfig::IntListToString(value1)), value1);
+ QCOMPARE(CBTConfig::StringToIntList(CBTConfig::IntListToString(emptyValue)), emptyValue);
+}
diff --git a/src/tests/bibletime_test.cpp b/src/tests/bibletime_test.cpp
new file mode 100644
index 0000000..e27a817
--- /dev/null
+++ b/src/tests/bibletime_test.cpp
@@ -0,0 +1,20 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "bibletime_test.h"
+
+#include <QtTest/QtTest>
+
+void BibleTimeTest::dummyTest()
+{
+ QCOMPARE(QString("Hello").toUpper(), QString("HELLO"));
+}
+
+
+
diff --git a/src/tests/bibletime_test.h b/src/tests/bibletime_test.h
new file mode 100644
index 0000000..a115553
--- /dev/null
+++ b/src/tests/bibletime_test.h
@@ -0,0 +1,28 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BIBLETIME_TEST_H
+#define BIBLETIME_TEST_H
+
+#include <QObject>
+
+class BibleTimeTest: public QObject
+{
+ Q_OBJECT
+
+private slots:
+ //frontend
+ void frontend_cbtconfig_test();
+
+ //dummy test
+ void dummyTest();
+};
+
+
+#endif
diff --git a/src/util/cpointers.cpp b/src/util/cpointers.cpp
new file mode 100644
index 0000000..73c36d4
--- /dev/null
+++ b/src/util/cpointers.cpp
@@ -0,0 +1,55 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cpointers.h"
+
+//BibleTime's backend
+#include "backend/managers/cswordbackend.h"
+#include "backend/managers/cdisplaytemplatemgr.h"
+
+//BibleTime's frontend
+#include "frontend/cprinter.h"
+
+CPointers::PointerCache m_pointerCache;
+
+void CPointers::setBackend(CSwordBackend* const backend) {
+ Q_ASSERT( m_pointerCache.backend == 0);
+ CPointers::deleteBackend();
+ m_pointerCache.backend = backend;
+}
+
+void CPointers::setInfoDisplay(InfoDisplay::CInfoDisplay* const infoDisplay) {
+ Q_ASSERT( m_pointerCache.infoDisplay == 0);
+ m_pointerCache.infoDisplay = infoDisplay;
+}
+
+void CPointers::deleteBackend() {
+ delete m_pointerCache.backend;
+ m_pointerCache.backend = 0;
+}
+
+void CPointers::deleteLanguageMgr() {
+ delete m_pointerCache.langMgr;
+ m_pointerCache.langMgr = 0;
+}
+
+void CPointers::deleteDisplayTemplateMgr() {
+ delete m_pointerCache.displayTemplateMgr;
+ m_pointerCache.displayTemplateMgr = 0;
+}
+
+/** Returns a pointer to the printer object. */
+CDisplayTemplateMgr* CPointers::displayTemplateManager() {
+ if (!m_pointerCache.displayTemplateMgr) {
+ m_pointerCache.displayTemplateMgr = new CDisplayTemplateMgr();
+ }
+
+ return m_pointerCache.displayTemplateMgr;
+}
+
diff --git a/src/util/cpointers.h b/src/util/cpointers.h
new file mode 100644
index 0000000..48ceea0
--- /dev/null
+++ b/src/util/cpointers.h
@@ -0,0 +1,116 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CPOINTERS_H
+#define CPOINTERS_H
+
+//BibleTime includes
+#include "backend/managers/clanguagemgr.h"
+//#include "backend/cdisplaytemplatemgr.h"
+
+class CSwordBackend;
+class CLanguageMgr;
+class CDisplayTemplateMgr;
+
+namespace InfoDisplay {
+ class CInfoDisplay;
+}
+
+/** Holds the pointers to important classes like modules, backend etc.
+*/
+class CPointers {
+protected:
+ friend class BibleTime; //BibleTime may initialize this object
+ friend class BibleTimeApp; //BibleTimeApp may initialize this object
+ friend int main(int argc, char* argv[]); //main may set the printer
+
+ //Empty virtuaual destructor
+ virtual ~CPointers() {}
+
+ /** Set the backend.
+ * @param backend Pointer to the new application-wide Sword backend
+ */
+ static void setBackend(CSwordBackend* const backend);
+ /** Set the info display.
+ * @param iDisplay The pointer to the new info display.
+ */
+ static void setInfoDisplay(InfoDisplay::CInfoDisplay* const iDisplay);
+
+ /** Delete the backend. Should be called by BibleTimeApp,
+ * because the backend should be deleted as late as possible.
+ */
+ static void deleteBackend();
+ /** Delete the printer. Should be called by BibleTimeApp,
+ * because the printer should be deleted as late as possible.
+ */
+ static void deletePrinter();
+ /** Delete the language manager. Should be called by BibleTimeApp,
+ * because the language manager should be deleted as late as possible.
+ */
+ static void deleteLanguageMgr();
+ /** Delete the display template manager. Should be called by BibleTimeApp,
+ * because the template manager should be deleted as late as possible.
+ */
+ static void deleteDisplayTemplateMgr();
+
+public: // Public methods
+ /** Returns a pointer to the backend
+ * @return The backend pointer.
+ */
+ inline static CSwordBackend* backend();
+ /** Returns a pointer to the language manager
+ * @return The language manager
+ */
+ inline static CLanguageMgr* languageMgr();
+ /** Returns a pointer to the info display.
+ * @return The backend pointer.
+ */
+ inline static InfoDisplay::CInfoDisplay* infoDisplay();
+ /** Returns a pointer to the application's display template manager
+ * @return The backend pointer.
+ */
+ static CDisplayTemplateMgr* displayTemplateManager();
+
+ struct PointerCache {
+ PointerCache() {
+ backend = 0;
+ langMgr = 0;
+ infoDisplay = 0;
+ displayTemplateMgr = 0;
+ };
+
+ CSwordBackend* backend;
+ CLanguageMgr* langMgr;
+ InfoDisplay::CInfoDisplay* infoDisplay;
+ CDisplayTemplateMgr* displayTemplateMgr;
+ };
+};
+
+extern CPointers::PointerCache m_pointerCache;
+
+/** Returns a pointer to the backend ... */
+inline CSwordBackend* CPointers::backend() {
+ return m_pointerCache.backend;
+}
+
+/** Returns a pointer to the backend ... */
+inline CLanguageMgr* CPointers::languageMgr() {
+ if (!m_pointerCache.langMgr) {
+ m_pointerCache.langMgr = new CLanguageMgr();
+ }
+ return m_pointerCache.langMgr;
+}
+
+/** Returns a pointer to the printer object. */
+inline InfoDisplay::CInfoDisplay* CPointers::infoDisplay() {
+ return m_pointerCache.infoDisplay;
+}
+
+
+#endif
diff --git a/src/util/cresmgr.cpp b/src/util/cresmgr.cpp
new file mode 100644
index 0000000..1bd51af
--- /dev/null
+++ b/src/util/cresmgr.cpp
@@ -0,0 +1,496 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "cresmgr.h"
+
+#include <QString>
+
+
+namespace CResMgr {
+ namespace modules {
+ namespace bible {
+ const QString icon_unlocked = "bible.svg";
+ const QString icon_locked = "bible_locked.svg";
+ const QString icon_add = "bible_add.svg";
+ } //bible
+ namespace commentary {
+ const QString icon_unlocked = "commentary.svg";
+ const QString icon_locked = "commentary_locked.svg";
+ const QString icon_add = "commentary_add.svg";
+ } //commentary
+ namespace lexicon {
+ const QString icon_unlocked = "lexicon.svg";
+ const QString icon_locked = "lexicon_locked.svg";
+ const QString icon_add = "lexicon_add.svg";
+ }//lexicon
+ namespace book {
+ const QString icon_unlocked = "book.svg";
+ const QString icon_locked = "book_locked.svg";
+ const QString icon_add = "book_add.svg";
+ }//book
+ }//modules
+
+ namespace categories {
+ namespace bibles {
+ const QString icon = "bible.svg";
+ }
+ namespace commentaries {
+ const QString icon = "commentary.svg";
+ }
+ namespace lexicons {
+ const QString icon = "dictionary.svg";
+ }
+ namespace dailydevotional {
+ const QString icon = "calendar.svg";
+ }
+ namespace books {
+ const QString icon = "books.svg";
+ }
+ namespace glossary {
+ const QString icon = "dictionary.svg";
+ }
+ namespace images {
+ const QString icon = "map.svg";
+ }
+ namespace cults {
+ const QString icon = "questionable.svg";
+ }
+ }//categories
+ namespace mainMenu { //Main menu
+
+ namespace view { //Main menu->View
+ namespace showMainIndex {
+ const QString icon = "view_index.svg";
+ const QKeySequence accel(Qt::Key_F9);
+ const char* actionName = "viewMainIndex_action";
+ }
+ namespace showInfoDisplay {
+ const QString icon = "view_mag.svg";
+ const QKeySequence accel(Qt::Key_F8);
+ const char* actionName = "viewInfoDisplay_action";
+ }
+ }//mainMenu::view
+
+ namespace mainIndex {
+ namespace search {
+ const QString icon = "find.svg";
+ const QKeySequence accel(Qt::CTRL + Qt::Key_O);
+ const char* actionName = "mainindex_search_action";
+ }
+ namespace searchdefaultbible {
+ const QString icon = "find.svg";
+ const QKeySequence accel(Qt::CTRL + Qt::ALT + Qt::Key_F);
+ const char* actionName = "mainindex_searchdefaultbible_action";
+ }
+ }//mainMenu::mainIndex
+
+ namespace window { //mainMenu::window
+ namespace loadProfile {
+ const QString icon = "view_profile.svg";
+ const char* actionName = "windowLoadProfile_action";
+ }
+ namespace saveProfile {
+ const QString icon = "view_profile.svg";
+ const char* actionName = "windowSaveProfile_action";
+ }
+ namespace saveToNewProfile {
+ const QString icon = "view_profile.svg";
+ const QKeySequence accel(Qt::CTRL + Qt::ALT + Qt::Key_S);
+ const char* actionName = "windowSaveToNewProfile_action";
+ }
+ namespace deleteProfile {
+ const QString icon = "view_profile.svg";
+ const char* actionName = "windowDeleteProfile_action";
+ }
+ namespace showFullscreen {
+ const QString icon = "window_fullscreen.svg";
+ const QKeySequence accel(Qt::Key_F5);
+ const char* actionName = "windowFullscreen_action";
+ }
+ namespace arrangementMode {
+ const QString icon = "cascade_auto.svg";
+ const QKeySequence accel;
+ const char* actionName = "windowArrangementMode_action";
+
+ namespace manual {
+ const QString icon = "tile.svg";
+ const QKeySequence accel(Qt::CTRL + Qt::ALT + Qt::Key_M);
+ const char* actionName = "windowArrangementManual_action";
+ }
+ namespace autoTileHorizontal {
+ const QString icon = "tile_horiz.svg";
+ const QKeySequence accel(Qt::CTRL + Qt::ALT + Qt::Key_H);
+ const char* actionName = "windowAutoTileHorizontal_action";
+ }
+ namespace autoTileVertical {
+ const QString icon = "tile_vert.svg";
+ const QKeySequence accel(Qt::CTRL + Qt::ALT + Qt::Key_G);
+ const char* actionName = "windowAutoTileVertical_action";
+ }
+ namespace autoCascade {
+ const QString icon = "cascade_auto.svg";
+ const QKeySequence accel(Qt::CTRL + Qt::ALT + Qt::Key_J);
+ const char* actionName = "windowAutoCascade_action";
+ }
+ }
+ namespace tileHorizontal {
+ const QString icon = "tile_horiz.svg";
+ const QKeySequence accel(Qt::CTRL + Qt::Key_H);
+ const char* actionName = "windowTileHorizontal_action";
+ }
+ namespace tileVertical {
+ const QString icon = "tile_vert.svg";
+ const QKeySequence accel(Qt::CTRL + Qt::Key_G);
+ const char* actionName = "windowTileVertical_action";
+ }
+ namespace cascade {
+ const QString icon = "cascade.svg";
+ const QKeySequence accel(Qt::CTRL + Qt::Key_J);
+ const char* actionName = "windowCascade_action";
+ }
+ namespace closeAll {
+ const QString icon = "fileclose.svg";
+ const QKeySequence accel(Qt::CTRL + Qt::ALT + Qt::Key_W);
+ const char* actionName = "windowCloseAll_action";
+ }
+ }//mainMenu::window
+
+ namespace settings { //Main menu->Settings
+ namespace swordSetupDialog {
+ const QString icon = "swordconfig.svg";
+ const QKeySequence accel(Qt::Key_F4);
+ const char* actionName = "options_sword_setup";
+ }
+
+ }//mainMenu::settings
+
+ namespace help { //Main menu->Help
+ namespace handbook {
+ const QString icon = "contents2.svg";
+ const QKeySequence accel(Qt::Key_F1);
+ const char* actionName = "helpHandbook_action";
+ }
+ namespace bibleStudyHowTo {
+ const QString icon = "contents2.svg";
+ const QKeySequence accel(Qt::Key_F2);
+ const char* actionName = "helpHowTo_action";
+ }
+ }//mainMenu::help
+ } //end of mainMenu
+
+ namespace searchdialog {
+ const QString icon = "find.svg";
+ const QString close_icon = "stop.svg";
+ const QString help_icon = "questionmark";
+ const QString chooseworks_icon = "checkbox";
+ const QString setupscope_icon = "configure";
+
+ namespace result {
+ namespace moduleList {
+
+ namespace copyMenu {
+ const QString icon = "edit_copy.svg";
+ }
+ namespace saveMenu {
+ const QString icon = "file_save.svg";
+ }
+ namespace printMenu {
+ const QString icon = "print.svg";
+ }
+ }
+ namespace foundItems {
+
+ namespace copyMenu {
+ const QString icon = "edit_copy.svg";
+ }
+ namespace saveMenu {
+ const QString icon = "file_save.svg";
+ }
+ namespace printMenu {
+ const QString icon = "print.svg";
+ }
+ }
+ }
+ } //searchDialog
+
+ namespace displaywindows {
+/* namespace transliteration {
+ const QString icon = "bt_displaytranslit";
+ }*/
+ namespace displaySettings {
+ const QString icon = "displayconfig.svg";
+ }
+
+ namespace general {
+ namespace search {
+ const QString icon = "find.svg";
+ const QKeySequence accel(Qt::CTRL + Qt::Key_L);
+ const char* actionName = "window_search_action";
+ }
+
+ namespace backInHistory {
+ const QString icon = "back.svg";
+ const QKeySequence accel(Qt::ALT + Qt::Key_Left);
+ const char* actionName = "window_history_back_action";
+ }
+ namespace forwardInHistory {
+ const QString icon = "forward.svg";
+ const QKeySequence accel(Qt::ALT + Qt::Key_Right);
+ const char* actionName = "window_history_forward_action";
+ }
+ namespace findStrongs {
+ const QString icon = "bt_findstrongs.svg";
+ const QKeySequence accel;
+ const char* actionName = "window_find_strongs_action";
+ }
+
+ }
+ namespace bibleWindow {
+ namespace nextBook {
+ const QKeySequence accel(Qt::CTRL + Qt::Key_Y);
+ }
+ namespace previousBook {
+ const QKeySequence accel(Qt::CTRL + Qt::SHIFT + Qt::Key_Y);
+ }
+
+ namespace nextChapter {
+ const QKeySequence accel(Qt::CTRL + Qt::Key_X);
+ }
+ namespace previousChapter {
+ const QKeySequence accel(Qt::CTRL + Qt::SHIFT + Qt::Key_X);
+ }
+ namespace nextVerse {
+ const QKeySequence accel(Qt::CTRL + Qt::Key_V);
+ }
+ namespace previousVerse {
+ const QKeySequence accel(Qt::CTRL + Qt::SHIFT + Qt::Key_V);
+ }
+
+ namespace copyMenu {
+ const QString icon = "edit_copy.svg";
+ }
+ namespace saveMenu {
+ const QString icon = "file_save.svg";
+ }
+ namespace printMenu {
+ const QString icon = "print.svg";
+ }
+ }
+ namespace commentaryWindow {
+ namespace syncWindow {
+ const QString icon = "sync.svg";
+ const QKeySequence accel;
+ const char* actionName = "commentary_syncWindow";
+ }
+ }
+ namespace lexiconWindow {
+ namespace entryList {
+ QString tooltip;
+ }
+ namespace nextEntry {
+ const QKeySequence accel(Qt::CTRL + Qt::Key_V);
+ }
+ namespace previousEntry {
+ const QKeySequence accel(Qt::CTRL + Qt::SHIFT + Qt::Key_V);
+ }
+
+ namespace copyMenu {
+ const QString icon = "edit_copy.svg";
+ }
+ namespace saveMenu {
+ const QString icon = "file_save.svg";
+ }
+ namespace printMenu {
+ const QString icon = "print.svg";
+ }
+ }
+ namespace bookWindow {
+ namespace toggleTree {
+ const QString icon = "view_sidetree.svg";
+ const QKeySequence accel;
+ }
+ }
+
+ namespace writeWindow {
+ namespace saveText {
+ const QString icon = "file_save";
+ const QKeySequence accel;
+ const char* actionName = "writeWindow_saveText";
+ }
+ namespace restoreText {
+ const QString icon = "import.svg";
+ const QKeySequence accel;
+ const char* actionName = "writeWindow_restoreText";
+ }
+ namespace deleteEntry {
+ const QString icon = "edit_delete.svg";
+ const QKeySequence accel;
+ const char* actionName = "writeWindow_deleteEntry";
+ }
+
+ //formatting buttons
+ namespace boldText {
+ const QString icon = "text_bold.svg";
+ const QKeySequence accel;
+ const char* actionName = "writeWindow_boldText";
+ }
+ namespace italicText {
+ const QString icon = "text_italic.svg";
+ const QKeySequence accel;
+ const char* actionName = "writeWindow_italicText";
+ }
+ namespace underlinedText {
+ const QString icon = "text_under.svg";
+ const QKeySequence accel;
+ const char* actionName = "writeWindow_underlineText";
+ }
+
+ namespace alignLeft {
+ const QString icon = "text_leftalign";
+ const QKeySequence accel;
+ const char* actionName = "writeWindow_alignLeft";
+ }
+ namespace alignCenter {
+ const QString icon = "text_center";
+ const QKeySequence accel;
+ const char* actionName = "writeWindow_alignCenter";
+ }
+ namespace alignRight {
+ const QString icon = "text_rightalign";
+ const QKeySequence accel;
+ const char* actionName = "writeWindow_alignRight";
+ }
+ namespace alignJustify {
+ const QString icon = "text_justify";
+ const QKeySequence accel;
+ const char* actionName = "writeWindow_alignJustify";
+ }
+
+ namespace fontFamily {
+ const QKeySequence accel;
+ const char* actionName = "writeWindow_fontFamily";
+ }
+ namespace fontSize {
+ const QKeySequence accel;
+ const char* actionName = "writeWindow_fontSize";
+ }
+ }
+ }//displayWindows
+
+ namespace settings {
+ namespace startup {
+ const QString icon = "startconfig.svg";
+ }
+ namespace fonts {
+ const QString icon = "fonts.svg";
+ }
+ namespace profiles {
+ const QString icon = "view_profile.svg";
+ }
+ namespace sword {
+ const QString icon = "swordconfig.svg";
+
+ }
+ namespace keys {
+ const QString icon = "key_bindings.svg";
+ }
+ }//settings
+
+ namespace mainIndex { // Bookshelf view
+ namespace search {
+ const QString icon = "find.svg";
+ const QKeySequence accel(Qt::CTRL + Qt::ALT + Qt::Key_M);
+ const char* actionName = "GMsearch_action";
+ }
+ namespace newFolder {
+ const QString icon = "folder_new.svg";
+ }
+ namespace changeFolder {
+ const QString icon = "folder.svg";
+ }
+ namespace openedFolder {
+ const QString icon = "folder_open.svg";
+ }
+ namespace closedFolder {
+ const QString icon = "folder.svg";
+ }
+
+ namespace bookmark {
+ const QString icon = "bookmark.svg";
+ }
+ namespace changeBookmark {
+ const QString icon = "bookmark.svg";
+ }
+ namespace importBookmarks {
+ const QString icon = "import.svg";
+ }
+ namespace exportBookmarks {
+ const QString icon = "export.svg";
+ }
+ namespace printBookmarks {
+ const QString icon = "print.svg";
+ }
+ namespace deleteItems {
+ const QString icon = "edit_delete.svg";
+ }
+
+ namespace editModuleMenu {
+ const QString icon = "pencil.svg";
+ }
+ namespace editModulePlain {
+ const QString icon = "pencil.svg";
+ }
+ namespace editModuleHTML {
+ const QString icon = "pencil.svg";
+ }
+
+ namespace unlockModule {
+ const QString icon = "unlock.svg";
+ }
+ namespace aboutModule {
+ const QString icon = "info.svg";
+ }
+ namespace grouping {
+ const QString icon = "view-tree.svg";
+ }
+ }//mainIndex
+
+ namespace bookshelfmgr {
+ namespace installpage {
+ const QString icon = "bible_add";
+ const QString refresh_icon = "refresh";
+ const QString delete_icon = "trash";
+ const QString add_icon = "plus";
+ const QString install_icon = "bible_add";
+ const QString path_icon = "configure";
+ }
+ namespace removepage {
+ const QString icon = "bible_remove";
+ const QString remove_icon = "trash";
+ }
+ namespace indexpage {
+ const QString icon = "document_magnifier";
+ const QString create_icon = "folder_new";
+ const QString delete_icon = "trash";
+ }
+ namespace paths {
+ const QString add_icon = "plus";
+ const QString edit_icon = "pencil";
+ const QString remove_icon = "trash";
+ }
+ }
+
+}
+
+
+
+namespace CResMgr {
+ void init_tr() {
+ } //init_tr()
+} //CResMgr
diff --git a/src/util/cresmgr.h b/src/util/cresmgr.h
new file mode 100644
index 0000000..1fa3953
--- /dev/null
+++ b/src/util/cresmgr.h
@@ -0,0 +1,509 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef CRESMGR_H
+#define CRESMGR_H
+
+//Qt includes
+#include <QString>
+#include <QKeySequence>
+
+/** Provides static functions to easily access the Tooltip texts for all the frontend parts.
+ * @author The BibleTime team
+ */
+namespace CResMgr {
+ void init_tr();
+
+ namespace modules {
+ namespace bible {
+ extern const QString icon_unlocked;
+ extern const QString icon_locked;
+ extern const QString icon_add;
+ }
+ namespace commentary {
+ extern const QString icon_unlocked;
+ extern const QString icon_locked;
+ extern const QString icon_add;
+ }
+ namespace lexicon {
+ extern const QString icon_unlocked;
+ extern const QString icon_locked;
+ extern const QString icon_add;
+ }
+ namespace book {
+ extern const QString icon_unlocked;
+ extern const QString icon_locked;
+ extern const QString icon_add;
+ }
+ }
+
+ namespace categories {
+ namespace bibles {
+ extern const QString icon;
+ }
+ namespace commentaries {
+ extern const QString icon;
+ }
+ namespace lexicons {
+ extern const QString icon;
+ }
+ namespace dailydevotional {
+ extern const QString icon;
+ }
+ namespace books {
+ extern const QString icon;
+ }
+ namespace glossary {
+ extern const QString icon;
+ }
+ namespace images {
+ extern const QString icon;
+ }
+ namespace cults {
+ extern const QString icon;
+ }
+ }
+
+ namespace mainMenu { //Main menu
+
+ namespace view { //Main menu->View
+ namespace showMainIndex {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace showInfoDisplay {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ }
+
+ namespace mainIndex { //configuration for the main index and the view->search menu
+ namespace search {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace searchdefaultbible {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ }
+
+ namespace window { //Main menu->Window
+ namespace loadProfile {
+ extern const QString icon;
+ extern const char* actionName;
+ }
+ namespace saveProfile {
+ extern const QString icon;
+ extern const char* actionName;
+ }
+ namespace saveToNewProfile {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace deleteProfile {
+ extern const QString icon;
+ extern const char* actionName;
+ }
+ namespace showFullscreen {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace arrangementMode {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+
+ namespace manual {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace autoTileVertical {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace autoTileHorizontal {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace autoCascade {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ }
+ namespace tileVertical {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace tileHorizontal {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace cascade {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace closeAll {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ }
+
+ namespace settings { //Main menu->Settings
+ namespace editToolBar { // available as KStdAction
+ }
+ namespace optionsDialog { // available as KStdAction
+ }
+ namespace swordSetupDialog {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ }
+
+ namespace help { //Main menu->Help
+ namespace handbook {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace bibleStudyHowTo {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ }
+ } //end of main menu
+
+ namespace searchdialog {
+ extern const QString icon;
+ extern const QString close_icon;
+ extern const QString help_icon;
+ extern const QString chooseworks_icon;
+ extern const QString setupscope_icon;
+
+ namespace result {
+ namespace moduleList {
+
+ namespace copyMenu {
+ extern const QString icon;
+ }
+ namespace saveMenu {
+ extern const QString icon;
+ }
+ namespace printMenu {
+ extern const QString icon;
+ }
+ }
+ namespace foundItems {
+
+ namespace copyMenu {
+ extern const QString icon;
+ }
+ namespace saveMenu {
+ extern const QString icon;
+ }
+ namespace printMenu {
+ extern const QString icon;
+ }
+
+ }
+ }
+ }
+
+namespace workspace {}
+
+ namespace displaywindows {
+ namespace transliteration {
+ extern const QString icon;
+ }
+ namespace displaySettings {
+ extern const QString icon;
+ }
+
+ namespace general {
+ namespace search {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+
+ namespace backInHistory {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace forwardInHistory {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+
+ namespace findStrongs {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ }
+
+ namespace bibleWindow {
+ namespace nextBook {
+ extern const QKeySequence accel;
+ }
+ namespace previousBook {
+ extern const QKeySequence accel;
+ }
+
+ namespace nextChapter {
+ extern const QKeySequence accel;
+ }
+ namespace previousChapter {
+ extern const QKeySequence accel;
+ }
+
+ namespace nextVerse {
+ extern const QKeySequence accel;
+ }
+ namespace previousVerse {
+ extern const QKeySequence accel;
+ }
+
+ namespace copyMenu {
+ extern const QString icon;
+ }
+ namespace saveMenu {
+ extern const QString icon;
+ }
+ namespace printMenu {
+ extern const QString icon;
+ }
+ }
+ namespace commentaryWindow {
+ namespace syncWindow {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+
+ }
+
+ namespace lexiconWindow {
+ namespace nextEntry {
+ extern const QKeySequence accel;
+ }
+ namespace previousEntry {
+ extern const QKeySequence accel;
+ }
+
+ namespace copyMenu {
+ extern const QString icon;
+ }
+ namespace saveMenu {
+ extern const QString icon;
+ }
+ namespace printMenu {
+ extern const QString icon;
+ }
+ }
+ namespace bookWindow {
+ namespace toggleTree {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ }
+ }
+
+
+ namespace writeWindow {
+ namespace saveText {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace restoreText {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace deleteEntry {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+
+ //formatting buttons
+ namespace boldText {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace italicText {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace underlinedText {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+
+ namespace alignLeft {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace alignCenter {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace alignRight {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace alignJustify {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+
+ namespace fontFamily {
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace fontSize {
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace fontColor {
+ }
+
+ }
+ }
+
+ namespace settings {
+ namespace startup {
+ extern const QString icon;
+ }
+ namespace fonts {
+ extern const QString icon;
+ }
+ namespace profiles {
+ extern const QString icon;
+ }
+ namespace sword {
+ extern const QString icon;
+
+ }
+ namespace keys {
+ extern const QString icon;
+ }
+ }
+
+ namespace mainIndex { //configuration for the main index and the view->search menu
+ namespace search {
+ extern const QString icon;
+ extern const QKeySequence accel;
+ extern const char* actionName;
+ }
+ namespace newFolder {
+ extern const QString icon;
+ }
+ namespace changeFolder {
+ extern const QString icon;
+ }
+ namespace openedFolder {
+ extern const QString icon;
+ }
+ namespace closedFolder {
+ extern const QString icon;
+ }
+
+ namespace bookmark {
+ extern const QString icon;
+ }
+ namespace changeBookmark {
+ extern const QString icon;
+ }
+ namespace importBookmarks {
+ extern const QString icon;
+ }
+ namespace exportBookmarks {
+ extern const QString icon;
+ }
+ namespace printBookmarks {
+ extern const QString icon;
+ }
+ namespace deleteItems {
+ extern const QString icon;
+ }
+
+ namespace editModuleMenu {
+ extern const QString icon;
+ }
+ namespace editModulePlain {
+ extern const QString icon;
+ }
+ namespace editModuleHTML {
+ extern const QString icon;
+ }
+
+ namespace unlockModule {
+ extern const QString icon;
+ }
+ namespace aboutModule {
+ extern const QString icon;
+ }
+ namespace grouping {
+ extern const QString icon;
+ }
+ }
+
+ namespace bookshelfmgr {
+ namespace installpage {
+ extern const QString icon;
+ extern const QString refresh_icon;
+ extern const QString delete_icon;
+ extern const QString add_icon;
+ extern const QString install_icon;
+ extern const QString path_icon;
+ }
+ namespace removepage {
+ extern const QString icon;
+ extern const QString remove_icon;
+ }
+ namespace indexpage {
+ extern const QString icon;
+ extern const QString create_icon;
+ extern const QString delete_icon;
+ }
+ namespace paths {
+ extern const QString add_icon;
+ extern const QString edit_icon;
+ extern const QString remove_icon;
+ }
+ }
+}
+
+#endif
diff --git a/src/util/ctoolclass.cpp b/src/util/ctoolclass.cpp
new file mode 100644
index 0000000..c21bfe3
--- /dev/null
+++ b/src/util/ctoolclass.cpp
@@ -0,0 +1,279 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "ctoolclass.h"
+
+#include "util/cresmgr.h"
+#include "util/directoryutil.h"
+#include "backend/managers/cswordbackend.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+
+//Qt
+#include <QLabel>
+#include <QFile>
+#include <QFileDialog>
+#include <QTextStream>
+#include <QRegExp>
+#include <QWidget>
+#include <QApplication>
+#include <QMessageBox>
+
+//KDE includes
+
+
+/** Converts HTML text to plain text */
+QString CToolClass::htmlToText(const QString& html) {
+ QString newText = html;
+ // convert some tags we need in code
+ newText.replace( QRegExp(" "),"#SPACE#" );
+ newText.replace( QRegExp("<br/?>\\s*"), "<br/>\n" );
+ newText.replace( QRegExp("#SPACE#")," " );
+
+ QRegExp re("<.+>");
+ re.setMinimal(true);
+ newText.replace( re,"" );
+ return newText;
+}
+
+/** Converts text to HTML (\n to <BR>) */
+QString CToolClass::textToHTML(const QString& text) {
+ QString newText = text;
+ newText.replace( QRegExp("<BR>\n"),"#NEWLINE#" );
+ newText.replace( QRegExp("\n"),"<BR>\n" );
+ newText.replace( QRegExp("#NEWLINE#"),"<BR>\n");
+ return newText;
+}
+
+/** Creates the file filename and put text into the file.
+ */
+bool CToolClass::savePlainFile( const QString& filename, const QString& text, const bool& forceOverwrite, QTextCodec* fileCodec) {
+ QFile saveFile(filename);
+ bool ret;
+
+ if (saveFile.exists()) {
+ if (!forceOverwrite && QMessageBox::question(0, QObject::tr("Overwrite File?"),
+ QString::fromLatin1("<qt><B>%1</B><BR>%2</qt>")
+ .arg( QObject::tr("The file already exists.") )
+ .arg( QObject::tr("Do you want to overwrite it?")),
+ QMessageBox::Yes|QMessageBox::No,
+ QMessageBox::No) == QMessageBox::No
+ )
+ {
+ return false;
+ }
+ else { //either the user chose yes or forceOverwrite is set
+ saveFile.remove();
+ }
+ }
+
+ if ( saveFile.open(QIODevice::ReadWrite) ) {
+ QTextStream textstream( &saveFile );
+ textstream.setCodec(fileCodec);
+ textstream << text;
+ saveFile.close();
+ ret = true;
+ }
+ else {
+ QMessageBox::critical(0, QObject::tr("Error"),
+ QString::fromLatin1("<qt>%1<BR><B>%2</B></qt>")
+ .arg( QObject::tr("The file couldn't be saved.") )
+ .arg( QObject::tr("Please check permissions etc.")));
+ saveFile.close();
+ ret = false;
+ }
+ return ret;
+}
+
+
+/** Returns the icon used for the module given as aparameter. */
+QIcon CToolClass::getIconForModule( CSwordModuleInfo* module_info ) {
+ return util::filesystem::DirectoryUtil::getIcon(getIconNameForModule(module_info));
+}
+
+/** Returns the name for the icon used for the module given as aparameter. */
+QString CToolClass::getIconNameForModule( CSwordModuleInfo* module_info ) {
+ //qDebug("CToolClass::getIconNameForModule");
+ if (!module_info) return CResMgr::modules::book::icon_locked;
+
+ if (module_info->category() == CSwordModuleInfo::Cult) {
+ return "stop.svg";
+ }
+
+ switch (module_info->type()) {
+ case CSwordModuleInfo::Bible:
+ if (module_info->isLocked())
+ return CResMgr::modules::bible::icon_locked;
+ else
+ return CResMgr::modules::bible::icon_unlocked;
+ break;
+
+ case CSwordModuleInfo::Lexicon:
+ if (module_info->isLocked())
+ return CResMgr::modules::lexicon::icon_locked;
+ else
+ return CResMgr::modules::lexicon::icon_unlocked;
+ break;
+
+ case CSwordModuleInfo::Commentary:
+ if (module_info->isLocked())
+ return CResMgr::modules::commentary::icon_locked;
+ else
+ return CResMgr::modules::commentary::icon_unlocked;
+ break;
+
+ case CSwordModuleInfo::GenericBook:
+ if (module_info->isLocked())
+ return CResMgr::modules::book::icon_locked;
+ else
+ return CResMgr::modules::book::icon_unlocked;
+ break;
+
+ case CSwordModuleInfo::Unknown: //fallback
+ default:
+ if (module_info->isLocked())
+ return CResMgr::modules::book::icon_locked;
+ else
+ return CResMgr::modules::book::icon_unlocked;
+ break;
+ }
+ return CResMgr::modules::book::icon_unlocked;
+}
+
+QLabel* CToolClass::explanationLabel(QWidget* parent, const QString& heading, const QString& text ) {
+ QString br;
+ if (!heading.isEmpty() && !text.isEmpty()) {
+ br = QString::fromLatin1("<span style='white-space:pre'> - </span>");
+ }
+ QLabel* label = new QLabel( QString::fromLatin1("<B>%1</B>%2<small>%3</small>").arg(heading).arg(br).arg(text),parent );
+
+ label->setWordWrap(true);
+ label->setMargin(1);
+ label->setFrameStyle(QFrame::Box | QFrame::Sunken);
+ return label;
+}
+
+/** No descriptions */
+bool CToolClass::inHTMLTag(int pos, QString & text) {
+ int i1=text.lastIndexOf("<",pos);
+ int i2=text.lastIndexOf(">",pos);
+ int i3=text.indexOf(">",pos);
+ int i4=text.indexOf("<",pos);
+
+
+ // if ((i1>0) && (i2==-1)) //we're in th first html tag
+ // i2=i1; // not ncessary, just for explanation
+
+ if ((i3>0) && (i4==-1)) //we're in the last html tag
+ i4=i3+1;
+
+ // qWarning("%d > %d && %d < %d",i1,i2,i3,i4);
+
+ if ( (i1>i2) && (i3<i4) )
+ return true; //yes, we're in a tag
+
+ return false;
+}
+
+QString CToolClass::moduleToolTip(CSwordModuleInfo* module) {
+ Q_ASSERT(module);
+ if (!module) {
+ return QString::null;
+ }
+
+ QString text;
+
+ text = QString("<b>%1</b> ").arg( module->name() )
+ + ((module->category() == CSwordModuleInfo::Cult) ? QString::fromLatin1("<small><b>%1</b></small><br>").arg(QObject::tr("Take care, this work contains cult / questionable material!")) : QString::null);
+
+ text += QString("<small>(") + module->config(CSwordModuleInfo::Description) + QString(")</small><hr>");
+
+ text += QObject::tr("Language") + QString(": %1<br>").arg( module->language()->translatedName() );
+
+ if (module->isEncrypted()) {
+ text += QObject::tr("Unlock key") + QString(": %1<br>")
+ .arg(!module->config(CSwordModuleInfo::CipherKey).isEmpty() ? module->config(CSwordModuleInfo::CipherKey) : QString("<font COLOR=\"red\">%1</font>").arg(QObject::tr("not set")));
+ }
+
+ if (module->hasVersion()) {
+ text += QObject::tr("Version") + QString(": %1<br>").arg( module->config(CSwordModuleInfo::ModuleVersion) );
+ }
+
+ QString options;
+ unsigned int opts;
+ for (opts = CSwordModuleInfo::filterTypesMIN; opts <= CSwordModuleInfo::filterTypesMAX; ++opts) {
+ if (module->has( static_cast<CSwordModuleInfo::FilterTypes>(opts) )) {
+ if (!options.isEmpty()) {
+ options += QString::fromLatin1(", ");
+ }
+
+ options += CSwordBackend::translatedOptionName(
+ static_cast<CSwordModuleInfo::FilterTypes>(opts)
+ );
+ }
+ }
+
+ if (!options.isEmpty()) {
+ text += QObject::tr("Options") + QString::fromLatin1(": <small>") + options + QString("</small>");
+ }
+
+ if (text.right(4) == QString::fromLatin1("<br>")) {
+ text = text.left(text.length()-4);
+ }
+
+ return text;
+}
+
+QString CToolClass::remoteModuleToolTip(CSwordModuleInfo* module, QString localVer) {
+ Q_ASSERT(module);
+ if (!module) {
+ return QString::null;
+ }
+
+ QString text;
+
+ text = QString("<p style='white-space:pre'><b>%1</b> ").arg( module->name() )
+ + ((module->category() == CSwordModuleInfo::Cult) ? QString::fromLatin1("<small><b>%1</b></small><br>").arg(QObject::tr("Take care, this work contains cult / questionable material!")) : QString::null);
+
+ text += QString("<small>(") + module->config(CSwordModuleInfo::Description) + QString(")</small><hr/>");
+
+ if (module->isEncrypted()) {
+ text += QObject::tr("Encrypted - needs unlock key") + QString("<br>");
+ }
+
+ if (!localVer.isEmpty()) {
+ text += QString("<b>") + QObject::tr("Updated version available!") + QString("</b><br>");
+ }
+
+ if (module->hasVersion()) {
+ text += QObject::tr("Version") + QString(": %1").arg( module->config(CSwordModuleInfo::ModuleVersion) );
+ }
+ // if installed already
+ if (!localVer.isEmpty()) {
+ text += QString(" ") + QObject::tr("Installed version") + QString(": %1").arg(localVer);
+ }
+ text += QString("<br>");
+
+ text += QString("<small>(") + QObject::tr("Double click for more information") + QString(")</small></p>");
+
+
+ if (text.right(4) == QString::fromLatin1("<br>")) {
+ text = text.left(text.length()-4);
+ }
+
+ return text;
+}
+
+
+int CToolClass::mWidth(const QWidget* widget, int m)
+{
+ if (widget) {
+ return widget->fontMetrics().width(QString().fill('M', m));
+ }
+ return QApplication::fontMetrics().width(QString().fill('M', m));
+}
diff --git a/src/util/ctoolclass.h b/src/util/ctoolclass.h
new file mode 100644
index 0000000..47ba228
--- /dev/null
+++ b/src/util/ctoolclass.h
@@ -0,0 +1,94 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+#ifndef CTOOLCLASS_H
+#define CTOOLCLASS_H
+
+//Qt
+#include <QString>
+#include <QIcon>
+#include <QTextCodec>
+
+class CSwordModuleInfo;
+class QLabel;
+class QWidget;
+
+/**
+ * Provides some useful functions which would be normally global.
+ *
+ * Some methods,that would be normaly global, but I hate global functions :-)
+ * (the function locateHTML is from Sandy Meier (KDevelop))
+ *
+ * TODO: I think this could be implemented as a namespace:
+ * namespace util { function()...}
+ * And used:
+ * #include "util/util.h"
+ * util::function();
+ * (comment by Eeli)
+ *
+ */
+class CToolClass {
+public:
+ /**
+ * Converts HTML text to plain text.
+ * This function converts some HTML tags in text (e.g. <BR> to \n)
+ * @return The text withput HTML tags and with converted <BR> to \n
+ * @author Joachim Ansorg
+ */
+ static QString htmlToText(const QString&);
+ /**
+ * Converts text to HTML converting some text commands into HTML tags (e.g. \n to <BR>)
+ * @return The HTML formatted text we got after changing \n to <BR>
+ * @author Joachim Ansorg
+ */
+ static QString textToHTML(const QString&);
+ /**
+ * Creates the file filename and put the text of parameter "text" into the file.
+ * @return True if saving was sucessful, otherwise false
+ * @author Joachim Ansorg
+ */
+ static bool savePlainFile( const QString& filename, const QString& text, const bool& forceOverwrite = false, QTextCodec* fileCodec = QTextCodec::codecForLocale());
+ /**
+ * Returns the icon used for the module given as aparameter.
+ */
+ static QIcon getIconForModule( CSwordModuleInfo* );
+ /**
+ * Returns the name for the icon used for the module given as aparameter.
+ */
+ static QString getIconNameForModule( CSwordModuleInfo* );
+
+ /** Returns a label to explain difficult things of dialogs.
+ * This function returns a label with heading "heading" and explanation "text". This label should be used to
+ * explain difficult things of the GUI, e.g. in the optionsdialog.
+ */
+ static QLabel* explanationLabel(QWidget* parent, const QString& heading, const QString& text );
+ /**
+ * Returns true if the character at position "pos" of text is inside an HTML tag. Returns false if it's not inside an HTML tag.
+ */
+ static bool inHTMLTag(int pos, QString & text);
+
+ /** Return the module's tooltip text
+ * @param module The module required for the tooltip
+ * @return The tooltip text for the passed module
+ */
+ static QString moduleToolTip(CSwordModuleInfo* module);
+
+ /** Return the module's tooltip text for a remote module
+ * @param module The module required for the tooltip
+ * @return The tooltip text for the passed module
+ */
+ static QString remoteModuleToolTip(CSwordModuleInfo* module, QString localVer);
+
+ /**
+ * Returns the width in pixels for a string which has mCount 'M' letters, using the specified widget's font.
+ * This can be used when setting the size for a widget. It may be better to roughly calculate the size based on some text width rather than use pixels directly.
+ */
+ static int mWidth(const QWidget* widget, int mCount);
+};
+
+#endif
diff --git a/src/util/dialogutil.cpp b/src/util/dialogutil.cpp
new file mode 100644
index 0000000..e89f881
--- /dev/null
+++ b/src/util/dialogutil.cpp
@@ -0,0 +1,61 @@
+//
+// C++ Interface: dialogutil
+//
+// Description:
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 2009
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#include "dialogutil.h"
+#include <QtGui/QDialogButtonBox>
+#include <QtGui/QPushButton>
+
+namespace util
+{
+
+ static void replaceText(QDialogButtonBox* box, QDialogButtonBox::StandardButton flag, const QString& text)
+ {
+ QPushButton* button = box->button(flag);
+ if (button != 0)
+ button->setText(text);
+ }
+
+ void prepareDialogBox(QDialogButtonBox* box)
+ {
+ //: Standard button
+ replaceText(box, QDialogButtonBox::Ok , QPushButton::tr("OK" , "Dialog Button"));
+ //: Standard button
+ replaceText(box, QDialogButtonBox::Open , QPushButton::tr("Open" , "Dialog Button"));
+ //: Standard button
+ replaceText(box, QDialogButtonBox::Save , QPushButton::tr("Save" , "Dialog Button"));
+ //: Standard button
+ replaceText(box, QDialogButtonBox::Cancel , QPushButton::tr("Cancel" , "Dialog Button"));
+ //: Standard button
+ replaceText(box, QDialogButtonBox::Close , QPushButton::tr("Close" , "Dialog Button"));
+ //: Standard button
+ replaceText(box, QDialogButtonBox::Discard , QPushButton::tr("Discard" , "Dialog Button"));
+ //: Standard button
+ replaceText(box, QDialogButtonBox::Apply , QPushButton::tr("Apply" , "Dialog Button"));
+ //: Standard button
+ replaceText(box, QDialogButtonBox::Reset , QPushButton::tr("Reset" , "Dialog Button"));
+ //: Standard button
+ replaceText(box, QDialogButtonBox::RestoreDefaults, QPushButton::tr("Restore defaults", "Dialog Button"));
+ //: Standard button
+ replaceText(box, QDialogButtonBox::Help , QPushButton::tr("Help" , "Dialog Button"));
+ //: Standard button
+ replaceText(box, QDialogButtonBox::SaveAll , QPushButton::tr("Save All" , "Dialog Button"));
+ //: Standard button
+ replaceText(box, QDialogButtonBox::Yes , QPushButton::tr("Yes" , "Dialog Button"));
+ //: Standard button
+ replaceText(box, QDialogButtonBox::YesToAll, QPushButton::tr("Yes to all", "Dialog Button"));
+ //: Standard button
+ replaceText(box, QDialogButtonBox::No , QPushButton::tr("No" , "Dialog Button"));
+ //: Standard button
+ replaceText(box, QDialogButtonBox::NoToAll , QPushButton::tr("No to all" , "Dialog Button"));
+ }
+
+}
+
diff --git a/src/util/dialogutil.h b/src/util/dialogutil.h
new file mode 100644
index 0000000..e25c931
--- /dev/null
+++ b/src/util/dialogutil.h
@@ -0,0 +1,23 @@
+//
+// C++ Interface: dialogutil
+//
+// Description:
+//
+//
+// Author: The BibleTime team <info@bibletime.info>, (C) 2009
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef UTIL_DIALOG_UTIL_H
+#define UTIL_DIALOG_UTIL_H
+
+class QDialogButtonBox;
+
+namespace util
+{
+ void prepareDialogBox(QDialogButtonBox* box);
+}
+
+#endif
+
diff --git a/src/util/directoryutil.cpp b/src/util/directoryutil.cpp
new file mode 100644
index 0000000..6a1076d
--- /dev/null
+++ b/src/util/directoryutil.cpp
@@ -0,0 +1,368 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "directoryutil.h"
+
+//Qt includes
+#include <QDir>
+#include <QFile>
+#include <QFileInfo>
+#include <QFileInfoList>
+#include <QDebug>
+#include <QCoreApplication>
+#include <QLocale>
+
+namespace util {
+
+namespace filesystem {
+
+void DirectoryUtil::removeRecursive(const QString dir) {
+ //Check for validity of argument
+ if (dir.isEmpty()) return;
+ QDir d(dir);
+ if (!d.exists()) return;
+
+ //remove all files in this dir
+ d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
+ const QFileInfoList fileList = d.entryInfoList();
+ for (QFileInfoList::const_iterator it_file = fileList.begin(); it_file != fileList.end(); it_file++)
+ {
+ d.remove( it_file->fileName() );
+ }
+
+ //remove all subdirs recursively
+ d.setFilter( QDir::Dirs | QDir::NoSymLinks );
+ const QFileInfoList dirList = d.entryInfoList();
+ for (QFileInfoList::const_iterator it_dir = dirList.begin(); it_dir != dirList.end(); it_dir++)
+ {
+ if ( !it_dir->isDir() || it_dir->fileName() == "." || it_dir->fileName() == ".." ) {
+ continue;
+ }
+ removeRecursive( it_dir->absoluteFilePath() );
+ }
+ d.rmdir(dir);
+}
+
+/** Returns the size of the directory including the size of all it's files and it's subdirs.
+ */
+unsigned long DirectoryUtil::getDirSizeRecursive(const QString dir) {
+ //Check for validity of argument
+ QDir d(dir);
+ if (!d.exists()) return 0;
+
+ unsigned long size = 0;
+
+ //First get the size of all files int this folder
+ d.setFilter(QDir::Files);
+ const QFileInfoList infoList = d.entryInfoList();
+ for (QFileInfoList::const_iterator it = infoList.begin(); it != infoList.end(); it++)
+ {
+ size += it->size();
+ }
+
+ //Then add the sizes of all subdirectories
+ d.setFilter(QDir::Dirs);
+ const QFileInfoList dirInfoList = d.entryInfoList();
+ for (QFileInfoList::const_iterator it_dir = dirInfoList.begin(); it_dir != dirInfoList.end(); it_dir++)
+ {
+ if ( !it_dir->isDir() || it_dir->fileName() == "." || it_dir->fileName() == ".." ) {
+ continue;
+ }
+ size += getDirSizeRecursive( it_dir->absoluteFilePath() );
+ }
+ return size;
+}
+
+/**Recursively copies a directory, overwriting existing files*/
+void DirectoryUtil::copyRecursive(QString src, QString dest){
+ QDir srcDir(src);
+ QDir destDir(dest);
+ //Copy files
+ QStringList files = srcDir.entryList(QDir::Files);
+ for (QStringList::iterator it = files.begin(); it != files.end(); ++it){
+ QFile currFile(src + "/" + *it);
+ QString newFileLoc = dest + "/" + *it;
+ QFile newFile(newFileLoc);
+ newFile.remove();
+ currFile.copy(newFileLoc);
+ }
+ QStringList dirs = srcDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
+ for (QStringList::iterator it = dirs.begin(); it != dirs.end(); ++it){
+ QString temp = *it;
+ if (!destDir.cd(*it)){
+ destDir.mkdir(*it);
+ }
+ copyRecursive(src + "/" + *it, dest + "/" + *it);
+ }
+}
+
+static QDir cachedIconDir;
+static QDir cachedJavascriptDir;
+static QDir cachedLicenseDir;
+static QDir cachedPicsDir;
+static QDir cachedLocaleDir;
+static QDir cachedHandbookDir;
+static QDir cachedHowtoDir;
+static QDir cachedDisplayTemplatesDir;
+static QDir cachedUserDisplayTemplatesDir;
+static QDir cachedUserBaseDir;
+static QDir cachedUserHomeDir;
+static QDir cachedUserSessionsDir;
+static QDir cachedUserCacheDir;
+static QDir cachedUserIndexDir;
+
+static bool dirCacheInitialized = false;
+
+void DirectoryUtil::initDirectoryCache(void)
+{
+ QDir wDir( QCoreApplication::applicationDirPath() );
+ wDir.makeAbsolute();
+
+ if (!wDir.cdUp()) //installation prefix
+ {
+ qWarning() << "Cannot cd up from directory " << QCoreApplication::applicationDirPath();
+ throw;
+ }
+
+ cachedIconDir = wDir; //icon dir
+ if (!cachedIconDir.cd("share/bibletime/icons") || !cachedIconDir.isReadable())
+ {
+ qWarning() << "Cannot find icon directory relative to" << QCoreApplication::applicationDirPath();
+ throw;
+ }
+
+ cachedJavascriptDir = wDir;
+ if (!cachedJavascriptDir.cd("share/bibletime/javascript") || !cachedJavascriptDir.isReadable())
+ {
+ qWarning() << "Cannot find javascript directory relative to" << QCoreApplication::applicationDirPath();
+ throw;
+ }
+
+ cachedLicenseDir = wDir;
+ if (!cachedLicenseDir.cd("share/bibletime/license") || !cachedLicenseDir.isReadable())
+ {
+ qWarning() << "Cannot find license directory relative to" << QCoreApplication::applicationDirPath();
+ throw;
+ }
+
+ cachedPicsDir = wDir; //icon dir
+ if (!cachedPicsDir.cd("share/bibletime/pics") || !cachedPicsDir.isReadable())
+ {
+ qWarning() << "Cannot find icon directory relative to" << QCoreApplication::applicationDirPath();
+ throw;
+ }
+
+ cachedLocaleDir = wDir;
+ if (!cachedLocaleDir.cd("share/bibletime/locale")) {
+ qWarning() << "Cannot find locale directory relative to" << QCoreApplication::applicationDirPath();
+ throw;
+ }
+
+ QString localeName = QLocale::system().name();
+ QString langCode = localeName.section('_', 0, 0);
+
+ cachedHandbookDir = wDir;
+ if (!cachedHandbookDir.cd(QString("share/bibletime/docs/handbook/") + localeName)) {
+ if (!cachedHandbookDir.cd(QString("share/bibletime/docs/handbook/") + langCode)) {
+ if (!cachedHandbookDir.cd("share/bibletime/docs/handbook/en/")) {
+ qWarning() << "Cannot find handbook directory relative to" << QCoreApplication::applicationDirPath();
+ throw;
+ }
+ }
+ }
+
+ cachedHowtoDir = wDir;
+ if (!cachedHowtoDir.cd(QString("share/bibletime/docs/howto/") + localeName)) {
+ if (!cachedHowtoDir.cd(QString("share/bibletime/docs/howto/") + langCode)) {
+ if (!cachedHowtoDir.cd("share/bibletime/docs/howto/en/")) {
+ qWarning() << "Cannot find handbook directory relative to" << QCoreApplication::applicationDirPath();
+ throw;
+ }
+ }
+ }
+
+ cachedDisplayTemplatesDir = wDir; //display templates dir
+ if (!cachedDisplayTemplatesDir.cd("share/bibletime/display-templates/")) {
+ qWarning() << "Cannot find display template directory relative to" << QCoreApplication::applicationDirPath();
+ throw;
+ }
+
+ cachedUserHomeDir = QDir::home();
+
+ cachedUserBaseDir = QDir::home();
+ if (!cachedUserBaseDir.cd(".bibletime")){
+ bool success = cachedUserBaseDir.mkdir(".bibletime") && cachedUserBaseDir.cd(".bibletime");
+ if (!success){
+ qWarning() << "Could not create user setting directory.";
+ throw;
+ }
+ }
+
+ cachedUserSessionsDir = cachedUserBaseDir;
+ if (!cachedUserSessionsDir.cd("sessions")){
+ bool success = cachedUserSessionsDir.mkdir("sessions") && cachedUserSessionsDir.cd("sessions");
+ if (!success){
+ qWarning() << "Could not create user sessions directory.";
+ throw;
+ }
+ }
+
+ cachedUserCacheDir = cachedUserBaseDir;
+ if (!cachedUserCacheDir.cd("cache")){
+ bool success = cachedUserCacheDir.mkdir("cache") && cachedUserCacheDir.cd("cache");
+ if (!success){
+ qWarning() << "Could not create user cache directory.";
+ throw;
+ }
+ }
+
+ cachedUserIndexDir = cachedUserBaseDir;
+ if (!cachedUserIndexDir.cd("indices")){
+ bool success = cachedUserIndexDir.mkdir("indices") && cachedUserIndexDir.cd("indices");
+ if (!success){
+ qWarning() << "Could not create user indices directory.";
+ }
+ }
+
+ cachedUserDisplayTemplatesDir = cachedUserBaseDir;
+ if (!cachedUserDisplayTemplatesDir.cd("display-templates")){
+ bool success = cachedUserDisplayTemplatesDir.mkdir("display-templates") && cachedUserDisplayTemplatesDir.cd("display-templates");
+ if (!success){
+ qWarning() << "Could not create user display templates directory.";
+ }
+ }
+
+ dirCacheInitialized = true;
+}
+
+QDir DirectoryUtil::getIconDir(void)
+{
+ if (!dirCacheInitialized) initDirectoryCache();
+ return cachedIconDir;
+}
+
+QDir DirectoryUtil::getJavascriptDir(void)
+{
+ if (!dirCacheInitialized) initDirectoryCache();
+ return cachedJavascriptDir;
+}
+
+QDir DirectoryUtil::getLicenseDir(void)
+{
+ if (!dirCacheInitialized) initDirectoryCache();
+ return cachedLicenseDir;
+}
+
+QIcon DirectoryUtil::getIcon(const QString& name)
+{
+ static QMap<QString, QIcon> iconCache;
+ //error if trying to use name directly...
+ QString name2(name);
+ QString plainName = name2.remove(".svg", Qt::CaseInsensitive);
+ if (iconCache.contains(plainName)) {
+ return iconCache.value(plainName);
+ }
+
+ QString iconDir = getIconDir().canonicalPath();
+ QString iconFileName = iconDir + "/" + plainName + ".svg";
+ if (QFile(iconFileName).exists())
+ {
+ QIcon ic = QIcon(iconFileName);
+ iconCache.insert(plainName, ic);
+ return ic;
+ }
+ else {
+ iconFileName = iconDir + "/" + plainName + ".png";
+ if (QFile(iconFileName).exists()) {
+ QIcon ic = QIcon(iconFileName);
+ iconCache.insert(plainName, ic);
+ return ic;
+ } else {
+ qWarning() << "Cannot find icon file" << iconFileName << ", using default icon.";
+ iconFileName = iconDir + "/" + "/default.svg";
+ if (QFile(iconFileName).exists()) {
+ return QIcon(iconDir + "/default.svg");
+ } else {
+ return QIcon(iconDir + "default.png");
+ }
+ }
+ }
+}
+
+QDir DirectoryUtil::getPicsDir(void)
+{
+ if (!dirCacheInitialized) initDirectoryCache();
+ return cachedPicsDir;
+}
+
+QDir DirectoryUtil::getLocaleDir(void)
+{
+ if (!dirCacheInitialized) initDirectoryCache();
+ return cachedLocaleDir;
+}
+
+QDir DirectoryUtil::getHandbookDir(void)
+{
+ if (!dirCacheInitialized) initDirectoryCache();
+ return cachedHandbookDir;
+}
+
+QDir DirectoryUtil::getHowtoDir(void)
+{
+ if (!dirCacheInitialized) initDirectoryCache();
+ return cachedHowtoDir;
+}
+
+QDir DirectoryUtil::getDisplayTemplatesDir(void)
+{
+ if (!dirCacheInitialized) initDirectoryCache();
+ return cachedDisplayTemplatesDir;
+}
+
+QDir DirectoryUtil::getUserBaseDir(void)
+{
+ if (!dirCacheInitialized) initDirectoryCache();
+ return cachedUserBaseDir;
+}
+
+QDir DirectoryUtil::getUserHomeDir(void)
+{
+ if (!dirCacheInitialized) initDirectoryCache();
+ return cachedUserHomeDir;
+}
+
+QDir DirectoryUtil::getUserSessionsDir(void)
+{
+ if (!dirCacheInitialized) initDirectoryCache();
+ return cachedUserSessionsDir;
+}
+
+QDir DirectoryUtil::getUserCacheDir(void)
+{
+ if (!dirCacheInitialized) initDirectoryCache();
+ return cachedUserCacheDir;
+}
+
+QDir DirectoryUtil::getUserIndexDir(void)
+{
+ if (!dirCacheInitialized) initDirectoryCache();
+ return cachedUserIndexDir;
+}
+
+QDir DirectoryUtil::getUserDisplayTemplatesDir(void)
+{
+ if (!dirCacheInitialized) initDirectoryCache();
+ return cachedUserDisplayTemplatesDir;
+}
+
+
+} //end of namespace util::filesystem
+
+} //end of namespace util
+
diff --git a/src/util/directoryutil.h b/src/util/directoryutil.h
new file mode 100644
index 0000000..be13c79
--- /dev/null
+++ b/src/util/directoryutil.h
@@ -0,0 +1,112 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef UTIL_FILESDIRECTORYUTIL_H
+#define UTIL_FILESDIRECTORYUTIL_H
+
+#include <QString>
+#include <QDir>
+#include <QIcon>
+
+namespace util {
+
+namespace filesystem {
+
+/**
+ * Tools for working with directories.
+ * @author The BibleTime team <info@bibletime.info>
+*/
+class DirectoryUtil {
+private:
+ DirectoryUtil() {};
+ ~DirectoryUtil() {};
+
+public:
+ /** Removes the given dir with all it's files and subdirs.
+ *
+ * TODO: Check if it's suitable for huge dir trees, as it holds a QDir object
+ * for each of it at the same time in the deepest recursion.
+ * For really deep dir tree this may lead to a stack overflow.
+ */
+ static void removeRecursive(const QString dir);
+
+ /** Returns the size of the directory including the size of all its files
+ * and its subdirs.
+ *
+ * TODO: Check if it's suitable for huge dir trees, as it holds a QDir object
+ * for each of it at the same time in the deepest recursion.
+ * For really deep dir tree this may lead to a stack overflow.
+ *
+ * @return The size of the dir in bytes
+ */
+ static unsigned long getDirSizeRecursive(const QString dir);
+
+ /** Recursively copies one directory into another. This WILL OVERWRITE
+ * any existing files of the same name, and WILL NOT handle symlinks.
+ *
+ * This probably won't need to be used for large directory structures.
+ */
+ static void copyRecursive(const QString src, const QString dest);
+
+ /** Return the path to the icons. */
+ static QDir getIconDir(void);
+
+ /** Return the path to the javascript. */
+ static QDir getJavascriptDir(void);
+
+ /** Return the path to the license. */
+ static QDir getLicenseDir(void);
+
+ /** Returns an icon with the given name */
+ static QIcon getIcon(const QString& name);
+
+ /** Return the path to the pictures. */
+ static QDir getPicsDir(void);
+
+ /** Return the path to the translation files. */
+ static QDir getLocaleDir(void);
+
+ /** Return the path to the handbook files, either of the current locale or en as fallback. */
+ static QDir getHandbookDir(void);
+
+ /** Return the path to the bible study howto files, either of the current locale or en as fallback. */
+ static QDir getHowtoDir(void);
+
+ /** Return the path to the default display template files. */
+ static QDir getDisplayTemplatesDir(void);
+
+ /** Return the path to the user's home directory.*/
+ static QDir getUserHomeDir(void);
+
+ /** Return the path to the user's settings directory.*/
+ static QDir getUserBaseDir(void);
+
+ /** Return the path to the user's sessions directory.*/
+ static QDir getUserSessionsDir(void);
+
+ /** Return the path to the user's cache directory.*/
+ static QDir getUserCacheDir(void);
+
+ /** Return the path to the user's indices directory.*/
+ static QDir getUserIndexDir(void);
+
+ /** Return the path to the user's custom display templates directory.*/
+ static QDir getUserDisplayTemplatesDir(void);
+
+private:
+ /** Will cache a few directories like icon directory */
+ static void initDirectoryCache(void);
+
+};
+
+} //namespace filesystem
+
+} //namespace directoryutil
+
+#endif
diff --git a/src/util/exceptions.h b/src/util/exceptions.h
new file mode 100644
index 0000000..2ba8ff3
--- /dev/null
+++ b/src/util/exceptions.h
@@ -0,0 +1,16 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+#ifndef EXCEPTIONS_H
+#define EXCEPTIONS_H
+
+class BTException {};
+
+class BTCLuceneException: public BTException {};
+
+#endif
diff --git a/src/util/migrationutil.cpp b/src/util/migrationutil.cpp
new file mode 100644
index 0000000..072b750
--- /dev/null
+++ b/src/util/migrationutil.cpp
@@ -0,0 +1,92 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "migrationutil.h"
+#include "directoryutil.h"
+#include "backend/config/cbtconfig.h"
+
+#include "swversion.h"
+
+#include <QMessageBox>
+#include <QSettings>
+
+
+using namespace util::filesystem;
+
+namespace util{
+
+void MigrationUtil::checkMigration(){
+ if (CBTConfig::get(CBTConfig::bibletimeVersion) != BT_VERSION)
+ {
+ sword::SWVersion lastVersion(CBTConfig::get(CBTConfig::bibletimeVersion).toUtf8());
+ //lastVersion will be 0.0, if it was an old KDE install,
+ //because the config could not be found yet
+ if (lastVersion < sword::SWVersion("1.7.0") )
+ {
+ tryMigrationFromKDE3(); //
+ }
+ }
+}
+
+//Migration code for KDE 4 port, moves from old config dir to ~/.bibletime/
+void MigrationUtil::tryMigrationFromKDE3(){
+ //List of potential old KDE directories to load data from.
+ QStringList searchDirs;
+ searchDirs << "/.kde" << "/.kde3" << "/.kde3.5";
+ searchDirs << "/.kde3.4" << "/.kde3.3" << "/.kde3.2";
+ searchDirs << "/.kde3.1" << "/.kde3.0";
+
+ foreach (QString searchDir, searchDirs){
+ QString currSearch = QDir::homePath() + searchDir;
+ QDir searchHome(currSearch);
+ QFile oldRc(currSearch + "/share/config/bibletimerc");
+ //Copy our old bibletimerc into the new KDE4 directory.
+ QString newRcLoc = DirectoryUtil::getUserBaseDir().absolutePath() + "/bibletimerc";
+ QFile newRc(newRcLoc);
+
+ //Migrate only if the old config exists and the new doesn't
+ if (oldRc.exists() && !newRc.exists()){
+ QMessageBox msg (QMessageBox::Question, QObject::tr("Settings Migration"),
+ QObject::tr("It appears you have a BibleTime configuration from KDE 3 stored in %1, and you have not migrated it to this version. Would you like to import it?").arg(currSearch), QMessageBox::Yes | QMessageBox::No);
+ int result = msg.exec();
+ if (result != QMessageBox::Yes){
+ break;
+ }
+ oldRc.copy(newRcLoc);
+ QFile oldBookmarks(currSearch + "/share/apps/bibletime/bookmarks.xml");
+ if (oldBookmarks.exists()){
+ QString newBookmarksLoc = DirectoryUtil::getUserBaseDir().absolutePath() + "/" + "bookmarks.xml";
+ QFile newBookmarks(newBookmarksLoc);
+ newBookmarks.remove();
+ oldBookmarks.copy(newBookmarksLoc);
+ }
+ QDir sessionDir(currSearch + "/share/apps/bibletime/sessions");
+ if (sessionDir.exists()){
+ DirectoryUtil::copyRecursive(
+ sessionDir.absolutePath(),
+ DirectoryUtil::getUserSessionsDir().absolutePath());
+ }
+ else{
+ QDir oldSessionDir(currSearch + "/share/apps/bibletime/profiles");
+ if (oldSessionDir.exists()){
+ DirectoryUtil::copyRecursive(
+ oldSessionDir.absolutePath(),
+ DirectoryUtil::getUserSessionsDir().absolutePath());
+ }
+ }
+ //We found at least a config file, so we are done
+ //searching for migration data.
+ break;
+ }
+ }
+ CBTConfig::syncConfig();
+}
+
+}
+
diff --git a/src/util/migrationutil.h b/src/util/migrationutil.h
new file mode 100644
index 0000000..66571ff
--- /dev/null
+++ b/src/util/migrationutil.h
@@ -0,0 +1,39 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2008 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef UTIL_MIGRATIONUTIL_H
+#define UTIL_MIGRATIONUTIL_H
+
+namespace util{
+
+/**
+ * Tools for handling settings migration automatically.
+ * @author The BibleTime team <info@bibletime.info>
+ */
+class MigrationUtil{
+public:
+ /**
+ * Performs any and all applicable migration actions, if neccessary
+ */
+ static void checkMigration();
+private:
+ MigrationUtil() {}; //hide
+ ~MigrationUtil() {}; //hide
+ /*
+ * Performs a migration from a KDE 3 version of BibleTime. It supports all
+ * KDE 3 versions of BibleTime, including versions older than 1.3. Its
+ * only alteration is to move files to the new location, and to rename the
+ * sessions directory from pre-1.3 versions if necessary. It does not
+ * change any settings.
+ */
+ static void tryMigrationFromKDE3();
+};
+
+} //namespace util
+#endif