1 /*********
2 *
3 * In the name of the Father, and of the Son, and of the Holy Spirit.
4 *
5 * This file is part of BibleTime's source code, http://www.bibletime.info/.
6 *
7 * Copyright 1999-2016 by the BibleTime developers.
8 * The BibleTime source code is licensed under the GNU General Public License version 2.0.
9 *
10 **********/
11 
12 #ifndef BIBLETIME_H
13 #define BIBLETIME_H
14 
15 #include <QMainWindow>
16 
17 #include <QList>
18 #include "frontend/displaywindow/cdisplaywindow.h"
19 #include "frontend/displaywindow/cplainwritewindow.h"
20 #include <QSignalMapper>
21 #ifndef NDEBUG
22 #include <QMutex>
23 #endif
24 
25 
26 namespace InfoDisplay {
27 class CInfoDisplay;
28 }
29 class BtActionClass;
30 class BtBookshelfDockWidget;
31 class BtFindWidget;
32 class BtOpenWorkAction;
33 class CBookmarkIndex;
34 class CDisplayWindow;
35 class CMDIArea;
36 class CSwordModuleInfo;
37 class QAction;
38 class QLabel;
39 class QMdiSubWindow;
40 class QMenu;
41 class QActionGroup;
42 class QToolBar;
43 class QSplitter;
44 class QSignalMapper;
45 
46 /**
47   * @page backend The structure of the backend
48   * <p>
49   * The backend implementation for Sword is called CSwordBackend, the classes we use
50   * to work with keys are called CSwordVerseKey and CSwordLDKey, both are derived from
51   * the class CSwordKey.
52   * The CSwordKey derived classes used for Sword do also inherit the classes
53   * VerseKey (CSwordVerseKey)
54   * and SWKey (CSwordLDKey).
55   * </p>
56   * <p>
57   * The classes used to handle all module based stuff are derived from CSwordModuleInfo.
58   * The module classes are: CSwordModuleInfo (for Sword modules),
59   * CSwordBibleModuleInfo (for bibles), CSwordCommentaryModuleInfo (for commentaries) and
60   * CSwordLexiconModuleInfo (for lexicons).
61   * Have a look at the class documentation of the mentioned classes to learn how the
62   * structure of them looks like and which class inherits which other class.
63   * </p>
64   * <p>
65   * The first objects which should be created in the application is the backend
66   * (for Sword the class is called CSwordBackend).
67   * Then create all the different module classes for the correct Sword modules.
68   * Have a look at
69   * BibleTime::initBackens() to see how it's done in BibleTime.@br
70   * Later you can work with them for example by using the CSwordKey and
71   * CSwordModuleInfo derived class.
72   * </p>
73   */
74 
75 /**
76   * @page frontend The structure of the frontend
77   *
78   * <p>
79   * The frontend contains the classes which interact with the user. For example the
80   * display windows, the searchdialog or the other parts.
81   * </p><p>
82   * The display windows which provide functionality are CBibleReadWindow for
83   * Bibles, CBookReadWindow for books, CCommentaryReadWindow for commentaries and CLexiconReadWindow for
84   * lexicon and dictionaries. CHTMLWriteWindow and CPlainWriteWindows are used for editing the Personal Commentary.
85   * </p><p>
86   *
87   * The class CDisplayWindow is the class that various views with in the windows are derived.
88   * </p><p>
89   *
90   * Another important part of the frontend are the keychoosers.
91   * They provide an interface to choose a key of a module.
92   * The interface for different module types is different.
93   * The base class is CKeyChooser which is the factory for the derived classes.
94   * Use the function CKeyChooser::createInstance to get the correct
95   * keychooser implementation for the desired module.<br/>
96   * </p><p>
97   * Some major toolbar widgets are CKeyChooser and BtDisplaySettingsButton.
98   * </p>
99   */
100 
101 /** @mainpage BibleTime - sourcecode documentation
102  * BibleTime main page.
103  * <p>This is the sourcecode documentation of BibleTime, a Bible study tool.
104  * <p>
105  * The main class of BibleTime is called @ref BibleTime, which is the main window
106  * and initializes all important parts at startup.
107  * </p><p>
108  * BibleTime is divided in two major parts, the backend and the frontend.
109  * The text display windows belong to the @ref frontend.
110  * The backend is mainly a wrapper around Sword's classes to use Qt functionality
111  * to allow easy access to it's functionality and to have it in a (more or less :)
112  * object oriented structure.</p><br/>
113  * <p>
114  *       -Introduction to the frontend: @ref frontend.<br/>
115  *       -Introduction to the backend: @ref backend<br/>
116  * </p>
117  */
118 
119 /** BibleTime's main class.
120  * The main class of BibleTime. Here are the main widgets created.
121  *
122  * This is the main class of BibleTime! This class creates the GUI, the QAction objects
123  * and connects to some slots. Please insert the creation of actions in initActions,
124  * the creation of widgets into initView and the connect(...) calls into initConnections.
125  * Reading from a config file on creation time should go into readSettings(), saving into
126  * saveSettings().
127  * This is the general way of all BibleTime classes.
128  */
129 class BibleTime : public QMainWindow {
130         friend class CDisplayWindow;
131         Q_OBJECT
132 
133     public:
134 
135         BibleTime(QWidget *parent = nullptr, Qt::WindowFlags flags = nullptr);
136 
137         ~BibleTime();
138 
instance()139         static inline BibleTime *instance() { return m_instance; }
140 
141         /**
142         *  Save the configuration dialog settings, don't open dialog
143         */
144         void saveConfigSettings();
145         /**
146         * Get pointer to Navigation toolbar
147         */
navToolBar()148         inline QToolBar *navToolBar() const {
149             return m_navToolBar;
150         }
151         /**
152         * Get pointer to Works toolbar
153         */
worksToolBar()154         inline BtModuleChooserBar *worksToolBar() const {
155             return m_worksToolBar;
156         }
157         /**
158         * Get pointer to Tools toolbar
159         */
toolsToolBar()160         inline QToolBar *toolsToolBar() const {
161             return m_toolsToolBar;
162         }
163         /**
164         * Get pointer to Format toolbar
165         */
formatToolBar()166         inline QToolBar *formatToolBar() const {
167             return m_formatToolBar;
168         }
169 
170         /**
171           \returns a pointer to the info display.
172         */
infoDisplay()173         inline InfoDisplay::CInfoDisplay *infoDisplay() const {
174             return m_infoDisplay;
175         }
176 
177         /**
178         * Clears the actions of the MDI related toolbars
179         */
180         void clearMdiToolBars();
181 
182         /**
183         * Returns the main window CKeyChooser
184         */
185         CKeyChooser* keyChooser() const;
186 
187         /**
188           Displays a dialog which asks the user an unlock key for the given module and tries
189           to unlock the module. If an invalid unlock key is given, a warning message is
190           issued and the user is again asked for the key.
191           \param[in] module The module to unlock.
192           \param[in] parent The parent widget for the unlock dialogs.
193           \returns whether the module was successfully unlocked.
194         */
195         static bool moduleUnlock(CSwordModuleInfo *module, QWidget *parent = nullptr);
196 
197         /**
198           Get a pointer to the module associated with the current window
199         */
200         const CSwordModuleInfo* getCurrentModule();
201 
202         /**
203           Open the BtFindWidget below the mdi area
204         */
205         void openFindWidget();
206 
207 public slots:
208         /**
209         * Opens the optionsdialog of BibleTime.
210         */
211         void slotSettingsOptions();
212         /**
213         * Opens the bookshelf wizard.
214         */
215         void slotBookshelfWizard();
216         /**
217         * Opens the handbook.
218         */
219         void openOnlineHelp_Handbook();
220         /**
221         * Opens the bible study howto.
222         */
223         void openOnlineHelp_Howto();
224 
225         /**
226         * Open the Tip Dialog
227         */
228         void slotOpenTipDialog();
229 
230         /**
231           Processes the command-line options given to BibleTime.
232           \param[in] ignoreSession Specifies whether --ignore-session was used.
233           \param[in] bibleKey If --open-default-bible was used, the bible key
234                               specified, or null otherwise.
235         */
236         void processCommandline(bool ignoreSession, const QString &bibleKey);
237 
238         /**
239         * Creates QAction's that have keyboard shortcuts
240         */
241         static void insertKeyboardActions( BtActionCollection* const a );
242 
243     protected: // Protected methods
244         /**
245         * Catch QMainWindow events
246         */
247         bool event(QEvent* event) override;
248         /**
249         * Create the main window menu and toolbar
250         */
251         void createMenuAndToolBar();
252         /**
253           Creates mdi and and BtFindWidget
254         */
255         void createCentralWidget();
256         /**
257         * Initializes the sword.conf in the $HOME\Sword directory
258         */
259         void initSwordConfigFile();
260         /**
261         * Initializes the view of this widget
262         */
263         void initView();
264         /**
265         * Initializes the menubar of BibleTime.
266         */
267         void initMenubar();
268         /**
269         * Initializes the SIGNAL / SLOT connections
270         */
271         void initConnections();
272         /**
273         * Initializes the backend
274         */
275         void initBackends();
276         /**
277         * Initializes the action objects of the GUI
278         */
279         void initActions();
280         /**
281           Initializes the toolbars.
282         */
283         void initToolbars();
284         /**
285           Retranslates the UI.
286         */
287         void retranslateUi();
288         /**
289           Retranslates the UI actions.
290         */
291         static void retranslateUiActions(BtActionCollection* ac);
292         /**
293         * Initializes one action object
294         */
295         QAction* initAction(QAction* action, QString text, QIcon const & icon, QKeySequence accel,
296                             const QString& tooltip, const QString& actionName, const char* slot );
297         /**
298         * Refreshes all presenter supporting at least in of the features given as parameter.
299         */
300         void refreshDisplayWindows() const;
301 
302         /**
303         * Reimplemented from QWidget.
304         */
305         void closeEvent(QCloseEvent *event) override;
306 
307     protected slots:
308         /**
309          * Creates a new presenter in the MDI area according to the type of the module.
310          */
311         CDisplayWindow* createReadDisplayWindow(QList<CSwordModuleInfo*> modules, const QString& key);
312         CDisplayWindow* createReadDisplayWindow(CSwordModuleInfo* module, const QString& key = QString::null);
313         CDisplayWindow* createWriteDisplayWindow(CSwordModuleInfo * module, const QString & key, CPlainWriteWindow::WriteWindowType type);
314         CDisplayWindow* moduleEditPlain(CSwordModuleInfo *module);
315         CDisplayWindow* moduleEditHtml(CSwordModuleInfo *module);
316         void searchInModule(CSwordModuleInfo *module);
317         void slotModuleUnlock(CSwordModuleInfo *module);
318         void moduleAbout(CSwordModuleInfo *module);
319         void quit();
320 
321         /**
322          * Is called when the window menu is about to show ;-)
323          */
324         void slotWindowMenuAboutToShow();
325         /**
326          * Is called when the open windows menu is about to show ;-)
327          */
328         void slotOpenWindowsMenuAboutToShow();
329         void slotUpdateWindowArrangementActions(QAction * trigerredAction);
330 
331         void slotCascade();
332         void slotTile();
333         void slotTileVertical();
334         void slotTileHorizontal();
335 
336         /**
337          * Shows/hides the main toolbar
338          */
339         void slotToggleMainToolbar();
340         void slotToggleToolsToolbar();
341         void slotToggleNavigatorToolbar();
342         void slotToggleWorksToolbar();
343         void slotToggleFormatToolbar();
344 
345         void slotToggleToolBarsInEachWindow();
346 
347         /**
348         * Shows/hides the text window text area headers and sets
349         * configuration that newly opened windows don't user headers.
350         */
351         void slotToggleTextWindowHeader();
352 
353         /**
354          * Used to set the active menu
355          */
356         void slotSetActiveSubWindow(QWidget* window);
357         /**
358          * The active window was changed
359          */
360         void slotActiveWindowChanged(QMdiSubWindow* window);
361         /**
362         * Saves the current settings into the currently activated profile.
363         */
364         void saveProfile();
365         /**
366         * Deletes the chosen session from the menu and from disk.
367         */
368         void deleteProfile(QAction* action);
369         /**
370         * Loads the profile with the menu id ID
371         */
372         void loadProfile(QAction * action);
373         /**
374         * Loads the profile with the given key
375         */
376         void loadProfile(const QString & profileKey);
377         /**
378         * Reloads the current profile
379         */
380         void reloadProfile();
381         /**
382         * Toggles between normal and fullscreen mode.
383         */
384         void toggleFullscreen();
385         /**
386         * Is called when settings in the optionsdialog have been
387         * changed (ok or apply)
388         */
389         void slotSettingsChanged();
390 
391         /**
392          * Called when search button is pressed
393          **/
394         void slotSearchModules();
395         /**
396          * Called for search default bible
397          **/
398         void slotSearchDefaultBible();
399         /**
400          Saves current settings into a new profile.
401         */
402         void saveToNewProfile();
403         /**
404         * Slot to refresh the save profile and load profile menus.
405         */
406         void refreshProfileMenus();
407 
408         /**
409         * Open the About Dialog
410         */
411         void slotOpenAboutDialog();
412 
413     signals:
414         void toggledTextWindowHeader(bool newState);
415         void toggledTextWindowNavigator(bool newState);
416         void toggledTextWindowToolButtons(bool newState);
417         void toggledTextWindowModuleChooser(bool newState);
418         void toggledTextWindowFormatToolbar(bool newState);
419 
420     private:
421         static BibleTime *m_instance;
422 
423         // Docking widgets and their respective content widgets:
424         BtBookshelfDockWidget* m_bookshelfDock;
425         QDockWidget* m_bookmarksDock;
426         CBookmarkIndex* m_bookmarksPage;
427         QDockWidget* m_magDock;
428         InfoDisplay::CInfoDisplay* m_infoDisplay;
429 
430         QToolBar* m_mainToolBar;
431         QToolBar* m_navToolBar;
432         BtModuleChooserBar* m_worksToolBar;
433         QToolBar* m_toolsToolBar;
434         QToolBar* m_formatToolBar;
435 
436         // File menu:
437         QMenu *m_fileMenu;
438         BtOpenWorkAction *m_openWorkAction;
439         QAction *m_quitAction;
440 
441         // View menu:
442         QMenu *m_viewMenu;
443         QAction *m_showBookshelfAction;
444         QAction *m_showBookmarksAction;
445         QAction *m_showMagAction;
446         QMenu *m_toolBarsMenu;
447         QAction* m_showMainWindowToolbarAction;
448         QAction *m_showTextAreaHeadersAction;
449         QAction *m_showTextWindowNavigationAction;
450         QAction *m_showTextWindowModuleChooserAction;
451         QAction *m_showTextWindowToolButtonsAction;
452         QAction *m_showFormatToolbarAction;
453         QAction *m_toolbarsInEachWindow;
454 
455         // Search menu:
456         QMenu *m_searchMenu;
457         QAction *m_searchOpenWorksAction;
458         QAction *m_searchStandardBibleAction;
459 
460         // Window menu:
461         QMenu *m_windowMenu;
462         QMenu *m_openWindowsMenu;
463         QAction *m_windowCascadeAction;
464         QAction *m_windowTileAction;
465         QAction *m_windowTileHorizontalAction;
466         QAction *m_windowTileVerticalAction;
467         QAction *m_windowManualModeAction;
468         QMenu *m_windowArrangementMenu;
469         QActionGroup *m_windowArrangementActionGroup;
470         QAction *m_windowAutoCascadeAction;
471         QAction *m_windowAutoTileAction;
472         QAction *m_windowAutoTabbedAction;
473         QAction *m_windowAutoTileVerticalAction;
474         QAction *m_windowAutoTileHorizontalAction;
475         QAction *m_windowCloseAction;
476         QAction *m_windowCloseAllAction;
477         QAction* m_windowSaveToNewProfileAction;
478         QMenu* m_windowLoadProfileMenu;
479         QActionGroup* m_windowLoadProfileActionGroup;
480         QMenu* m_windowDeleteProfileMenu;
481 
482         // Settings menu:
483         QMenu *m_settingsMenu;
484         QAction *m_setPreferencesAction;
485         QAction *m_bookshelfManagerAction;
486         QAction *m_bookshelfWizardAction;
487 
488         // Help menu:
489         QMenu *m_helpMenu;
490         QAction *m_openHandbookAction;
491         QAction *m_bibleStudyHowtoAction;
492         QAction *m_aboutBibleTimeAction;
493         QAction *m_tipOfTheDayAction;
494 
495         BtActionCollection* m_actionCollection;
496 
497 
498         QAction* m_windowFullscreenAction;
499 
500         /**
501          * Signal mapper to map windows to menu items.
502          */
503         QSignalMapper* m_windowMapper;
504         /// \todo remove?
505         // QList<QAction*> m_windowOpenWindowsList;
506 
507         CMDIArea* m_mdi;
508         BtFindWidget* m_findWidget;
509 
510 
511     protected:
512         void closeAllModuleWindows();
513         void syncAllBibles(const QString& key);
514         void syncAllCommentaries(const QString& key);
515         void syncAllLexicons(const QString& key);
516         void syncAllVerseBasedModules(const QString& key);
517         void openWindow(const QString& moduleName, const QString& key);
518         void openDefaultBible(const QString& key);
519         QString getCurrentReference();
520         QStringList searchInModule(const QString& module, const QString& searchText);
521         QStringList searchInOpenModules(const QString& searchText);
522         QStringList searchInDefaultBible(const QString& searchText);
523         QStringList getModulesOfType(const QString& type);
524 
525         // Helper function
526         void syncAllModulesByType(const CSwordModuleInfo::ModuleType type, const QString& key);
527 
528     private:
529         /**
530          * Set the visibility of all tool bars according to the configuration
531          * taking the toolbarsInEachWindow setting into account.
532          */
533         void showOrHideToolBars();
534 
535 #ifndef NDEBUG
536         void deleteDebugWindow();
537     private:
538         void slotDebugWindowClosing();
539         void slotDebugTimeout();
540         void slotShowDebugWindow(bool);
541     private:
542         QAction *m_debugWidgetAction;
543         static QLabel *m_debugWindow;
544         static QMutex m_debugWindowLock;
545 #endif
546 };
547 
548 #endif
549