diff options
Diffstat (limited to 'src/bibletime_init.cpp')
-rw-r--r-- | src/bibletime_init.cpp | 241 |
1 files changed, 145 insertions, 96 deletions
diff --git a/src/bibletime_init.cpp b/src/bibletime_init.cpp index dd68265..98db7d9 100644 --- a/src/bibletime_init.cpp +++ b/src/bibletime_init.cpp @@ -7,40 +7,38 @@ * **********/ -//BibleTime includes #include "bibletime.h" -#include "util/cpointers.h" -#include "util/cresmgr.h" -#include "util/directoryutil.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/cswordbackend.h" #include "backend/managers/clanguagemgr.h" +#include "backend/managers/cswordbackend.h" #include "frontend/btbookshelfdockwidget.h" -#include "frontend/displaywindow/btactioncollection.h" -#include "frontend/profile/cprofilemgr.h" -#include "frontend/profile/cprofile.h" +#include "frontend/cinfodisplay.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/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" -// Qt includes -#include <QSplitter> -#include <QPointer> -#include <QLabel> -#include <QVBoxLayout> -#include <QMenu> -#include <QMenuBar> -#include <QToolBar> -#include <QApplication> -#include <QDebug> -#include <QDockWidget> - -// Sword includes +// Sword includes: #include <swlog.h> + using namespace InfoDisplay; using namespace Profile; @@ -71,11 +69,14 @@ void BibleTime::initView() { 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 ) { +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(util::filesystem::DirectoryUtil::getIcon(icon)); + action->setIcon(DU::getIcon(icon)); action->setShortcut(accel); if (tooltip != QString::null) action->setToolTip(tooltip); m_actionCollection->addAction(actionName, action); @@ -86,16 +87,18 @@ QAction* BibleTime::initAction(QAction* action, QString text, QString icon, QKey // 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(util::filesystem::DirectoryUtil::getIcon("exit.svg")); + 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(util::filesystem::DirectoryUtil::getIcon(CResMgr::mainMenu::window::showFullscreen::icon)); + 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); @@ -107,106 +110,113 @@ void BibleTime::insertKeyboardActions( BtActionCollection* const a ) { action = new QAction(a); action->setText(tr("Search in &open works...")); - action->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::mainMenu::mainIndex::search::icon)); + 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(util::filesystem::DirectoryUtil::getIcon(CResMgr::mainMenu::mainIndex::searchdefaultbible::icon)); + 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(util::filesystem::DirectoryUtil::getIcon(CResMgr::mainMenu::window::saveToNewProfile::icon)); + 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(util::filesystem::DirectoryUtil::getIcon(CResMgr::mainMenu::window::arrangementMode::manual::icon)); + 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(util::filesystem::DirectoryUtil::getIcon(CResMgr::mainMenu::window::arrangementMode::autoTileVertical::icon)); + 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(util::filesystem::DirectoryUtil::getIcon(CResMgr::mainMenu::window::arrangementMode::autoTileHorizontal::icon)); + 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-&cascade")); - action->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::mainMenu::window::arrangementMode::autoCascade::icon)); + 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(util::filesystem::DirectoryUtil::getIcon(CResMgr::mainMenu::window::cascade::icon)); + 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 &vertically")); - action->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::mainMenu::window::tileVertical::icon)); + 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(util::filesystem::DirectoryUtil::getIcon(CResMgr::mainMenu::window::tileHorizontal::icon)); + 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(util::filesystem::DirectoryUtil::getIcon(CResMgr::mainMenu::window::closeAll::icon)); + 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(util::filesystem::DirectoryUtil::getIcon("configure.svg")); + 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(util::filesystem::DirectoryUtil::getIcon(CResMgr::mainMenu::settings::swordSetupDialog::icon)); + 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(util::filesystem::DirectoryUtil::getIcon(CResMgr::mainMenu::help::handbook::icon)); + 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(util::filesystem::DirectoryUtil::getIcon(CResMgr::mainMenu::help::bibleStudyHowTo::icon)); + 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.")); + 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); @@ -219,6 +229,13 @@ void BibleTime::insertKeyboardActions( BtActionCollection* const a ) { 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 @@ -239,7 +256,7 @@ void BibleTime::initActions() { fileMenu->addAction(tmp); m_mainToolBar->addAction(tmp); m_mainToolBar->addSeparator(); - connect(tmp, SIGNAL(triggered()), this, SLOT(close()) ); + connect(tmp, SIGNAL(triggered()), this, SLOT(quit()) ); m_windowFullscreen_action = m_actionCollection->action("toggleFullscreen"); m_windowFullscreen_action->setCheckable(true); @@ -253,7 +270,6 @@ void BibleTime::initActions() { 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); @@ -278,29 +294,35 @@ void BibleTime::initActions() { searchMenu->addAction(tmp); connect(tmp, SIGNAL(triggered()), this, SLOT(slotSearchDefaultBible()) ); - 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()) ); + /** + * 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_windowLoadProfileMenu = new QMenu(tr("&Load session")); - m_windowMenu->addMenu(m_windowLoadProfileMenu); + m_windowCloseAll_action = m_actionCollection->action("closeAllWindows"); + m_windowMenu->addAction(m_windowCloseAll_action); + connect(m_windowCloseAll_action, SIGNAL(triggered()), m_mdi, SLOT(closeAllSubWindows())); - m_windowDeleteProfileMenu = new QMenu(tr("&Delete session")); - m_windowMenu->addMenu(m_windowDeleteProfileMenu); + m_windowMenu->addSeparator(); - 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*))); + // *** Window arrangement actions *** - refreshProfileMenus(); + m_windowCascade_action = m_actionCollection->action("cascade"); + m_windowMenu->addAction(m_windowCascade_action); + connect(m_windowCascade_action, SIGNAL(triggered()), this, SLOT(slotCascade()) ); - m_windowMenu->addSeparator(); + m_windowTileVertical_action = m_actionCollection->action("tileVertically"); + m_windowMenu->addAction(m_windowTileVertical_action); + connect(m_windowTileVertical_action, SIGNAL(triggered()), this, SLOT(slotTileVertical()) ); -//--------------------------Window arrangement actions--------------------------------------- + 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); @@ -327,22 +349,26 @@ void BibleTime::initActions() { arrangementMenu->addAction(m_windowAutoCascade_action); connect(m_windowAutoCascade_action, SIGNAL(triggered()), this, SLOT(slotAutoCascade()) ); - m_windowCascade_action = m_actionCollection->action("cascade"); - m_windowMenu->addAction(m_windowCascade_action); - connect(m_windowCascade_action, SIGNAL(triggered()), this, SLOT(slotCascade()) ); + m_windowMenu->addSeparator(); - m_windowTileVertical_action = m_actionCollection->action("tileVertically"); - m_windowMenu->addAction(m_windowTileVertical_action); - connect(m_windowTileVertical_action, SIGNAL(triggered()), this, SLOT(slotTileVertical()) ); + m_windowSaveProfileMenu = new QMenu(tr("&Save session")); + m_windowMenu->addMenu(m_windowSaveProfileMenu); - m_windowTileHorizontal_action = m_actionCollection->action("tileHorizontally"); - m_windowMenu->addAction(m_windowTileHorizontal_action); - connect(m_windowTileHorizontal_action, SIGNAL(triggered()), this, SLOT(slotTileHorizontal()) ); + m_windowSaveToNewProfile_action = m_actionCollection->action("saveNewSession"); + m_windowMenu->addAction(m_windowSaveToNewProfile_action); + connect(m_windowSaveToNewProfile_action, SIGNAL(triggered()), this, SLOT(saveToNewProfile()) ); - m_windowCloseAll_action = m_actionCollection->action("closeAllWindows"); - m_windowMenu->addAction(m_windowCloseAll_action); - connect(m_windowCloseAll_action, SIGNAL(triggered()), m_mdi, SLOT(deleteAll())); + 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); @@ -384,6 +410,13 @@ void BibleTime::initConnections() { 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&))); @@ -404,9 +437,36 @@ void BibleTime::initConnections() { 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"); + qDebug() << "BibleTime::initBackends"; + + initSwordConfigFile(); sword::StringMgr::setSystemStringMgr( new BTStringMgr() ); sword::SWLog::getSystemLog()->setLogLevel(1); @@ -419,12 +479,12 @@ void BibleTime::initBackends() { if (errorCode != CSwordBackend::NoError) { //show error message that initBackend failed - //TODO: + /// \todo // switch (errorCode) { // case CSwordBackend::NoSwordConfig: //mods.d or mods.conf missing // { // KStartupLogo::hideSplash(); -// qDebug("case CSwordBackend::NoSwordConfig"); +// qDebug() << "case CSwordBackend::NoSwordConfig"; // BookshelfManager::CSwordSetupDialog dlg; // dlg.showPart( BookshelfManager::CSwordSetupDialog::Sword ); // dlg.exec(); @@ -434,7 +494,7 @@ void BibleTime::initBackends() { // case CSwordBackend::NoModules: //no modules installed, but config exists // { // KStartupLogo::hideSplash(); -// qDebug("case CSwordBackend::NoModules"); +// qDebug() << "case CSwordBackend::NoModules"; // BookshelfManager::CSwordSetupDialog dlg; // dlg.showPart( BookshelfManager::CSwordSetupDialog::Install ); // dlg.exec(); @@ -444,7 +504,7 @@ void BibleTime::initBackends() { // default: //unknown error // { // KStartupLogo::hideSplash(); -// qDebug("unknown error"); +// qDebug() << "unknown error"; // BookshelfManager::CSwordSetupDialog dlg; // dlg.showPart( BookshelfManager::CSwordSetupDialog::Sword ); // dlg.exec(); @@ -457,23 +517,19 @@ void BibleTime::initBackends() { // - 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(); + /// \todo //backend::deleteOrphanedIndices(); } void BibleTime::applyProfileSettings( CProfile* p ) { - qDebug("BibleTime::applyProfileSettings"); + 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()); + restoreGeometry(p->getMainwindowGeometry()); + m_windowFullscreen_action->setChecked(isFullScreen()); const CMDIArea::MDIArrangementMode newArrangementMode = p->getMDIArrangementMode(); //make sure actions are updated by calling the slot functions @@ -499,14 +555,7 @@ void BibleTime::storeProfileSettings( CProfile* p ) { 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->setMainwindowGeometry(saveGeometry()); p->setMDIArrangementMode(m_mdi->getMDIArrangementMode()); } |