summaryrefslogtreecommitdiff
path: root/src/bibletime_slots.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bibletime_slots.cpp')
-rw-r--r--src/bibletime_slots.cpp610
1 files changed, 308 insertions, 302 deletions
diff --git a/src/bibletime_slots.cpp b/src/bibletime_slots.cpp
index 05729bf..0572f73 100644
--- a/src/bibletime_slots.cpp
+++ b/src/bibletime_slots.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2011 by the BibleTime developers.
+* Copyright 1999-2014 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -22,23 +22,22 @@
#include <QtGlobal>
#include <QToolBar>
#include <QUrl>
-#include "backend/config/cbtconfig.h"
+#include "backend/config/btconfig.h"
#include "backend/keys/cswordversekey.h"
#include "frontend/btaboutdialog.h"
#include "frontend/cinfodisplay.h"
#include "frontend/cmdiarea.h"
#include "frontend/bookshelfmanager/btmodulemanagerdialog.h"
+#include "frontend/display/btfindwidget.h"
#include "frontend/displaywindow/btmodulechooserbar.h"
#include "frontend/displaywindow/cdisplaywindow.h"
+#include "frontend/messagedialog.h"
#include "frontend/searchdialog/csearchdialog.h"
#include "frontend/settingsdialogs/cconfigurationdialog.h"
#include "frontend/tips/bttipdialog.h"
#include "util/directory.h"
-using namespace Profile;
-
-
/** Opens the optionsdialog of BibleTime. */
void BibleTime::slotSettingsOptions() {
qDebug() << "BibleTime::slotSettingsOptions";
@@ -58,7 +57,7 @@ void BibleTime::saveConfigSettings() {
/** 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);
+ const QString language = btConfig().value<QString>("language", QLocale::system().name());
CSwordBackend::instance()->booknameLanguage(language);
// \todo update the bookmarks after Bible bookname language has been changed
@@ -91,38 +90,24 @@ void BibleTime::slotSwordSetupDialog() {
void BibleTime::slotWindowMenuAboutToShow() {
Q_ASSERT(m_windowMenu);
- if ( m_mdi->subWindowList().isEmpty() ) {
- m_windowCascadeAction->setEnabled(false);
- m_windowTileVerticalAction->setEnabled(false);
- m_windowTileHorizontalAction->setEnabled(false);
- m_windowCloseAction->setEnabled(false);
- m_windowCloseAllAction->setEnabled(false);
- m_openWindowsMenu->setEnabled(false);
- }
- else if (m_mdi->subWindowList().count() == 1) {
- m_windowTileVerticalAction->setEnabled(false);
- m_windowTileHorizontalAction->setEnabled(false);
- m_windowCascadeAction->setEnabled(false);
- m_windowCloseAction->setEnabled(true);
- m_windowCloseAllAction->setEnabled(true);
- m_openWindowsMenu->setEnabled(true);
- // m_windowMenu->insertSeparator();
- }
- else {
- slotUpdateWindowArrangementActions(0); //update the window tile/cascade states
- m_windowCloseAction->setEnabled(true);
- m_windowCloseAllAction->setEnabled(true);
- m_openWindowsMenu->setEnabled(true);
- }
+ const int numSubWindows = m_mdi->subWindowList().count();
+ m_windowCloseAction->setEnabled(numSubWindows);
+ m_windowCloseAllAction->setEnabled(numSubWindows);
+ m_openWindowsMenu->setEnabled(numSubWindows);
+
+ const bool enableManualArrangeActions = numSubWindows > 1;
+ m_windowCascadeAction->setEnabled(enableManualArrangeActions);
+ m_windowTileAction->setEnabled(enableManualArrangeActions);
+ m_windowTileVerticalAction->setEnabled(enableManualArrangeActions);
+ m_windowTileHorizontalAction->setEnabled(enableManualArrangeActions);
}
/** Is called just before the open windows menu is shown. */
void BibleTime::slotOpenWindowsMenuAboutToShow() {
Q_ASSERT(m_openWindowsMenu);
- QList<QMdiSubWindow*> windows = m_mdi->usableWindowList();
m_openWindowsMenu->clear();
- Q_FOREACH (QMdiSubWindow * const window, windows) {
+ Q_FOREACH (QMdiSubWindow * const window, m_mdi->usableWindowList()) {
QAction *openWindowAction = m_openWindowsMenu->addAction(window->windowTitle());
openWindowAction->setCheckable(true);
openWindowAction->setChecked(window == m_mdi->activeSubWindow());
@@ -132,134 +117,56 @@ void BibleTime::slotOpenWindowsMenuAboutToShow() {
}
/** This slot is connected with the windowAutoTileAction object */
-void BibleTime::slotUpdateWindowArrangementActions( QAction* clickedAction ) {
- /* If a toggle action was clicked we see if it is checked or unchecked and
- * enable/disable the simple cascade and tile options accordingly
- */
- m_windowTileVerticalAction->setEnabled( m_windowManualModeAction->isChecked() );
- m_windowTileHorizontalAction->setEnabled( m_windowManualModeAction->isChecked() );
- m_windowCascadeAction->setEnabled( m_windowManualModeAction->isChecked() );
- m_windowTileAction->setEnabled( m_windowManualModeAction->isChecked() );
-
- if (clickedAction) {
- m_windowManualModeAction->setEnabled(
- m_windowManualModeAction != clickedAction
- && m_windowTileHorizontalAction != clickedAction
- && m_windowTileVerticalAction != clickedAction
- && m_windowCascadeAction != clickedAction
- && m_windowTileAction != clickedAction
- );
- m_windowAutoTileVerticalAction->setEnabled( m_windowAutoTileVerticalAction != clickedAction );
- m_windowAutoTileHorizontalAction->setEnabled( m_windowAutoTileHorizontalAction != clickedAction );
- m_windowAutoCascadeAction->setEnabled( m_windowAutoCascadeAction != clickedAction );
- m_windowAutoTileAction->setEnabled( m_windowAutoTileAction != clickedAction );
- m_windowAutoTabbedAction->setEnabled( m_windowAutoTabbedAction != clickedAction );
- }
+void BibleTime::slotUpdateWindowArrangementActions(QAction * trigerredAction) {
+ Q_ASSERT(trigerredAction);
- if (clickedAction == m_windowManualModeAction) {
- m_windowAutoTileVerticalAction->setChecked(false);
- m_windowAutoTileHorizontalAction->setChecked(false);
- m_windowAutoCascadeAction->setChecked(false);
- m_windowAutoTileAction->setChecked(false);
- m_windowAutoTabbedAction->setChecked(false);
- m_mdi->enableWindowMinMaxFlags(true);
- m_mdi->setMDIArrangementMode( CMDIArea::ArrangementModeManual );
- CBTConfig::set(CBTConfig::autoTileVertical, false);
- CBTConfig::set(CBTConfig::autoTileHorizontal, false);
- CBTConfig::set(CBTConfig::autoTile, false);
- CBTConfig::set(CBTConfig::autoTabbed, false);
- CBTConfig::set(CBTConfig::autoCascade, false);
- }
- else if (clickedAction == m_windowAutoTileVerticalAction) {
- m_windowManualModeAction->setChecked(false);
- m_windowAutoTileHorizontalAction->setChecked(false);
- m_windowAutoCascadeAction->setChecked(false);
- m_windowAutoTileAction->setChecked(false);
- m_windowAutoTabbedAction->setChecked(false);
- m_mdi->enableWindowMinMaxFlags(false);
- m_mdi->setMDIArrangementMode( CMDIArea::ArrangementModeTileVertical );
- CBTConfig::set(CBTConfig::autoTileVertical, true);
- }
- else if (clickedAction == m_windowAutoTileHorizontalAction) {
- m_windowManualModeAction->setChecked(false);
- m_windowAutoTileVerticalAction->setChecked(false);
- m_windowAutoCascadeAction->setChecked(false);
- m_windowAutoTileAction->setChecked(false);
- m_windowAutoTabbedAction->setChecked(false);
- m_mdi->enableWindowMinMaxFlags(false);
- m_mdi->setMDIArrangementMode( CMDIArea::ArrangementModeTileHorizontal );
- CBTConfig::set(CBTConfig::autoTileHorizontal, true);
+ if (trigerredAction == m_windowAutoTileVerticalAction) {
+ m_mdi->setMDIArrangementMode(CMDIArea::ArrangementModeTileVertical);
+ btConfig().setSessionValue("GUI/alignmentMode", autoTileVertical);
}
- else if (clickedAction == m_windowAutoTileAction) {
- m_windowManualModeAction->setChecked(false);
- m_windowAutoTileHorizontalAction->setChecked(false);
- m_windowAutoTileVerticalAction->setChecked(false);
- m_windowAutoTabbedAction->setChecked(false);
- m_windowAutoCascadeAction->setChecked(false);
- m_mdi->enableWindowMinMaxFlags(false);
- m_mdi->setMDIArrangementMode( CMDIArea::ArrangementModeTile );
- CBTConfig::set(CBTConfig::autoTile, true);
+ else if (trigerredAction == m_windowAutoTileHorizontalAction) {
+ m_mdi->setMDIArrangementMode(CMDIArea::ArrangementModeTileHorizontal);
+ btConfig().setSessionValue("GUI/alignmentMode", autoTileHorizontal);
}
- else if (clickedAction == m_windowAutoTabbedAction) {
- m_windowManualModeAction->setChecked(false);
- m_windowAutoTileHorizontalAction->setChecked(false);
- m_windowAutoTileVerticalAction->setChecked(false);
- m_windowAutoTileAction->setChecked(false);
- m_windowAutoCascadeAction->setChecked(false);
- m_mdi->enableWindowMinMaxFlags(false);
- m_mdi->setMDIArrangementMode( CMDIArea::ArrangementModeTabbed );
- CBTConfig::set(CBTConfig::autoTabbed, true);
+ else if (trigerredAction == m_windowAutoTileAction) {
+ m_mdi->setMDIArrangementMode(CMDIArea::ArrangementModeTile);
+ btConfig().setSessionValue("GUI/alignmentMode", autoTile);
}
- else if (clickedAction == m_windowAutoCascadeAction) {
- m_windowManualModeAction->setChecked(false);
- m_windowAutoTileHorizontalAction->setChecked(false);
- m_windowAutoTileVerticalAction->setChecked(false);
- m_windowAutoTileAction->setChecked(false);
- m_windowAutoTabbedAction->setChecked(false);
- m_mdi->enableWindowMinMaxFlags(false);
- m_mdi->setMDIArrangementMode( CMDIArea::ArrangementModeCascade );
- CBTConfig::set(CBTConfig::autoCascade, true);
+ else if (trigerredAction == m_windowAutoTabbedAction) {
+ m_mdi->setMDIArrangementMode(CMDIArea::ArrangementModeTabbed);
+ btConfig().setSessionValue("GUI/alignmentMode", autoTabbed);
}
- else if (clickedAction == m_windowTileAction) {
- m_mdi->setMDIArrangementMode( CMDIArea::ArrangementModeManual );
- m_mdi->myTile();
+ else if (trigerredAction == m_windowAutoCascadeAction) {
+ m_mdi->setMDIArrangementMode(CMDIArea::ArrangementModeCascade);
+ btConfig().setSessionValue("GUI/alignmentMode", autoCascade);
}
- else if (clickedAction == m_windowCascadeAction) {
- m_mdi->setMDIArrangementMode( CMDIArea::ArrangementModeManual );
- m_mdi->myCascade();
- }
- else if (clickedAction == m_windowTileVerticalAction) {
- m_mdi->setMDIArrangementMode( CMDIArea::ArrangementModeManual );
- m_mdi->myTileVertical();
- }
- else if (clickedAction == m_windowTileHorizontalAction) {
- m_mdi->setMDIArrangementMode( CMDIArea::ArrangementModeManual );
- m_mdi->myTileHorizontal();
- }
-}
-
-void BibleTime::slotManualArrangementMode() {
- slotUpdateWindowArrangementActions( m_windowManualModeAction );
-}
+ else {
+ Q_ASSERT(trigerredAction == m_windowManualModeAction
+ || trigerredAction == m_windowTileAction
+ || trigerredAction == m_windowCascadeAction
+ || trigerredAction == m_windowTileVerticalAction
+ || trigerredAction == m_windowTileHorizontalAction);
-/** This slot is connected with the windowAutoTileAction object */
-void BibleTime::slotAutoTileHorizontal() {
- slotUpdateWindowArrangementActions( m_windowAutoTileHorizontalAction );
-}
+ if (trigerredAction != m_windowManualModeAction)
+ m_windowManualModeAction->setChecked(true);
-/** This slot is connected with the windowAutoTileAction object */
-void BibleTime::slotAutoTileVertical() {
- slotUpdateWindowArrangementActions( m_windowAutoTileVerticalAction );
-}
+ m_mdi->enableWindowMinMaxFlags(true);
+ m_mdi->setMDIArrangementMode(CMDIArea::ArrangementModeManual);
+ btConfig().setSessionValue("GUI/alignmentMode", manual);
+
+ if (trigerredAction == m_windowTileAction)
+ m_mdi->myTile();
+ else if (trigerredAction == m_windowCascadeAction)
+ m_mdi->myCascade();
+ else if (trigerredAction == m_windowTileVerticalAction)
+ m_mdi->myTileVertical();
+ else if (trigerredAction == m_windowTileHorizontalAction)
+ m_mdi->myTileHorizontal();
-/** This slot is connected with the windowAutoTileAction object */
-void BibleTime::slotAutoTile() {
- slotUpdateWindowArrangementActions( m_windowAutoTileAction );
-}
+ return;
+ }
-/** This slot is connected with the windowAutoTabbedAction object */
-void BibleTime::slotAutoTabbed() {
- slotUpdateWindowArrangementActions( m_windowAutoTabbedAction );
+ m_mdi->enableWindowMinMaxFlags(false);
}
void BibleTime::slotTile() {
@@ -278,16 +185,11 @@ void BibleTime::slotTileHorizontal() {
slotUpdateWindowArrangementActions( m_windowTileHorizontalAction );
}
-/** This slot is connected with the windowAutoCascadeAction object */
-void BibleTime::slotAutoCascade() {
- slotUpdateWindowArrangementActions( m_windowAutoCascadeAction );
-}
-
/** Shows/hides the toolbar */
void BibleTime::slotToggleMainToolbar() {
Q_ASSERT(m_mainToolBar);
- bool currentState = CBTConfig::get(CBTConfig::showMainWindowToolbar);
- CBTConfig::set(CBTConfig::showMainWindowToolbar, !currentState);
+ bool currentState = btConfig().sessionValue<bool>("GUI/showMainToolbar", true);
+ btConfig().setSessionValue("GUI/showMainToolbar", !currentState);
if ( m_showMainWindowToolbarAction->isChecked()) {
m_mainToolBar->show();
}
@@ -297,84 +199,77 @@ void BibleTime::slotToggleMainToolbar() {
}
void BibleTime::slotToggleTextWindowHeader() {
- bool currentState = CBTConfig::get(CBTConfig::showTextWindowHeaders);
- CBTConfig::set(CBTConfig::showTextWindowHeaders, !currentState);
+ bool currentState = btConfig().sessionValue<bool>("GUI/showTextWindowHeaders", true);
+ btConfig().setSessionValue("GUI/showTextWindowHeaders", !currentState);
emit toggledTextWindowHeader(!currentState);
}
void BibleTime::slotToggleNavigatorToolbar() {
- bool currentState = CBTConfig::get(CBTConfig::showTextWindowNavigator);
- CBTConfig::set(CBTConfig::showTextWindowNavigator, !currentState);
- showOrHideToolBars();
- if (CBTConfig::get(CBTConfig::showToolbarsInEachWindow))
+ bool currentState = btConfig().sessionValue<bool>("GUI/showTextWindowNavigator", true);
+ btConfig().setSessionValue("GUI/showTextWindowNavigator", !currentState);
+ if (btConfig().sessionValue<bool>("GUI/showToolbarsInEachWindow", true))
emit toggledTextWindowNavigator(!currentState);
else
- emit toggledTextWindowNavigator(false);
+ m_navToolBar->setVisible(btConfig().sessionValue<bool>("GUI/showTextWindowNavigator", true));
}
void BibleTime::slotToggleToolsToolbar() {
- bool currentState = CBTConfig::get(CBTConfig::showTextWindowToolButtons);
- CBTConfig::set(CBTConfig::showTextWindowToolButtons, !currentState);
- showOrHideToolBars();
- if (CBTConfig::get(CBTConfig::showToolbarsInEachWindow))
+ bool currentState = btConfig().sessionValue<bool>("GUI/showTextWindowToolButtons", true);
+ btConfig().setSessionValue("GUI/showTextWindowToolButtons", !currentState);
+ if (btConfig().sessionValue<bool>("GUI/showToolbarsInEachWindow", true))
emit toggledTextWindowToolButtons(!currentState);
else
- emit toggledTextWindowToolButtons(false);
+ m_toolsToolBar->setVisible(btConfig().sessionValue<bool>("GUI/showTextWindowToolButtons", true));
}
void BibleTime::slotToggleWorksToolbar() {
- bool currentState = CBTConfig::get(CBTConfig::showTextWindowModuleSelectorButtons);
- CBTConfig::set(CBTConfig::showTextWindowModuleSelectorButtons, !currentState);
- showOrHideToolBars();
- if (CBTConfig::get(CBTConfig::showToolbarsInEachWindow))
+ bool currentState = btConfig().sessionValue<bool>("GUI/showTextWindowModuleSelectorButtons", true);
+ btConfig().setSessionValue("GUI/showTextWindowModuleSelectorButtons", !currentState);
+ if (btConfig().sessionValue<bool>("GUI/showToolbarsInEachWindow", true))
emit toggledTextWindowModuleChooser(!currentState);
else
- emit toggledTextWindowModuleChooser(false);
+ m_worksToolBar->setVisible(btConfig().sessionValue<bool>("GUI/showTextWindowModuleSelectorButtons", true));
}
void BibleTime::slotToggleFormatToolbar() {
- bool currentState = CBTConfig::get(CBTConfig::showFormatToolbarButtons);
- CBTConfig::set(CBTConfig::showFormatToolbarButtons, !currentState);
- showOrHideToolBars();
- if (CBTConfig::get(CBTConfig::showToolbarsInEachWindow))
+ bool currentState = btConfig().sessionValue<bool>("GUI/showFormatToolbarButtons", true);
+ btConfig().setSessionValue("GUI/showFormatToolbarButtons", !currentState);
+ if (btConfig().sessionValue<bool>("GUI/showToolbarsInEachWindow", true))
emit toggledTextWindowFormatToolbar(!currentState);
else
- emit toggledTextWindowFormatToolbar(false);
+ m_formatToolBar->setVisible(!currentState);
}
void BibleTime::slotToggleToolBarsInEachWindow() {
- bool currentState = CBTConfig::get(CBTConfig::showToolbarsInEachWindow);
- CBTConfig::set(CBTConfig::showToolbarsInEachWindow, !currentState);
+ bool currentState = btConfig().sessionValue<bool>("GUI/showToolbarsInEachWindow", true);
+ btConfig().setSessionValue("GUI/showToolbarsInEachWindow", !currentState);
showOrHideToolBars();
-
- if (!currentState) {
- emit toggledTextWindowNavigator(CBTConfig::get(CBTConfig::showTextWindowNavigator));
- emit toggledTextWindowToolButtons(CBTConfig::get(CBTConfig::showTextWindowToolButtons));
- emit toggledTextWindowModuleChooser(CBTConfig::get(CBTConfig::showTextWindowModuleSelectorButtons));
- emit toggledTextWindowFormatToolbar(CBTConfig::get(CBTConfig::showFormatToolbarButtons));
- }
- else {
- emit toggledTextWindowNavigator(false);
- emit toggledTextWindowToolButtons(false);
- emit toggledTextWindowModuleChooser(false);
- emit toggledTextWindowFormatToolbar(false);
- }
-
-
}
void BibleTime::showOrHideToolBars() {
- if (CBTConfig::get(CBTConfig::showToolbarsInEachWindow)) {
+ if (btConfig().sessionValue<bool>("GUI/showToolbarsInEachWindow", true)) {
+ // set main window widgets invisible
m_navToolBar->setVisible(false);
m_worksToolBar->setVisible(false);
m_toolsToolBar->setVisible(false);
m_formatToolBar->setVisible(false);
+ // set state of sub window widets
+ emit toggledTextWindowNavigator(btConfig().sessionValue<bool>("GUI/showTextWindowNavigator", true));
+ emit toggledTextWindowModuleChooser(btConfig().sessionValue<bool>("GUI/showTextWindowModuleSelectorButtons", true));
+ emit toggledTextWindowToolButtons(btConfig().sessionValue<bool>("GUI/showTextWindowToolButtons", true));
+ emit toggledTextWindowFormatToolbar(btConfig().sessionValue<bool>("GUI/showFormatToolbarButtons", true));
}
else {
- m_navToolBar->setVisible(CBTConfig::get(CBTConfig::showTextWindowNavigator));
- m_worksToolBar->setVisible(CBTConfig::get(CBTConfig::showTextWindowModuleSelectorButtons));
- m_toolsToolBar->setVisible(CBTConfig::get(CBTConfig::showTextWindowToolButtons));
- m_formatToolBar->setVisible(CBTConfig::get(CBTConfig::showFormatToolbarButtons));
+ // set state of main window widgets
+ m_navToolBar->setVisible(btConfig().sessionValue<bool>("GUI/showTextWindowNavigator", true));
+ m_worksToolBar->setVisible(btConfig().sessionValue<bool>("GUI/showTextWindowModuleSelectorButtons", true));
+ m_toolsToolBar->setVisible(btConfig().sessionValue<bool>("GUI/showTextWindowToolButtons", true));
+ m_formatToolBar->setVisible(btConfig().sessionValue<bool>("GUI/showFormatToolbarButtons", true));
+ //set sub window widgets invisible
+ emit toggledTextWindowNavigator(false);
+ emit toggledTextWindowToolButtons(false);
+ emit toggledTextWindowModuleChooser(false);
+ emit toggledTextWindowFormatToolbar(false);
}
}
@@ -398,12 +293,18 @@ void BibleTime::slotSearchModules() {
Search::CSearchDialog::openDialog(modules, QString::null);
}
+void BibleTime::slotActiveWindowChanged(QMdiSubWindow* window)
+{
+ if (window == 0)
+ m_findWidget->setVisible(false);
+}
+
/* Search default Bible slot
* Call CSearchDialog::openDialog with only the default bible module
*/
void BibleTime::slotSearchDefaultBible() {
QList<const CSwordModuleInfo*> module;
- CSwordModuleInfo* bible = CBTConfig::get(CBTConfig::standardBible);
+ CSwordModuleInfo* bible = btConfig().getDefaultSwordModuleByType("standardBible");
if (bible) {
module.append(bible);
}
@@ -430,117 +331,187 @@ void BibleTime::slotOpenTipDialog() {
dlg->show();
}
-/** Saves the current settings into the currently activated profile. */
-void BibleTime::saveProfile(QAction* action) {
- m_mdi->setUpdatesEnabled(false);
-
- CProfile * p = (CProfile *) action->property("CProfilePointer").value<void *>();
- Q_ASSERT(p);
- Q_ASSERT(p == m_profileMgr.profile(action->text().remove("&")));
- if ( p ) {
- saveProfile(p);
- }
-
- m_mdi->setUpdatesEnabled(true);
-}
+void BibleTime::saveProfile() {
+ // Save main window settings:
+ BtConfig & conf = btConfig();
+ conf.setSessionValue("MainWindow/geometry", saveGeometry());
+ conf.setSessionValue("MainWindow/state", saveState());
+ conf.setSessionValue("MainWindow/MDIArrangementMode", static_cast<int>(m_mdi->getMDIArrangementMode()));
-void BibleTime::saveProfile(CProfile* profile) {
- if (!profile) {
- return;
- }
- //save mainwindow settings
- storeProfileSettings(profile);
+ conf.setSessionValue("FindIsVisible", m_findWidget->isVisibleTo(this));
- QList<CProfileWindow*> profileWindows;
- Q_FOREACH (const QMdiSubWindow * const w, m_mdi->subWindowList(QMdiArea::StackingOrder)) {
+ QStringList windowsList;
+ Q_FOREACH (const QMdiSubWindow * const w,
+ m_mdi->subWindowList(QMdiArea::StackingOrder))
+ {
CDisplayWindow * const displayWindow = dynamic_cast<CDisplayWindow*>(w->widget());
- if (displayWindow == 0) {
+ if (!displayWindow)
continue;
- }
- CProfileWindow * const profileWindow = new CProfileWindow();
- displayWindow->storeProfileSettings(profileWindow);
- profileWindows.append(profileWindow);
+ const QString windowKey = QString::number(windowsList.size());
+ windowsList.append(windowKey);
+ const QString windowGroup = "window/" + windowKey + '/';
+ displayWindow->storeProfileSettings(windowGroup);
}
- profile->save(profileWindows);
-
- //clean up memory - delete all created profile windows
- //profileWindows.setAutoDelete(true);
- qDeleteAll(profileWindows);
- profileWindows.clear();
+ conf.setSessionValue("windowsList", windowsList);
}
-void BibleTime::loadProfile(QAction* action) {
- CProfile * p = (CProfile *) action->property("CProfilePointer").value<void *>();
- Q_ASSERT(p);
- Q_ASSERT(p == m_profileMgr.profile(action->text().remove("&")));
- if ( p ) {
- m_mdi->closeAllSubWindows();
- loadProfile(p);
- }
+void BibleTime::loadProfile(QAction * action) {
+ Q_ASSERT(action);
+ QVariant keyProperty = action->property("ProfileKey");
+ Q_ASSERT(keyProperty.type() == QVariant::String);
+ Q_ASSERT(btConfig().sessionNames().contains(keyProperty.toString()));
+ loadProfile(keyProperty.toString());
}
-void BibleTime::loadProfile(CProfile* p) {
- if (!p)
- return;
-
- QList<CProfileWindow*> windows = p->load();
+void BibleTime::loadProfile(const QString & profileKey) {
+ Q_ASSERT(btConfig().sessionNames().contains(profileKey));
- m_mdi->setUpdatesEnabled(false);//don't auto tile or auto cascade, this would mess up everything!!
+ // do nothing if requested session is the current session
+ if (profileKey == btConfig().currentSessionKey())
+ return;
- //load mainwindow setttings
- applyProfileSettings(p);
+ // Save old profile:
+ saveProfile();
- QWidget* focusWindow = 0;
+ // Close all open windows BEFORE switching profile:
+ m_mdi->closeAllSubWindows();
- // for (CProfileWindow* w = windows.last(); w; w = windows.prev()) { //from the last one to make sure the order is right in the mdi area
- Q_FOREACH (CProfileWindow * w, windows) {
- const QString &key = w->key;
+ // Switch profile Activate profile:
+ btConfig().setCurrentSession(profileKey);
+ reloadProfile();
+ refreshProfileMenus();
+}
- QList<CSwordModuleInfo*> modules;
- Q_FOREACH (const QString &moduleName, w->modules) {
+namespace {
+
+/// Helper object for reloadProfile()
+struct WindowLoadStatus {
+ inline WindowLoadStatus() : window(0) {}
+ QStringList failedModules;
+ QList<CSwordModuleInfo*> okModules;
+ CDisplayWindow * window;
+};
+
+} // anonymous namespace
+
+void BibleTime::reloadProfile() {
+ typedef CMDIArea::MDIArrangementMode MAM;
+ typedef CPlainWriteWindow::WriteWindowType WWT;
+ using message::setQActionCheckedNoTrigger;
+
+ // Cache pointer to config:
+ BtConfig & conf = btConfig();
+
+ // Disable updates while doing big changes:
+ setUpdatesEnabled(false);
+
+ // Close all open windows:
+ m_mdi->closeAllSubWindows();
+
+ // Reload main window settings:
+ restoreGeometry(conf.sessionValue<QByteArray>("MainWindow/geometry"));
+ restoreState(conf.sessionValue<QByteArray>("MainWindow/state"));
+
+ /*
+ * restoreState includes visibility of child widgets, the manually added
+ * qactions (so not including bookmark, bookshelf and mag) are not restored
+ * though, so we restore their state here.
+ */
+ setQActionCheckedNoTrigger(m_windowFullscreenAction, isFullScreen());
+ setQActionCheckedNoTrigger(m_showTextAreaHeadersAction, conf.sessionValue<bool>("GUI/showTextWindowHeaders", true));
+ setQActionCheckedNoTrigger(m_showMainWindowToolbarAction, conf.sessionValue<bool>("GUI/showMainToolbar", true));
+ setQActionCheckedNoTrigger(m_showTextWindowNavigationAction, conf.sessionValue<bool>("GUI/showTextWindowNavigator", true));
+ setQActionCheckedNoTrigger(m_showTextWindowModuleChooserAction, conf.sessionValue<bool>("GUI/showTextWindowModuleSelectorButtons", true));
+ setQActionCheckedNoTrigger(m_showTextWindowToolButtonsAction, conf.sessionValue<bool>("GUI/showTextWindowToolButtons", true));
+ setQActionCheckedNoTrigger(m_showFormatToolbarAction, conf.sessionValue<bool>("GUI/showFormatToolbarButtons", true));
+ setQActionCheckedNoTrigger(m_toolbarsInEachWindow, conf.sessionValue<bool>("GUI/showToolbarsInEachWindow", true));
+
+ m_mdi->setMDIArrangementMode(static_cast<MAM>(conf.sessionValue<int>("MainWindow/MDIArrangementMode")));
+
+ m_findWidget->setVisible(conf.sessionValue<bool>("FindIsVisible", false));
+
+ QWidget * focusWindow = 0;
+ QMap<QString, WindowLoadStatus> failedWindows;
+ Q_FOREACH (const QString & w,
+ conf.sessionValue<QStringList>("windowsList"))
+ {
+ const QString windowGroup = "window/" + w + '/';
+
+ // Try to determine window modules:
+ WindowLoadStatus wls;
+ Q_FOREACH (const QString &moduleName,
+ conf.sessionValue<QStringList>(windowGroup + "modules"))
+ {
CSwordModuleInfo * const m = CSwordBackend::instance()->findModuleByName(moduleName);
- if (m != 0) {
- modules.append(m);
+ if (m) {
+ wls.okModules.append(m);
+ } else {
+ wls.failedModules.append(moduleName);
}
}
- if (modules.isEmpty()) { //are the modules still installed? If not continue wih next session window
+
+ // Check whether the window totally failed (no modules can be loaded):
+ if (wls.okModules.isEmpty()) {
+ failedWindows.insert(w, wls);
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, CWriteWindow::WriteWindowType(w->writeWindowType) );
- }
- else { //create a read window
- displayWindow = createReadDisplayWindow(modules, key);
+ // Check whether the window partially failed:
+ if (!wls.failedModules.isEmpty())
+ failedWindows.insert(w, wls);
+
+ // Try to respawn the window:
+ Q_ASSERT(!wls.window);
+ const QString key = conf.sessionValue<QString>(windowGroup + "key");
+ WWT wwt = static_cast<WWT>(conf.sessionValue<int>(windowGroup + "writeWindowType", 0));
+ if (wwt > 0) {
+ // Note, that we *might* lose the rest of wls.okModules here:
+ if (wls.okModules.size() > 1)
+ qWarning() << "Got more modules for a \"write window\" than expected from the profile!";
+
+ wls.window = createWriteDisplayWindow(wls.okModules.first(), key, wwt);
+ } else {
+ wls.window = createReadDisplayWindow(wls.okModules, key);
}
- if (displayWindow) { //if a window was created initialize it.
- if (w->hasFocus) {
- focusWindow = displayWindow;
- }
-
- displayWindow->applyProfileSettings(w);
+ if (wls.window) {
+ wls.window->applyProfileSettings(windowGroup);
+ if (conf.sessionValue<bool>(windowGroup + "hasFocus", false))
+ focusWindow = wls.window;
+ } else {
+ failedWindows.insert(w, wls);
}
}
- m_mdi->setUpdatesEnabled(true);
+ /* This call is necessary to restore the visibility of the toolbars in the child
+ * windows, since their state is not saved automatically.
+ */
+ showOrHideToolBars();
+
+ // Re-arrange MDI:
m_mdi->triggerWindowUpdate();
- if (focusWindow) {
+ // Activate focused window:
+ if (focusWindow)
focusWindow->setFocus();
- }
+
+ // Re-enable updates and repaint:
+ setUpdatesEnabled(true);
+ repaint(); /// \bug The main window (except decors) is all black without this (not even hover over toolbar buttons work)
+ raise(); /// \bug The main window would not refresh at all. A call to this function or adjustSize() seems to fix this
+
+ /// \todo For windows in failedWindows ask whether to keep the settings / close windows etc
}
void BibleTime::deleteProfile(QAction* action) {
- //HACK: work around the inserted & char by KPopupMenu
- CProfile * p = (CProfile *) action->property("CProfilePointer").value<void *>();
- Q_ASSERT(p);
- Q_ASSERT(p == m_profileMgr.profile(action->text().remove("&")));
- if (p)
- m_profileMgr.remove(p);
+ Q_ASSERT(action);
+ QVariant keyProperty = action->property("ProfileKey");
+ Q_ASSERT(keyProperty.type() == QVariant::String);
+ Q_ASSERT(btConfig().sessionNames().contains(keyProperty.toString()));
+
+ /// \todo Ask for confirmation
+ btConfig().deleteSession(keyProperty.toString());
refreshProfileMenus();
}
@@ -551,40 +522,75 @@ void BibleTime::toggleFullscreen() {
/** 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);
+ BtConfig & conf = btConfig();
+
+ // Get new unique name:
+ QString name;
+ for (;;) {
+ bool ok;
+ name = QInputDialog::getText(
+ this, tr("New Session"),
+ tr("Please enter a name for the new session."),
+ QLineEdit::Normal, name, &ok);
+ if (!ok)
+ return;
+
+ if (!name.isEmpty()) {
+ // Check whether name already exists:
+ if (conf.sessionNames().values().contains(name)) {
+ message::showInformation(this, tr("Session already exists"),
+ tr("Session with the name \"%1\" "
+ "already exists. Please provide a "
+ "different name.").arg(name));
+ } else {
+ break;
+ }
+ }
}
+
+ // Also save old profile:
+ saveProfile();
+
+ // Save new profile:
+ conf.setCurrentSession(conf.addSession(name));
+ saveProfile();
+
+ // Refresh profile menus:
refreshProfileMenus();
}
-/** Slot to refresh the save profile and load profile menus. */
+/** Slot to refresh the saved profile and load profile menus. */
void BibleTime::refreshProfileMenus() {
- m_windowSaveProfileMenu->clear();
+ typedef BtConfig::SessionNamesHashMap SNHM;
+ typedef SNHM::const_iterator SNHMCI;
+
m_windowLoadProfileMenu->clear();
m_windowDeleteProfileMenu->clear();
- //refresh the load, save and delete profile menus
- m_profileMgr.refresh();
- const QList<CProfile*> profiles = m_profileMgr.profiles();
+ BtConfig & conf = btConfig();
+ const BtConfig::SessionNamesHashMap &sessions = conf.sessionNames();
- const bool enableActions = !profiles.isEmpty();
- m_windowSaveProfileMenu->setEnabled(enableActions);
+ const bool enableActions = sessions.size() > 1;
m_windowLoadProfileMenu->setEnabled(enableActions);
m_windowDeleteProfileMenu->setEnabled(enableActions);
- Q_FOREACH (const CProfile * const p, profiles) {
- const QString &profileName = p->name();
- QAction * a;
- a = m_windowSaveProfileMenu->addAction(profileName);
- a->setProperty("CProfilePointer", QVariant::fromValue((void *) p));
- a = m_windowLoadProfileMenu->addAction(profileName);
- a->setProperty("CProfilePointer", QVariant::fromValue((void *) p));
- a = m_windowDeleteProfileMenu->addAction(profileName);
- a->setProperty("CProfilePointer", QVariant::fromValue((void *) p));
+
+ if (enableActions) {
+ for (SNHMCI it = sessions.constBegin(); it != sessions.constEnd(); ++it) {
+ QAction * a;
+
+ a = m_windowLoadProfileMenu->addAction(it.value());
+ a->setProperty("ProfileKey", it.key());
+ a->setActionGroup(m_windowLoadProfileActionGroup);
+ a->setCheckable(true);
+ if (it.key() == conf.currentSessionKey())
+ a->setChecked(true);
+
+ a = m_windowDeleteProfileMenu->addAction(it.value());
+ a->setProperty("ProfileKey", it.key());
+ if (it.key() == conf.currentSessionKey())
+ a->setDisabled(true);
+ }
}
}