summaryrefslogtreecommitdiff
path: root/src/bibletime_init.cpp
blob: cbff79f0c932a6c56db3a288873a0b8fb164f6ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
/*********
*
* 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.h"

#include <QApplication>
#include <QDebug>
#include <QDockWidget>
#include <QLabel>
#include <QMenu>
#include <QMenuBar>
#include <QPointer>
#include <QSplitter>
#include <QToolBar>
#include <QVBoxLayout>
#include "backend/config/cbtconfig.h"
#include "backend/managers/btstringmgr.h"
#include "backend/managers/clanguagemgr.h"
#include "backend/managers/cswordbackend.h"
#include "frontend/btbookshelfdockwidget.h"
#include "frontend/cinfodisplay.h"
#include "frontend/cmdiarea.h"
#include "frontend/cprinter.h"
#include "frontend/displaywindow/btactioncollection.h"
#include "frontend/mainindex/bookmarks/cbookmarkindex.h"
#include "frontend/profile/cprofile.h"
#include "frontend/profile/cprofilemgr.h"
#include "util/cpointers.h"
#include "util/cresmgr.h"
#include "util/directory.h"

// 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_bookshelfDock = new BtBookshelfDockWidget(this);
    addDockWidget(Qt::LeftDockWidgetArea, m_bookshelfDock);

    m_bookmarksDock = new QDockWidget(tr("Bookmarks"), this);
    m_bookmarksDock->setObjectName("BookmarksDock");
    m_bookmarksPage = new CBookmarkIndex(0);
    m_bookmarksDock->setWidget(m_bookmarksPage);
    addDockWidget(Qt::LeftDockWidgetArea, m_bookmarksDock);
    tabifyDockWidget(m_bookmarksDock, m_bookshelfDock);

    m_magDock = new QDockWidget(tr("Mag"), this);
    m_magDock->setObjectName("MagDock");
    m_infoDisplay = new CInfoDisplay(this);
    m_infoDisplay->resize(150, 150);
    m_magDock->setWidget(m_infoDisplay);
    addDockWidget(Qt::LeftDockWidgetArea, m_magDock);

    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, const QString& tooltip,
                               const QString& actionName, const char* slot) {
    namespace DU = util::directory;

    action->setText(text);
    if ( ! icon.isEmpty() )
        action->setIcon(DU::getIcon(icon));
    action->setShortcut(accel);
    if (tooltip != QString::null) action->setToolTip(tooltip);
    m_actionCollection->addAction(actionName, action);
    if (slot) QObject::connect( action, SIGNAL(triggered()), this, slot );
    return action;
}

// Creates QAction's for all actions that can have keyboard shortcuts
// Used in creating the main window and by the configuration dialog for setting shortcuts
void BibleTime::insertKeyboardActions( BtActionCollection* const a ) {
    namespace DU = util::directory;

    QAction* action = new QAction(a);
    action->setText(tr("&Quit"));
    action->setIcon(DU::getIcon("exit.svg"));
    action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
    action->setToolTip(tr("Quit BibleTime"));
    a->addAction("quit", action);

    action = new QAction(a);
    action->setText(tr("&Fullscreen mode"));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::window::showFullscreen::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::window::showFullscreen::accel));
    action->setToolTip(tr("Toggle fullscreen mode of the main window"));
    a->addAction("toggleFullscreen", action);

    action = new QAction(a);
    action->setText(tr("&Show toolbar"));
    action->setShortcut(QKeySequence(Qt::Key_F6));
    a->addAction("showToolbar", action);

    action = new QAction(a);
    action->setText(tr("Search in &open works..."));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::mainIndex::search::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::mainIndex::search::accel));
    action->setToolTip(tr("Search in all works that are currently open"));
    a->addAction("searchOpenWorks", action);

    action = new QAction(a);
    action->setText(tr("Search in standard &Bible..."));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::mainIndex::searchdefaultbible::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::mainIndex::searchdefaultbible::accel));
    action->setToolTip(tr("Search in the standard Bible"));
    a->addAction("searchStdBible", action);

    action = new QAction(a);
    action->setText(tr("Save as &new session..."));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::window::saveToNewProfile::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::window::saveToNewProfile::accel));
    action->setToolTip(tr("Create and save a new session"));
    a->addAction("saveNewSession", action);

    action = new QAction(a);
    action->setText(tr("&Manual mode"));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::window::arrangementMode::manual::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::window::arrangementMode::manual::accel));
    action->setToolTip(tr("Manually arrange the open windows"));
    a->addAction("manualArrangement", action);

    action = new QAction(a);
    action->setText(tr("Auto-tile &vertically"));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::window::arrangementMode::autoTileVertical::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::window::arrangementMode::autoTileVertical::accel));
    action->setToolTip(tr("Automatically tile the open windows vertically (arrange side by side)"));
    a->addAction("autoVertical", action);

    action = new QAction(a);
    action->setText(tr("Auto-tile &horizontally"));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::window::arrangementMode::autoTileHorizontal::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::window::arrangementMode::autoTileHorizontal::accel));
    action->setToolTip(tr("Automatically tile the open windows horizontally (arrange on top of each other)"));
    a->addAction("autoHorizontal", action);

    action = new QAction(a);
    action->setText(tr("Auto-&tile"));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::window::arrangementMode::autoTile::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::window::arrangementMode::autoTile::accel));
    action->setToolTip(tr("Automatically tile the open windows"));
    a->addAction("autoTile", action);

    action = new QAction(a);
    action->setText(tr("Auto-&cascade"));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::window::arrangementMode::autoCascade::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::window::arrangementMode::autoCascade::accel));
    action->setToolTip(tr("Automatically cascade the open windows"));
    a->addAction("autoCascade", action);

    action = new QAction(a);
    action->setText(tr("&Cascade"));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::window::cascade::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::window::cascade::accel));
    action->setToolTip(tr("Cascade the open windows"));
    a->addAction("cascade", action);

    action = new QAction(a);
    action->setText(tr("&Tile"));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::window::tile::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::window::tile::accel));
    action->setToolTip(tr("Tile the open windows"));
    a->addAction("tile", action);

    action = new QAction(a);
    action->setText(tr("Tile &vertically"));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::window::tileVertical::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::window::tileVertical::accel));
    action->setToolTip(tr("Vertically tile (arrange side by side) the open windows"));
    a->addAction("tileVertically", action);

    action = new QAction(a);
    action->setText(tr("Tile &horizontally"));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::window::tileHorizontal::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::window::tileHorizontal::accel));
    action->setToolTip(tr("Horizontally tile (arrange on top of each other) the open windows"));
    a->addAction("tileHorizontally", action);

    action = new QAction(a);
    action->setText(tr("Close &window"));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::window::close::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::window::close::accel));
    action->setToolTip(tr("Close the current open window"));
    a->addAction("closeWindow", action);

    action = new QAction(a);
    action->setText(tr("Cl&ose all windows"));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::window::closeAll::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::window::closeAll::accel));
    action->setToolTip(tr("Close all open windows inside BibleTime"));
    a->addAction("closeAllWindows", action);

    action = new QAction(a);
    action->setText(tr("&Configure BibleTime..."));
    action->setIcon(DU::getIcon("configure.svg"));
    action->setToolTip(tr("Set BibleTime's preferences"));
    a->addAction("setPreferences", action);

    action = new QAction(a);
    action->setText(tr("Bookshelf &Manager..."));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::settings::swordSetupDialog::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::settings::swordSetupDialog::accel));
    action->setToolTip(tr("Configure your bookshelf and install/update/remove/index works"));
    a->addAction("bookshelfManager", action);

    action = new QAction(a);
    action->setText(tr("&Handbook"));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::help::handbook::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::help::handbook::accel));
    action->setToolTip(tr("Open BibleTime's handbook"));
    a->addAction("openHandbook", action);

    action = new QAction(a);
    action->setText(tr("&Bible Study Howto"));
    action->setIcon(DU::getIcon(CResMgr::mainMenu::help::bibleStudyHowTo::icon));
    action->setShortcut(QKeySequence(CResMgr::mainMenu::help::bibleStudyHowTo::accel));
    action->setToolTip(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."));
    a->addAction("bibleStudyHowto", action);

    action = new QAction(a);
    action->setText(tr("&About BibleTime"));
    action->setToolTip(tr("Information about the BibleTime program"));
    a->addAction("aboutBibleTime", action);
}

/** Initializes the action objects of the GUI */
void BibleTime::initActions() {
    m_actionCollection = new BtActionCollection(this);

    /**
     * Create the window to signal mapper and connect it up.
     */
    m_windowMapper = new QSignalMapper(this);
    connect(m_windowMapper, SIGNAL(mapped(QWidget*)),
            this, SLOT(slotSetActiveSubWindow(QWidget*)));

    insertKeyboardActions(m_actionCollection);

    // Main menus
    QMenu* fileMenu = menuBar()->addMenu(tr("&File"));
    QMenu* viewMenu = menuBar()->addMenu(tr("&View"));
    QMenu* searchMenu = menuBar()->addMenu(tr("&Search"));
    m_windowMenu = menuBar()->addMenu(tr("&Window"));
    QMenu* settingsMenu = menuBar()->addMenu(tr("Se&ttings"));
    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 = m_actionCollection->action("quit");
    fileMenu->addAction(tmp);
    connect(tmp, SIGNAL(triggered()), this, SLOT(quit()) );

    
    // ********** View menu *********************
    
    m_windowFullscreen_action = m_actionCollection->action("toggleFullscreen");
    m_windowFullscreen_action->setCheckable(true);
    viewMenu->addAction(m_windowFullscreen_action);
    m_mainToolBar->addAction(m_windowFullscreen_action);
    connect(m_windowFullscreen_action, SIGNAL(triggered()), this, SLOT(toggleFullscreen()) );

    m_viewToolbar_action = m_actionCollection->action("showToolbar");
    m_viewToolbar_action->setCheckable(true);
    m_viewToolbar_action->setChecked(true);
    viewMenu->addAction(m_viewToolbar_action);
    connect(m_viewToolbar_action, SIGNAL(triggered()), this, SLOT(slotToggleToolbar()) );

    QAction* action = m_bookshelfDock->toggleViewAction();
    action->setText(tr("Show Bookshelf"));
    viewMenu->addAction(action);

    action = m_bookmarksDock->toggleViewAction();
    action->setText(tr("Show Bookmarks"));
    viewMenu->addAction(action);

    action = m_magDock->toggleViewAction();
    action->setText(tr("Show Mag"));
    viewMenu->addAction(action);

    viewMenu->addSeparator();
    QMenu* textWindowsMenu = new QMenu(tr("Text windows"));
    viewMenu->addMenu(textWindowsMenu);
    
    action = new QAction(tr("Show text area headers"), this);
    action->setCheckable(true);
    action->setChecked(CBTConfig::get(CBTConfig::showTextWindowHeaders));
    connect(action, SIGNAL(toggled(bool)), SLOT(slotToggleTextWindowHeader()));
    textWindowsMenu->addAction(action);
    
    action = new QAction(tr("Show navigation"), this);
    action->setCheckable(true);
    action->setChecked(CBTConfig::get(CBTConfig::showTextWindowNavigator));
    connect(action, SIGNAL(toggled(bool)), SLOT(slotToggleTextWindowNavigator()));
    textWindowsMenu->addAction(action);
    
    action = new QAction(tr("Show work chooser buttons"), this);
    action->setCheckable(true);
    action->setChecked(CBTConfig::get(CBTConfig::showTextWindowModuleSelectorButtons));
    connect(action, SIGNAL(toggled(bool)), SLOT(slotToggleTextWindowModuleChooser()));
    textWindowsMenu->addAction(action);
    
    action = new QAction(tr("Show tools"), this);
    action->setCheckable(true);
    action->setChecked(CBTConfig::get(CBTConfig::showTextWindowToolButtons));
    connect(action, SIGNAL(toggled(bool)), SLOT(slotToggleTextWindowToolButtons()));
    textWindowsMenu->addAction(action);
    
    // *************************************
    m_mainToolBar->addSeparator();

    tmp = m_actionCollection->action("searchOpenWorks");
    searchMenu->addAction(tmp);
    m_mainToolBar->addAction(tmp);
    m_mainToolBar->addSeparator();
    connect(tmp, SIGNAL(triggered()), this, SLOT(slotSearchModules()) );

    tmp = m_actionCollection->action("searchStdBible");
    searchMenu->addAction(tmp);
    connect(tmp, SIGNAL(triggered()), this, SLOT(slotSearchDefaultBible()) );

    /**
     * Window Menu
     */
    m_openWindowsMenu = new QMenu(tr("O&pen Windows"), m_windowMenu);
    m_windowMenu->addMenu(m_openWindowsMenu);

    m_windowClose_action = m_actionCollection->action("closeWindow");
    m_windowMenu->addAction(m_windowClose_action);
    connect(m_windowClose_action, SIGNAL(triggered()), m_mdi, SLOT(closeActiveSubWindow()));

    m_windowCloseAll_action = m_actionCollection->action("closeAllWindows");
    m_windowMenu->addAction(m_windowCloseAll_action);
    connect(m_windowCloseAll_action, SIGNAL(triggered()), m_mdi, SLOT(closeAllSubWindows()));

    m_windowMenu->addSeparator();

    // *** Window arrangement actions ***

    m_windowCascade_action = m_actionCollection->action("cascade");
    m_windowMenu->addAction(m_windowCascade_action);
    connect(m_windowCascade_action, SIGNAL(triggered()), this, SLOT(slotCascade()) );

    m_windowTile_action = m_actionCollection->action("tile");
    m_windowMenu->addAction(m_windowTile_action);
    connect(m_windowTile_action, SIGNAL(triggered()), this, SLOT(slotTile()) );

    m_windowTileVertical_action = m_actionCollection->action("tileVertically");
    m_windowMenu->addAction(m_windowTileVertical_action);
    connect(m_windowTileVertical_action, SIGNAL(triggered()), this, SLOT(slotTileVertical()) );

    m_windowTileHorizontal_action = m_actionCollection->action("tileHorizontally");
    m_windowMenu->addAction(m_windowTileHorizontal_action);
    connect(m_windowTileHorizontal_action, SIGNAL(triggered()), this, SLOT(slotTileHorizontal()) );

    QMenu* arrangementMenu = new QMenu(tr("&Arrangement mode"));
    m_windowMenu->addMenu(arrangementMenu);

    m_windowManualMode_action = m_actionCollection->action("manualArrangement");
    m_windowManualMode_action->setCheckable(true);
    arrangementMenu->addAction(m_windowManualMode_action);
    connect(m_windowManualMode_action, SIGNAL(triggered()), this, SLOT(slotManualArrangementMode()) );

    //: Vertical tiling means that windows are vertical, placed side by side
    m_windowAutoTileVertical_action = m_actionCollection->action("autoVertical");
    m_windowAutoTileVertical_action->setCheckable(true);
    arrangementMenu->addAction(m_windowAutoTileVertical_action);
    connect(m_windowAutoTileVertical_action, SIGNAL(triggered()), this, SLOT(slotAutoTileVertical()) );

    //: Horizontal tiling means that windows are horizontal, placed on top of each other
    m_windowAutoTileHorizontal_action = m_actionCollection->action("autoHorizontal");
    m_windowAutoTileHorizontal_action->setCheckable(true);
    arrangementMenu->addAction(m_windowAutoTileHorizontal_action);
    connect(m_windowAutoTileHorizontal_action, SIGNAL(triggered()), this, SLOT(slotAutoTileHorizontal()) );

    m_windowAutoTile_action = m_actionCollection->action("autoTile");
    m_windowAutoTile_action->setCheckable(true);
    arrangementMenu->addAction(m_windowAutoTile_action);
    connect(m_windowAutoTile_action, SIGNAL(triggered()), this, SLOT(slotAutoTile()) );

    m_windowAutoCascade_action = m_actionCollection->action("autoCascade");
    m_windowAutoCascade_action->setCheckable(true);
    arrangementMenu->addAction(m_windowAutoCascade_action);
    connect(m_windowAutoCascade_action, SIGNAL(triggered()), this, SLOT(slotAutoCascade()) );

    m_windowMenu->addSeparator();

    m_windowSaveProfileMenu = new QMenu(tr("&Save session"));
    m_windowMenu->addMenu(m_windowSaveProfileMenu);

    m_windowSaveToNewProfile_action = m_actionCollection->action("saveNewSession");
    m_windowMenu->addAction(m_windowSaveToNewProfile_action);
    connect(m_windowSaveToNewProfile_action, SIGNAL(triggered()), this, 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();

    tmp = m_actionCollection->action("setPreferences");
    settingsMenu->addAction(tmp);
    connect(tmp, SIGNAL(triggered()), this, SLOT(slotSettingsOptions()) );

    settingsMenu->addSeparator();

    tmp = m_actionCollection->action("bookshelfManager");
    settingsMenu->addAction(tmp);
    connect(tmp, SIGNAL(triggered()), this, SLOT(slotSwordSetupDialog()) );

    tmp = m_actionCollection->action("openHandbook");
    helpMenu->addAction(tmp);
    m_mainToolBar->addAction(tmp);
    connect(tmp, SIGNAL(triggered()), this, SLOT(openOnlineHelp_Handbook()) );

    tmp = m_actionCollection->action("bibleStudyHowto");
    helpMenu->addAction(tmp);
    connect(tmp, SIGNAL(triggered()), this, SLOT(openOnlineHelp_Howto()) );

    helpMenu->addSeparator();

    tmp = m_actionCollection->action("aboutBibleTime");
    helpMenu->addAction(tmp);
    connect(tmp, SIGNAL(triggered()), this, SLOT(slotOpenAboutDialog()) );
}

/** Initializes the SIGNAL / SLOT connections */
void BibleTime::initConnections() {
    if (m_windowMenu) {
        QObject::connect(m_windowMenu, SIGNAL(aboutToShow()), this, SLOT(slotWindowMenuAboutToShow()));
    }
    else {
        qWarning() << "Main window: can't find window menu";
    }

    if (m_openWindowsMenu) {
        QObject::connect(m_openWindowsMenu, SIGNAL(aboutToShow()),
                         this, SLOT(slotOpenWindowsMenuAboutToShow()));
    }
    else {
        qWarning() << "Main window: can't find open windows menu";
    }

    bool ok;
    ok = connect(m_bookmarksPage,
                 SIGNAL(createReadDisplayWindow(QList<CSwordModuleInfo*>, const QString&)),
                 this,
                 SLOT(createReadDisplayWindow(QList<CSwordModuleInfo*>, const QString&)));
    Q_ASSERT(ok);
    connect(m_bookshelfDock, SIGNAL(moduleOpenTriggered(CSwordModuleInfo*)),
            this, SLOT(createReadDisplayWindow(CSwordModuleInfo*)));
    connect(m_bookshelfDock, SIGNAL(moduleSearchTriggered(CSwordModuleInfo*)),
            this, SLOT(searchInModule(CSwordModuleInfo*)));
    connect(m_bookshelfDock, SIGNAL(moduleEditPlainTriggered(CSwordModuleInfo*)),
            this, SLOT(moduleEditPlain(CSwordModuleInfo*)));
    connect(m_bookshelfDock, SIGNAL(moduleEditHtmlTriggered(CSwordModuleInfo*)),
            this, SLOT(moduleEditHtml(CSwordModuleInfo*)));
    connect(m_bookshelfDock, SIGNAL(moduleUnlockTriggered(CSwordModuleInfo*)),
            this, SLOT(moduleUnlock(CSwordModuleInfo*)));
    connect(m_bookshelfDock, SIGNAL(moduleAboutTriggered(CSwordModuleInfo*)),
            this, SLOT(moduleAbout(CSwordModuleInfo*)));

    connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(slot_aboutToQuit()));
}

void BibleTime::initSwordConfigFile() {
// On Windows the sword.conf must be created before the initialization of sword
// It will contain the LocalePath which is used for sword locales
// It also contains a DataPath to the %ALLUSERSPROFILE%\Sword directory
// If this is not done here, the sword locales.d won't be found
#ifdef Q_WS_WIN
    namespace DU = util::directory;
    QString configFile = util::directory::getUserHomeSwordDir().filePath("sword.conf");
    QFile file(configFile);
    if (file.exists()) {
        return;
    }
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
        return;
    }
    QTextStream out(&file);
    out << "\n";
    out << "[Install]\n";
    out << "DataPath="   << DU::convertDirSeparators( DU::getSharedSwordDir().absolutePath()) << "\n";
    out << "LocalePath=" << DU::convertDirSeparators(DU::getApplicationSwordDir().absolutePath()) << "\n";
    out << "\n";
    file.close();
#endif
}

/** Initializes the backend */
void BibleTime::initBackends() {
    qDebug() << "BibleTime::initBackends";

    initSwordConfigFile();

    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);

    if (errorCode != CSwordBackend::NoError) {
        //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
    restoreState(p->getMainwindowState());
    restoreGeometry(p->getMainwindowGeometry());
    m_windowFullscreen_action->setChecked(isFullScreen());

    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;
        case CMDIArea::ArrangementModeTile:
            slotAutoTile();
            break;
        case CMDIArea::ArrangementModeManual:
            slotManualArrangementMode();
            break;
        default:
            slotAutoTileVertical();
            break;
    }
}

void BibleTime::storeProfileSettings( CProfile* p ) {
    Q_ASSERT(p && m_windowFullscreen_action);
    if (!p || !m_windowFullscreen_action) return;

    p->setMainwindowState(saveState());
    p->setMainwindowGeometry(saveGeometry());
    p->setMDIArrangementMode(m_mdi->getMDIArrangementMode());
}