[bt-devel] refactoring::namespace

Olaf Radicke briefkasten at olaf-radicke.de
Sat Jul 10 06:06:07 MST 2010


Hi!

I have try BibleTime move in ../gui/ but i don't understand the make file.
So i think, it is a little magic??

Olaf Radicke 
-------------- next part --------------
diff --git a/trunk/bibletime/cmake/BTSourceFileList.cmake b/trunk/bibletime/cmake/BTSourceFileList.cmake
index 964007c..5d192e5 100644
--- a/trunk/bibletime/cmake/BTSourceFileList.cmake
+++ b/trunk/bibletime/cmake/BTSourceFileList.cmake
@@ -15,6 +15,14 @@ SET(bibletime_SRC
 
 SOURCE_GROUP("src" FILES ${bibletime_SRC})
 
+
+# Namespace and directory "Gui"
+SET(bibletime_SRC_GUI
+    # Toplevel files:
+    src/gui/bibletime.cpp
+)
+SOURCE_GROUP("src\\gui" FILES ${bibletime_SRC_GUI})
+
 SET(bibletime_SRC_BACKEND
 	# Backend top level:
 	src/backend/btmoduletreeitem.cpp
@@ -428,6 +436,7 @@ SET(bibletime_SOURCES
     ${bibletime_SRC_FRONTEND_KEYCHOOSER_VERSEKEYCHOOSER}
     ${bibletime_SRC_FRONTEND_DISPLAY}
     ${bibletime_SRC_FRONTEND_DISPLAYWINDOW}
+    ${bibletime_SRC_GUI}
 )
 
 
diff --git a/trunk/bibletime/src/bibletime.cpp b/trunk/bibletime/src/bibletime.cpp
deleted file mode 100644
index 2bd0747..0000000
--- a/trunk/bibletime/src/bibletime.cpp
+++ /dev/null
@@ -1,383 +0,0 @@
-/*********
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2010 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#include "bibletime.h"
-
-#include <cstdlib>
-#include <iostream>
-#include <ctime>
-#include <QAction>
-#include <QApplication>
-#include <QCloseEvent>
-#include <QDate>
-#include <QDebug>
-#include <QInputDialog>
-#include <QMdiSubWindow>
-#include <QMessageBox>
-#include <QSplashScreen>
-#include <QSplitter>
-#include "backend/config/cbtconfig.h"
-#include "backend/drivers/cswordbiblemoduleinfo.h"
-#include "backend/drivers/cswordbookmoduleinfo.h"
-#include "backend/drivers/cswordcommentarymoduleinfo.h"
-#include "backend/drivers/cswordlexiconmoduleinfo.h"
-#include "backend/drivers/cswordmoduleinfo.h"
-#include "backend/keys/cswordldkey.h"
-#include "backend/keys/cswordversekey.h"
-#include "frontend/btaboutmoduledialog.h"
-#include "frontend/cmdiarea.h"
-#include "frontend/displaywindow/btactioncollection.h"
-#include "frontend/displaywindow/cdisplaywindow.h"
-#include "frontend/displaywindow/cdisplaywindowfactory.h"
-#include "frontend/displaywindow/creadwindow.h"
-#include "frontend/displaywindow/cwritewindow.h"
-#include "frontend/keychooser/ckeychooser.h"
-#include "frontend/searchdialog/csearchdialog.h"
-#include "util/cresmgr.h"
-#include "util/directory.h"
-
-
-using namespace Profile;
-
-BibleTime *BibleTime::m_instance = 0;
-
-BibleTime::BibleTime(QWidget *parent, Qt::WindowFlags flags)
-    : QMainWindow(parent, flags), m_WindowWasMaximizedBeforeFullScreen(false)
-{
-    namespace DU = util::directory;
-
-    Q_ASSERT(m_instance == 0);
-    m_instance = this;
-
-    QSplashScreen splash;
-    bool showSplash = CBTConfig::get(CBTConfig::logo);
-    QString splashHtml;
-
-    if (showSplash) {
-        splashHtml = "<div style='background:transparent;color:white;font-weight:bold'>%1"
-                     "</div>";
-        const QDate date(QDate::currentDate());
-        const int day = date.day();
-        const int month = date.month();
-        QString splashImage(DU::getPicsDir().canonicalPath().append("/"));
-
-        if ((month >= 12 && day >= 24) || (month <= 1 && day < 6)) {
-            splashImage.append("startuplogo_christmas.png");
-        } else {
-            splashImage.append("startuplogo.png");
-        }
-
-        QPixmap pm;
-        if (!pm.load(splashImage)) {
-            qWarning("Can't load startuplogo! Check your installation.");
-        }
-        splash.setPixmap(pm);
-        splash.show();
-
-        splash.showMessage(splashHtml.arg(tr("Initializing the SWORD engine...")),
-                           Qt::AlignCenter);
-    }
-    initBackends();
-
-    if (showSplash) {
-        splash.showMessage(splashHtml.arg(tr("Creating BibleTime's user interface...")),
-                           Qt::AlignCenter);
-    }
-    initView();
-
-    if (showSplash) {
-        splash.showMessage(splashHtml.arg(tr("Initializing menu- and toolbars...")),
-                           Qt::AlignCenter);
-    }
-    initActions();
-    initMenubar();
-    initToolbars();
-    initConnections();
-    readSettings();
-
-    setWindowTitle("BibleTime " BT_VERSION);
-    setWindowIcon(DU::getIcon(CResMgr::mainWindow::icon));
-    retranslateUi();
-}
-
-BibleTime::~BibleTime() {
-    //  delete m_dcopInterface;
-    // The backend is deleted by the BibleTimeApp instance
-#ifdef BT_DEBUG
-    deleteDebugWindow();
-#endif
-    saveSettings();
-}
-
-/** Saves the properties of BibleTime to the application wide configfile  */
-void BibleTime::saveSettings() {
-    /// \todo how to write settings?
-    //accel()->writeSettings(CBTConfig::getConfig());
-
-    CBTConfig::set(CBTConfig::toolbar, m_viewToolbarAction->isChecked());
-
-    // set the default to false
-    /* CBTConfig::set(CBTConfig::autoTileVertical, false);
-     CBTConfig::set(CBTConfig::autoTileHorizontal, false);
-     CBTConfig::set(CBTConfig::autoCascade, false);
-    */
-    CBTConfig::set(CBTConfig::autoTileVertical, m_windowAutoTileVerticalAction->isChecked());
-    CBTConfig::set(CBTConfig::autoTileHorizontal, m_windowAutoTileHorizontalAction->isChecked());
-    CBTConfig::set(CBTConfig::autoTile, m_windowAutoTileAction->isChecked());
-    CBTConfig::set(CBTConfig::autoTabbed, m_windowAutoTabbedAction->isChecked());
-    CBTConfig::set(CBTConfig::autoCascade, m_windowAutoCascadeAction->isChecked());
-
-    CProfile* p = m_profileMgr.startupProfile();
-    if (p) {
-        saveProfile(p);
-    }
-}
-
-/** Reads the settings from the configfile and sets the right properties. */
-void BibleTime::readSettings() {
-    qDebug() << "******************BibleTime::readSettings******************************";
-    //  accel()->readSettings(CBTConfig::getConfig());
-    CBTConfig::setupAccelSettings(CBTConfig::application, m_actionCollection);
-
-    m_viewToolbarAction->setChecked( CBTConfig::get(CBTConfig::toolbar) );
-    slotToggleMainToolbar();
-
-    if ( CBTConfig::get(CBTConfig::autoTileVertical) ) {
-        m_windowAutoTileVerticalAction->setChecked( true );
-        m_windowManualModeAction->setChecked(false);
-        slotAutoTileVertical();
-    }
-    else if ( CBTConfig::get(CBTConfig::autoTileHorizontal) ) {
-        m_windowAutoTileHorizontalAction->setChecked( true );
-        m_windowManualModeAction->setChecked(false);
-        slotAutoTileHorizontal();
-    }
-    else if ( CBTConfig::get(CBTConfig::autoTile) ) {
-        m_windowAutoTileAction->setChecked(true);
-        m_windowManualModeAction->setChecked(false);
-        slotAutoTile();
-    }
-    else if ( CBTConfig::get(CBTConfig::autoTabbed) ) {
-        m_windowAutoTabbedAction->setChecked(true);
-        m_windowManualModeAction->setChecked(false);
-        slotAutoTabbed();
-    }
-    else if ( CBTConfig::get(CBTConfig::autoCascade) ) {
-        m_windowAutoCascadeAction->setChecked(true);
-        m_windowManualModeAction->setChecked(false);
-        slotAutoCascade();
-    }
-    else {
-        m_windowManualModeAction->setChecked(true);
-        slotManualArrangementMode();
-    }
-}
-
-/** Creates a new presenter in the MDI area according to the type of the module. */
-CDisplayWindow* BibleTime::createReadDisplayWindow(QList<CSwordModuleInfo*> modules, const QString& key) {
-    qApp->setOverrideCursor( QCursor(Qt::WaitCursor) );
-    qDebug() << "BibleTime::createReadDisplayWindow(QList<CSwordModuleInfo*> modules, const QString& key)";
-    CDisplayWindow* displayWindow = CDisplayWindowFactory::createReadInstance(modules, m_mdi);
-    if ( displayWindow ) {
-        displayWindow->init();
-	m_mdi->addSubWindow(displayWindow); 
-        displayWindow->show();
-        //   if (!key.isEmpty())
-        displayWindow->lookupKey(key);
-    }
-    // We have to process pending events here, otherwise displayWindow is not fully painted
-    qApp->processEvents();
-    // Now all events, including mouse clicks for the displayWindow have been handled
-    // and we can let the user click the same module again
-    //m_bookshelfPage->unfreezeModules(modules);
-    qApp->restoreOverrideCursor();
-    return displayWindow;
-}
-
-
-/** Creates a new presenter in the MDI area according to the type of the module. */
-CDisplayWindow* BibleTime::createReadDisplayWindow(CSwordModuleInfo* module, const QString& key) {
-    QList<CSwordModuleInfo*> list;
-    list.append(module);
-
-    return createReadDisplayWindow(list, key);
-}
-
-CDisplayWindow* BibleTime::createWriteDisplayWindow(CSwordModuleInfo* module, const QString& key, const CDisplayWindow::WriteWindowType& type) {
-    qApp->setOverrideCursor( QCursor(Qt::WaitCursor) );
-
-    QList<CSwordModuleInfo*> modules;
-    modules.append(module);
-
-    CDisplayWindow* displayWindow = CDisplayWindowFactory::createWriteInstance(modules, m_mdi, type);
-    if ( displayWindow ) {
-        displayWindow->init();
-        if (m_mdi->subWindowList().count() == 0)
-            displayWindow->showMaximized();
-        else
-            displayWindow->show();
-        displayWindow->lookupKey(key);
-    }
-
-    qApp->restoreOverrideCursor();
-    return displayWindow;
-}
-
-CDisplayWindow* BibleTime::moduleEditPlain(CSwordModuleInfo *module) {
-    /// \todo Refactor this.
-    return createWriteDisplayWindow(module,
-                                    QString::null,
-                                    CDisplayWindow::PlainTextWindow);
-}
-
-CDisplayWindow* BibleTime::moduleEditHtml(CSwordModuleInfo *module) {
-    /// \todo Refactor this.
-    return createWriteDisplayWindow(module,
-                                    QString::null,
-                                    CDisplayWindow::HTMLWindow);
-}
-
-
-void BibleTime::searchInModule(CSwordModuleInfo *module) {
-    /// \todo Refactor this.
-    QList<CSwordModuleInfo *> modules;
-    modules.append(module);
-    Search::CSearchDialog::openDialog(modules, QString::null);
-}
-
-bool BibleTime::moduleUnlock(CSwordModuleInfo *module, QWidget *parent) {
-    /// \todo Write a proper unlocking dialog with integrated error messages.
-    QString unlockKey;
-    bool ok;
-    for (;;) {
-        unlockKey = QInputDialog::getText(
-            parent, tr("Unlock Work"), tr("Enter the unlock key for %1.").arg(module->name()),
-            QLineEdit::Normal, module->config(CSwordModuleInfo::CipherKey), &ok
-        );
-        if (!ok) return false;
-        module->unlock(unlockKey);
-
-        /// \todo refactor this module reload
-        /* There is currently a deficiency in sword 1.6.1 in that backend->setCipherKey() does
-         * not work correctly for modules from which data was already fetched. Therefore we have to
-         * reload the modules.
-         */
-        {
-            const QString moduleName(module->name());
-            CSwordBackend *backend = CSwordBackend::instance();
-            backend->reloadModules(CSwordBackend::OtherChange);
-            module = backend->findModuleByName(moduleName);
-            Q_ASSERT(module != 0);
-        }
-
-        if (!module->isLocked()) break;
-        QMessageBox::warning(parent, tr("Warning: Invalid unlock key!"),
-                             tr("The unlock key you provided did not properly unlock this "
-                                "module. Please try again."));
-    }
-    return true;
-}
-
-void BibleTime::slotModuleUnlock(CSwordModuleInfo *module) {
-    moduleUnlock(module, this);
-}
-
-void BibleTime::moduleAbout(CSwordModuleInfo *module) {
-    BTAboutModuleDialog *dialog = new BTAboutModuleDialog(module, this);
-    dialog->setAttribute(Qt::WA_DeleteOnClose); // Destroy dialog when closed
-    dialog->show();
-    dialog->raise();
-}
-
-/** Refreshes all presenters.*/
-void BibleTime::refreshDisplayWindows() {
-    foreach (QMdiSubWindow* subWindow, m_mdi->subWindowList()) {
-        if (CDisplayWindow* window = dynamic_cast<CDisplayWindow*>(subWindow->widget())) {
-            window->reload(CSwordBackend::OtherChange);
-        }
-    }
-}
-
-/** Refresh main window accelerators */
-void BibleTime::refreshBibleTimeAccel() {
-    CBTConfig::setupAccelSettings(CBTConfig::application, m_actionCollection);
-}
-
-void BibleTime::closeEvent(QCloseEvent *event) {
-    /*
-      Sequentially queries all open subwindows whether its fine to close them. If some sub-
-      window returns false, the querying is stopped and the close event is ignored. If all
-      subwindows return true, the close event is accepted.
-    */
-    Q_FOREACH(QMdiSubWindow *subWindow, m_mdi->subWindowList()) {
-        if (CDisplayWindow* window = dynamic_cast<CDisplayWindow*>(subWindow->widget())) {
-            if (!window->queryClose()) {
-                event->ignore();
-                return;
-            }
-        }
-    }
-    event->accept();
-}
-
-/** Restores the workspace if the flag for this is set in the config. */
-void BibleTime::restoreWorkspace() {
-    if (CProfile* p = m_profileMgr.startupProfile()) {
-        loadProfile(p);
-    }
-}
-
-/** Processes the commandline options given to BibleTime. */
-void BibleTime::processCommandline() {
-    QStringList args = qApp->QCoreApplication::arguments();
-
-    if (args.contains("--help") || args.contains("-h") || args.contains("/h") || args.contains("/?")) {
-        std::cout << "BibleTime" << std::endl << "--help (-h, /h, /?): Show this help message and exit"
-                  << std::endl << "--ignore-session: open a clean session" << std:: endl << "--open-default-bible <ref>: "
-                  << "Open the default Bible with the reference <ref>" << std::endl;
-        std::cout << "Some Qt arguments:" << std::endl << "-reverse: reverse the UI layout direction"
-                  << std::endl;
-        exit(0);
-        //printHelpAndExit();
-    }
-    if ( !CBTConfig::get(CBTConfig::crashedTwoTimes) &&
-            !args.contains("--ignore-session") ) {
-        restoreWorkspace();
-    }
-
-    if ( args.contains("--open-default-bible") &&
-            !CBTConfig::get(CBTConfig::crashedLastTime) &&
-            !CBTConfig::get(CBTConfig::crashedTwoTimes)) {
-        int index = args.indexOf("--open-default-bible");
-        QString bibleKey;
-        if (index >= 0 && (index + 1) < args.size()) {
-            bibleKey = args.at(index + 1);
-        }
-        CSwordModuleInfo* bible = CBTConfig::get(CBTConfig::standardBible);
-        if (bibleKey == "random") {
-            CSwordVerseKey vk(0);
-            const int maxIndex = 31100;
-            time_t seconds;
-            seconds = time (NULL);
-            srand(seconds);
-            int newIndex = rand() % maxIndex;
-            vk.setPosition(sword::TOP);
-            vk.Index(newIndex);
-            bibleKey = vk.key();
-        }
-        createReadDisplayWindow(bible, bibleKey);
-        m_mdi->myTileVertical();//we are sure only one window is open, which should be displayed fullscreen in the working area
-    }
-}
-
-bool BibleTime::event(QEvent* event) {
-    if (event->type() == QEvent::Close)
-        Search::CSearchDialog::closeDialog();
-    return QMainWindow::event(event);
-}
diff --git a/trunk/bibletime/src/bibletime.h b/trunk/bibletime/src/bibletime.h
deleted file mode 100644
index bac0d69..0000000
--- a/trunk/bibletime/src/bibletime.h
+++ /dev/null
@@ -1,553 +0,0 @@
-/*********
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2010 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#ifndef BIBLETIME_H
-#define BIBLETIME_H
-
-#include <QMainWindow>
-
-#include <QList>
-#include "frontend/displaywindow/cdisplaywindow.h"
-#include "frontend/profile/cprofile.h"
-#include "frontend/profile/cprofilemgr.h"
-#include <QSignalMapper>
-#ifdef BT_DEBUG
-#include <QMutex>
-#endif
-
-
-namespace InfoDisplay {
-class CInfoDisplay;
-}
-class BtActionClass;
-class BtBookshelfDockWidget;
-class BtOpenWorkAction;
-class CBookmarkIndex;
-class CDisplayWindow;
-class CMDIArea;
-class CSwordModuleInfo;
-class QAction;
-class QLabel;
-class QMenu;
-class QToolBar;
-class QSplitter;
-class QSignalMapper;
-
-/**
-  * @page backend The structure of the backend
-  * <p>
-  * The backend implementation for Sword is called CSwordBackend, the classes we use
-  * to work with keys are called CSwordVerseKey and CSwordLDKey, both are derived from
-  * the class CSwordKey.
-  * The CSwordKey derived classes used for Sword do also inherit the classes
-  * VerseKey (CSwordVerseKey)
-  * and SWKey (CSwordLDKey).
-  * </p>
-  * <p>
-  * The classes used to handle all module based stuff are derived from CSwordModuleInfo.
-  * The module classes are: CSwordModuleInfo (for Sword modules),
-  * CSwordBibleModuleInfo (for bibles), CSwordCommentaryModuleInfo (for commentaries) and
-  * CSwordLexiconModuleInfo (for lexicons).
-  * Have a look at the class documentation of the mentioned classes to learn how the
-  * structure of them looks like and which class inherits which other class.
-  * </p>
-  * <p>
-  * The first objects which should be created in the application is the backend
-  * (for Sword the class is called CSwordBackend).
-  * Then create all the different module classes for the correct Sword modules.
-  * Have a look at
-  * BibleTime::initBackens() to see how it's done in BibleTime. at br
-  * Later you can work with them for example by using the CSwordKey and
-  * CSwordModuleInfo derived class.
-  * </p>
-  */
-
-/**
-  * @page frontend The structure of the frontend
-  *
-  * <p>
-  * The frontend contains the classes which interact with the user. For example the 
-  * display windows, the searchdialog or the other parts.
-  * </p><p>
-  * The display windows which provide functionality are CBibleReadWindow for
-  * Bibles, CBookReadWindow for books, CCommentaryReadWindow for commentaries and CLexiconReadWindow for
-  * lexicon and dictionaries.
-  * </p><p>
-  * 
-  * The class CDisplay is the class that various views with in the windows are derived. 
-  * </p><p>
-  *
-  * Another important part of the frontend are the keychoosers.
-  * They provide an interface to choose a key of a module.
-  * The interface for different module types is different.
-  * The base class is CKeyChooser which is the factory for the derived classes.
-  * Use the function CKeyChooser::createInstance to get the correct
-  * keychooser implementation for the desired module.<br/>
-  * </p><p>
-  * Some major toolbar widgets are CKeyChooser and BtDisplaySettingsButton.
-  * </p>
-  */
-
-/** @mainpage BibleTime - sourcecode documentation
- * BibleTime main page.
- * <p>This is the sourcecode documentation of BibleTime, a Bible study tool.
- * <p>
- * The main class of BibleTime is called @ref BibleTime, which is the main window
- * and initializes all important parts at startup. 
- * </p><p>
- * BibleTime is divided in two major parts, the backend and the frontend.
- * The text display windows belong to the @ref frontend.
- * The backend is mainly a wrapper around Sword's classes to use Qt functionality
- * to allow easy access to it's functionality and to have it in a (more or less :)
- * object oriented structure.</p><br/>
- * <p>
- *       -Introduction to the frontend: @ref frontend.<br/>
- *       -Introduction to the backend: @ref backend<br/>
- * </p>
- */
-
-/** BibleTime's main class.
- * The main class of BibleTime. Here are the main widgets created.
- *
- * This is the main class of BibleTime! This class creates the GUI, the QAction objects
- * and connects to some slots. Please insert the creation of actions in initActions,
- * the creation of widgets into initView and the connect(...) calls into initConnections.
- * Reading from a config file on creation time should go into readSettings(), saving into
- * saveSettings().
- * This is the general way of all BibleTime classes.
- */
-class BibleTime : public QMainWindow {
-        friend class CDisplayWindow;
-        friend class BibleTimeDBusAdaptor;
-        Q_OBJECT
-
-    public:
-
-        BibleTime(QWidget *parent = 0, Qt::WindowFlags flags = 0);
-
-        ~BibleTime();
-
-        static inline BibleTime *instance() { return m_instance; }
-
-        /**
-        * Reads the settings from the configfile and sets the right properties.
-        */
-        void readSettings();
-        /**
-        * Saves the settings of this class
-        */
-        void saveSettings();
-        /**
-        * Restores the workspace if the flaf for this is set in the config.
-        */
-        void restoreWorkspace();
-        /**
-        * Apply the settings given by the profile p
-        */
-        void applyProfileSettings( Profile::CProfile* p );
-        /**
-        * Stores the settings of the mainwindow in the profile p
-        */
-        void storeProfileSettings( Profile::CProfile* p );
-        /**
-        *  Save the configuration dialog settings, don't open dialog
-        */
-        void saveConfigSettings();
-        /**
-        * Get pointer to Navigation toolbar
-        */
-        inline QToolBar *navToolBar() const {
-            return m_navToolBar;
-        }
-        /**
-        * Get pointer to Works toolbar
-        */
-        inline BtModuleChooserBar *worksToolBar() const {
-            return m_worksToolBar;
-        }
-        /**
-        * Get pointer to Tools toolbar
-        */
-        inline QToolBar *toolsToolBar() const {
-            return m_toolsToolBar;
-        }
-        /**
-        * Get pointer to Format toolbar
-        */
-        inline QToolBar *formatToolBar() const {
-            return m_formatToolBar;
-        }
-
-        /**
-          \returns a pointer to the info display.
-        */
-        inline InfoDisplay::CInfoDisplay *infoDisplay() const {
-            return m_infoDisplay;
-        }
-
-        /**
-        * Clears the actions of the MDI related toolbars
-        */
-        void clearMdiToolBars();
-
-        /**
-          Displays a dialog which asks the user an unlock key for the given module and tries
-          to unlock the module. If an invalid unlock key is given, a warning message is
-          issued and the user is again asked for the key.
-          \param[in] module The module to unlock.
-          \param[in] parent The parent widget for the unlock dialogs.
-          \returns whether the module was successfully unlocked.
-        */
-        static bool moduleUnlock(CSwordModuleInfo *module, QWidget *parent = 0);
-
-    public slots:
-        /**
-        * Opens the optionsdialog of BibleTime.
-        */
-        void slotSettingsOptions();
-        /**
-        * Opens the optionsdialog of BibleTime.
-        */
-        void slotSwordSetupDialog();
-        /**
-        * Opens the handbook.
-        */
-        void openOnlineHelp_Handbook();
-        /**
-        * Opens the bible study howto.
-        */
-        void openOnlineHelp_Howto();
-        /**
-        * Processes the commandline options given to BibleTime.
-        */
-        void processCommandline();
-        /**
-        * Creates QAction's that have keyboard shortcuts
-        */
-        static void insertKeyboardActions( BtActionCollection* const a );
-
-    protected: // Protected methods
-        /**
-        * Catch QMainWindow events
-        */
-        bool event(QEvent* event);
-        /**
-        * Create the main window menu and toolbar
-        */
-        void createMenuAndToolBar();
-        /**
-        * Initializes the sword.conf in the $HOME\Sword directory
-        */
-        void initSwordConfigFile();
-        /**
-        * Initializes the view of this widget
-        */
-        void initView();
-        /**
-        * Initializes the menubar of BibleTime.
-        */
-        void initMenubar();
-        /**
-        * Initializes the SIGNAL / SLOT connections
-        */
-        void initConnections();
-        /**
-        * Initializes the backend
-        */
-        void initBackends();
-        /**
-        * Initializes the action objects of the GUI
-        */
-        void initActions();
-        /**
-          Initializes the toolbars.
-        */
-        void initToolbars();
-        /**
-          Retranslates the UI.
-        */
-        void retranslateUi();
-        /**
-          Retranslates the UI actions.
-        */
-        static void retranslateUiActions(BtActionCollection* ac);
-        /**
-        * Initializes one action object
-        */
-        QAction* initAction(QAction* action, QString text, QString icon, QKeySequence accel,
-                            const QString& tooltip, const QString& actionName, const char* slot );
-        /**
-        * Refreshes all presenter supporting at least in of the features given as parameter.
-        */
-        void refreshDisplayWindows();
-        /**
-        * Refresh main window accelerators
-        */
-        void refreshBibleTimeAccel();
-
-        /**
-        * Reimplemented from QWidget.
-        */
-        void closeEvent(QCloseEvent *event);
-
-    protected slots:
-        /**
-         * Creates a new presenter in the MDI area according to the type of the module.
-         */
-        CDisplayWindow* createReadDisplayWindow(QList<CSwordModuleInfo*> modules, const QString& key);
-        CDisplayWindow* createReadDisplayWindow(CSwordModuleInfo* module, const QString& key = QString::null);
-        CDisplayWindow* createWriteDisplayWindow(CSwordModuleInfo* module, const QString& key, const CDisplayWindow::WriteWindowType& type);
-        CDisplayWindow* moduleEditPlain(CSwordModuleInfo *module);
-        CDisplayWindow* moduleEditHtml(CSwordModuleInfo *module);
-        void searchInModule(CSwordModuleInfo *module);
-        void slotModuleUnlock(CSwordModuleInfo *module);
-        void moduleAbout(CSwordModuleInfo *module);
-        void quit();
-
-        /**
-         * Is called when the window menu is about to show ;-)
-         */
-        void slotWindowMenuAboutToShow();
-        /**
-         * Is called when the open windows menu is about to show ;-)
-         */
-        void slotOpenWindowsMenuAboutToShow();
-        /**
-         * This slot is connected with the windowAutoTileVerticalAction object
-         */
-        void slotAutoTileVertical();
-        /**
-         * This slot is connected with the windowAutoTileHorizontalAction object
-         */
-        void slotAutoTileHorizontal();
-        /**
-         * This slot is connected with the windowAutoTileAction object
-         */
-        void slotAutoTile();
-        /**
-         * This slot is connected with the windowAutoTabbedAction object
-         */
-        void slotAutoTabbed();
-        /**
-         * This slot is connected with the windowAutoCascadeAction object
-         */
-        void slotAutoCascade();
-        void slotUpdateWindowArrangementActions( QAction* );
-
-        void slotCascade();
-        void slotTile();
-        void slotTileVertical();
-        void slotTileHorizontal();
-
-        void slotManualArrangementMode();
-
-        /**
-         * Shows/hides the main toolbar
-         */
-        void slotToggleMainToolbar();
-        void slotToggleToolsToolbar();
-        void slotToggleNavigatorToolbar();
-        void slotToggleWorksToolbar();
-        void slotToggleFormatToolbar();
-
-        void slotToggleToolBarsInEachWindow();
-        
-        /**
-        * Shows/hides the text window text area headers and sets
-        * configuration that newly opened windows don't user headers.
-        */
-        void slotToggleTextWindowHeader();
-
-        /**
-         * Used to set the active menu
-         */
-        void slotSetActiveSubWindow(QWidget* window);
-        /**
-        * Saves to the profile with the menu id ID
-        */
-        void saveProfile(QAction* action);
-        /**
-        * Saves the current settings into the currently activatred profile.
-        */
-        void saveProfile(Profile::CProfile* p);
-        /**
-        * Deletes the chosen session from the menu and from disk.
-        */
-        void deleteProfile(QAction* action);
-        /**
-        * Loads the profile with the menu id ID
-        */
-        void loadProfile(QAction* action);
-        /**
-        * Loads the profile with the menu ID id
-        */
-        void loadProfile(Profile::CProfile* p);
-        /**
-        * Toggles between normal and fullscreen mode.
-        */
-        void toggleFullscreen();
-        /**
-        * Is called when settings in the optionsdialog have been
-        * changed (ok or apply)
-        */
-        void slotSettingsChanged();
-
-        /**
-         * Called when search button is pressed
-         **/
-        void slotSearchModules();
-        /**
-         * Called for search default bible
-         **/
-        void slotSearchDefaultBible();
-        /**
-         Saves current settings into a new profile.
-        */
-        void saveToNewProfile();
-        /**
-        * Slot to refresh the save profile and load profile menus.
-        */
-        void refreshProfileMenus();
-
-        /**
-        * Open the About Dialog
-        */
-        void slotOpenAboutDialog();
-
-    signals:
-        void toggledTextWindowHeader(bool newState);
-        void toggledTextWindowNavigator(bool newState);
-        void toggledTextWindowToolButtons(bool newState);
-        void toggledTextWindowModuleChooser(bool newState);
-        void toggledTextWindowFormatToolbar(bool newState);
-
-    private:
-        static BibleTime *m_instance;
-
-        //  True if window was maximized before last toggle to full screen.
-        bool m_WindowWasMaximizedBeforeFullScreen;
-
-        // Docking widgets and their respective content widgets:
-        BtBookshelfDockWidget* m_bookshelfDock;
-        QDockWidget* m_bookmarksDock;
-        CBookmarkIndex* m_bookmarksPage;
-        QDockWidget* m_magDock;
-        InfoDisplay::CInfoDisplay* m_infoDisplay;
-
-        QToolBar* m_mainToolBar;
-        QToolBar* m_navToolBar;
-        BtModuleChooserBar* m_worksToolBar;
-        QToolBar* m_toolsToolBar;
-        QToolBar* m_formatToolBar;
-
-        // File menu:
-        QMenu *m_fileMenu;
-        BtOpenWorkAction *m_openWorkAction;
-        QAction *m_quitAction;
-
-        // View menu:
-        QMenu *m_viewMenu;
-        QAction* m_viewToolbarAction;
-        QAction *m_showBookshelfAction;
-        QAction *m_showBookmarksAction;
-        QAction *m_showMagAction;
-        QMenu *m_toolBarsMenu;
-        QAction *m_showTextAreaHeadersAction;
-        QAction *m_showTextWindowNavigationAction;
-        QAction *m_showTextWindowModuleChooserAction;
-        QAction *m_showTextWindowToolButtonsAction;
-        QAction *m_showFormatToolbarAction;
-        QAction *m_toolbarsInEachWindow;
-
-        // Search menu:
-        QMenu *m_searchMenu;
-        QAction *m_searchOpenWorksAction;
-        QAction *m_searchStandardBibleAction;
-
-        // Window menu:
-        QMenu *m_windowMenu;
-        QMenu *m_openWindowsMenu;
-        QAction *m_windowCascadeAction;
-        QAction *m_windowTileAction;
-        QAction *m_windowTileHorizontalAction;
-        QAction *m_windowTileVerticalAction;
-        QAction *m_windowManualModeAction;
-        QMenu *m_windowArrangementMenu;
-        QAction *m_windowAutoCascadeAction;
-        QAction *m_windowAutoTileAction;
-        QAction *m_windowAutoTabbedAction;
-        QAction *m_windowAutoTileVerticalAction;
-        QAction *m_windowAutoTileHorizontalAction;
-        QAction *m_windowCloseAction;
-        QAction *m_windowCloseAllAction;
-
-        // Settings menu:
-        QMenu *m_settingsMenu;
-        QAction *m_setPreferencesAction;
-        QAction *m_bookshelfManagerAction;
-
-        // Help menu:
-        QMenu *m_helpMenu;
-        QAction *m_openHandbookAction;
-        QAction *m_bibleStudyHowtoAction;
-        QAction *m_aboutBibleTimeAction;
-
-        BtActionCollection* m_actionCollection;
-
-        QMenu* m_windowSaveProfileMenu;
-        QAction* m_windowSaveToNewProfileAction;
-        QMenu* m_windowLoadProfileMenu;
-        QMenu* m_windowDeleteProfileMenu;
-        QAction* m_windowFullscreenAction;
-
-        /**
-         * Signal mapper to map windows to menu items.
-         */
-        QSignalMapper* m_windowMapper;
-        /// \todo remove?
-        // QList<QAction*> m_windowOpenWindowsList;
-
-        CMDIArea* m_mdi;
-
-        Profile::CProfileMgr m_profileMgr;
-
-
-    protected: //DBUS interface implementation
-        void closeAllModuleWindows();
-        void syncAllBibles(const QString& key);
-        void syncAllCommentaries(const QString& key);
-        void syncAllLexicons(const QString& key);
-        void syncAllVerseBasedModules(const QString& key);
-        void openWindow(const QString& moduleName, const QString& key);
-        void openDefaultBible(const QString& key);
-        QString getCurrentReference();
-        QStringList searchInModule(const QString& module, const QString& searchText);
-        QStringList searchInOpenModules(const QString& searchText);
-        QStringList searchInDefaultBible(const QString& searchText);
-        QStringList getModulesOfType(const QString& type);
-
-        // Helper function
-        void syncAllModulesByType(const CSwordModuleInfo::ModuleType type, const QString& key);
-
-    private:
-        void showOrHideToolBars();
-#ifdef BT_DEBUG
-        void deleteDebugWindow();
-    private slots:
-        void slotDebugWindowClosing();
-        void slotDebugTimeout();
-        void slotShowDebugWindow(bool);
-    private:
-        QAction *m_debugWidgetAction;
-        static QLabel *m_debugWindow;
-        static QMutex m_debugWindowLock;
-#endif
-};
-
-#endif
diff --git a/trunk/bibletime/src/gui/bibletime.cpp b/trunk/bibletime/src/gui/bibletime.cpp
new file mode 100644
index 0000000..2bd0747
--- /dev/null
+++ b/trunk/bibletime/src/gui/bibletime.cpp
@@ -0,0 +1,383 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2010 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "bibletime.h"
+
+#include <cstdlib>
+#include <iostream>
+#include <ctime>
+#include <QAction>
+#include <QApplication>
+#include <QCloseEvent>
+#include <QDate>
+#include <QDebug>
+#include <QInputDialog>
+#include <QMdiSubWindow>
+#include <QMessageBox>
+#include <QSplashScreen>
+#include <QSplitter>
+#include "backend/config/cbtconfig.h"
+#include "backend/drivers/cswordbiblemoduleinfo.h"
+#include "backend/drivers/cswordbookmoduleinfo.h"
+#include "backend/drivers/cswordcommentarymoduleinfo.h"
+#include "backend/drivers/cswordlexiconmoduleinfo.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/keys/cswordldkey.h"
+#include "backend/keys/cswordversekey.h"
+#include "frontend/btaboutmoduledialog.h"
+#include "frontend/cmdiarea.h"
+#include "frontend/displaywindow/btactioncollection.h"
+#include "frontend/displaywindow/cdisplaywindow.h"
+#include "frontend/displaywindow/cdisplaywindowfactory.h"
+#include "frontend/displaywindow/creadwindow.h"
+#include "frontend/displaywindow/cwritewindow.h"
+#include "frontend/keychooser/ckeychooser.h"
+#include "frontend/searchdialog/csearchdialog.h"
+#include "util/cresmgr.h"
+#include "util/directory.h"
+
+
+using namespace Profile;
+
+BibleTime *BibleTime::m_instance = 0;
+
+BibleTime::BibleTime(QWidget *parent, Qt::WindowFlags flags)
+    : QMainWindow(parent, flags), m_WindowWasMaximizedBeforeFullScreen(false)
+{
+    namespace DU = util::directory;
+
+    Q_ASSERT(m_instance == 0);
+    m_instance = this;
+
+    QSplashScreen splash;
+    bool showSplash = CBTConfig::get(CBTConfig::logo);
+    QString splashHtml;
+
+    if (showSplash) {
+        splashHtml = "<div style='background:transparent;color:white;font-weight:bold'>%1"
+                     "</div>";
+        const QDate date(QDate::currentDate());
+        const int day = date.day();
+        const int month = date.month();
+        QString splashImage(DU::getPicsDir().canonicalPath().append("/"));
+
+        if ((month >= 12 && day >= 24) || (month <= 1 && day < 6)) {
+            splashImage.append("startuplogo_christmas.png");
+        } else {
+            splashImage.append("startuplogo.png");
+        }
+
+        QPixmap pm;
+        if (!pm.load(splashImage)) {
+            qWarning("Can't load startuplogo! Check your installation.");
+        }
+        splash.setPixmap(pm);
+        splash.show();
+
+        splash.showMessage(splashHtml.arg(tr("Initializing the SWORD engine...")),
+                           Qt::AlignCenter);
+    }
+    initBackends();
+
+    if (showSplash) {
+        splash.showMessage(splashHtml.arg(tr("Creating BibleTime's user interface...")),
+                           Qt::AlignCenter);
+    }
+    initView();
+
+    if (showSplash) {
+        splash.showMessage(splashHtml.arg(tr("Initializing menu- and toolbars...")),
+                           Qt::AlignCenter);
+    }
+    initActions();
+    initMenubar();
+    initToolbars();
+    initConnections();
+    readSettings();
+
+    setWindowTitle("BibleTime " BT_VERSION);
+    setWindowIcon(DU::getIcon(CResMgr::mainWindow::icon));
+    retranslateUi();
+}
+
+BibleTime::~BibleTime() {
+    //  delete m_dcopInterface;
+    // The backend is deleted by the BibleTimeApp instance
+#ifdef BT_DEBUG
+    deleteDebugWindow();
+#endif
+    saveSettings();
+}
+
+/** Saves the properties of BibleTime to the application wide configfile  */
+void BibleTime::saveSettings() {
+    /// \todo how to write settings?
+    //accel()->writeSettings(CBTConfig::getConfig());
+
+    CBTConfig::set(CBTConfig::toolbar, m_viewToolbarAction->isChecked());
+
+    // set the default to false
+    /* CBTConfig::set(CBTConfig::autoTileVertical, false);
+     CBTConfig::set(CBTConfig::autoTileHorizontal, false);
+     CBTConfig::set(CBTConfig::autoCascade, false);
+    */
+    CBTConfig::set(CBTConfig::autoTileVertical, m_windowAutoTileVerticalAction->isChecked());
+    CBTConfig::set(CBTConfig::autoTileHorizontal, m_windowAutoTileHorizontalAction->isChecked());
+    CBTConfig::set(CBTConfig::autoTile, m_windowAutoTileAction->isChecked());
+    CBTConfig::set(CBTConfig::autoTabbed, m_windowAutoTabbedAction->isChecked());
+    CBTConfig::set(CBTConfig::autoCascade, m_windowAutoCascadeAction->isChecked());
+
+    CProfile* p = m_profileMgr.startupProfile();
+    if (p) {
+        saveProfile(p);
+    }
+}
+
+/** Reads the settings from the configfile and sets the right properties. */
+void BibleTime::readSettings() {
+    qDebug() << "******************BibleTime::readSettings******************************";
+    //  accel()->readSettings(CBTConfig::getConfig());
+    CBTConfig::setupAccelSettings(CBTConfig::application, m_actionCollection);
+
+    m_viewToolbarAction->setChecked( CBTConfig::get(CBTConfig::toolbar) );
+    slotToggleMainToolbar();
+
+    if ( CBTConfig::get(CBTConfig::autoTileVertical) ) {
+        m_windowAutoTileVerticalAction->setChecked( true );
+        m_windowManualModeAction->setChecked(false);
+        slotAutoTileVertical();
+    }
+    else if ( CBTConfig::get(CBTConfig::autoTileHorizontal) ) {
+        m_windowAutoTileHorizontalAction->setChecked( true );
+        m_windowManualModeAction->setChecked(false);
+        slotAutoTileHorizontal();
+    }
+    else if ( CBTConfig::get(CBTConfig::autoTile) ) {
+        m_windowAutoTileAction->setChecked(true);
+        m_windowManualModeAction->setChecked(false);
+        slotAutoTile();
+    }
+    else if ( CBTConfig::get(CBTConfig::autoTabbed) ) {
+        m_windowAutoTabbedAction->setChecked(true);
+        m_windowManualModeAction->setChecked(false);
+        slotAutoTabbed();
+    }
+    else if ( CBTConfig::get(CBTConfig::autoCascade) ) {
+        m_windowAutoCascadeAction->setChecked(true);
+        m_windowManualModeAction->setChecked(false);
+        slotAutoCascade();
+    }
+    else {
+        m_windowManualModeAction->setChecked(true);
+        slotManualArrangementMode();
+    }
+}
+
+/** Creates a new presenter in the MDI area according to the type of the module. */
+CDisplayWindow* BibleTime::createReadDisplayWindow(QList<CSwordModuleInfo*> modules, const QString& key) {
+    qApp->setOverrideCursor( QCursor(Qt::WaitCursor) );
+    qDebug() << "BibleTime::createReadDisplayWindow(QList<CSwordModuleInfo*> modules, const QString& key)";
+    CDisplayWindow* displayWindow = CDisplayWindowFactory::createReadInstance(modules, m_mdi);
+    if ( displayWindow ) {
+        displayWindow->init();
+	m_mdi->addSubWindow(displayWindow); 
+        displayWindow->show();
+        //   if (!key.isEmpty())
+        displayWindow->lookupKey(key);
+    }
+    // We have to process pending events here, otherwise displayWindow is not fully painted
+    qApp->processEvents();
+    // Now all events, including mouse clicks for the displayWindow have been handled
+    // and we can let the user click the same module again
+    //m_bookshelfPage->unfreezeModules(modules);
+    qApp->restoreOverrideCursor();
+    return displayWindow;
+}
+
+
+/** Creates a new presenter in the MDI area according to the type of the module. */
+CDisplayWindow* BibleTime::createReadDisplayWindow(CSwordModuleInfo* module, const QString& key) {
+    QList<CSwordModuleInfo*> list;
+    list.append(module);
+
+    return createReadDisplayWindow(list, key);
+}
+
+CDisplayWindow* BibleTime::createWriteDisplayWindow(CSwordModuleInfo* module, const QString& key, const CDisplayWindow::WriteWindowType& type) {
+    qApp->setOverrideCursor( QCursor(Qt::WaitCursor) );
+
+    QList<CSwordModuleInfo*> modules;
+    modules.append(module);
+
+    CDisplayWindow* displayWindow = CDisplayWindowFactory::createWriteInstance(modules, m_mdi, type);
+    if ( displayWindow ) {
+        displayWindow->init();
+        if (m_mdi->subWindowList().count() == 0)
+            displayWindow->showMaximized();
+        else
+            displayWindow->show();
+        displayWindow->lookupKey(key);
+    }
+
+    qApp->restoreOverrideCursor();
+    return displayWindow;
+}
+
+CDisplayWindow* BibleTime::moduleEditPlain(CSwordModuleInfo *module) {
+    /// \todo Refactor this.
+    return createWriteDisplayWindow(module,
+                                    QString::null,
+                                    CDisplayWindow::PlainTextWindow);
+}
+
+CDisplayWindow* BibleTime::moduleEditHtml(CSwordModuleInfo *module) {
+    /// \todo Refactor this.
+    return createWriteDisplayWindow(module,
+                                    QString::null,
+                                    CDisplayWindow::HTMLWindow);
+}
+
+
+void BibleTime::searchInModule(CSwordModuleInfo *module) {
+    /// \todo Refactor this.
+    QList<CSwordModuleInfo *> modules;
+    modules.append(module);
+    Search::CSearchDialog::openDialog(modules, QString::null);
+}
+
+bool BibleTime::moduleUnlock(CSwordModuleInfo *module, QWidget *parent) {
+    /// \todo Write a proper unlocking dialog with integrated error messages.
+    QString unlockKey;
+    bool ok;
+    for (;;) {
+        unlockKey = QInputDialog::getText(
+            parent, tr("Unlock Work"), tr("Enter the unlock key for %1.").arg(module->name()),
+            QLineEdit::Normal, module->config(CSwordModuleInfo::CipherKey), &ok
+        );
+        if (!ok) return false;
+        module->unlock(unlockKey);
+
+        /// \todo refactor this module reload
+        /* There is currently a deficiency in sword 1.6.1 in that backend->setCipherKey() does
+         * not work correctly for modules from which data was already fetched. Therefore we have to
+         * reload the modules.
+         */
+        {
+            const QString moduleName(module->name());
+            CSwordBackend *backend = CSwordBackend::instance();
+            backend->reloadModules(CSwordBackend::OtherChange);
+            module = backend->findModuleByName(moduleName);
+            Q_ASSERT(module != 0);
+        }
+
+        if (!module->isLocked()) break;
+        QMessageBox::warning(parent, tr("Warning: Invalid unlock key!"),
+                             tr("The unlock key you provided did not properly unlock this "
+                                "module. Please try again."));
+    }
+    return true;
+}
+
+void BibleTime::slotModuleUnlock(CSwordModuleInfo *module) {
+    moduleUnlock(module, this);
+}
+
+void BibleTime::moduleAbout(CSwordModuleInfo *module) {
+    BTAboutModuleDialog *dialog = new BTAboutModuleDialog(module, this);
+    dialog->setAttribute(Qt::WA_DeleteOnClose); // Destroy dialog when closed
+    dialog->show();
+    dialog->raise();
+}
+
+/** Refreshes all presenters.*/
+void BibleTime::refreshDisplayWindows() {
+    foreach (QMdiSubWindow* subWindow, m_mdi->subWindowList()) {
+        if (CDisplayWindow* window = dynamic_cast<CDisplayWindow*>(subWindow->widget())) {
+            window->reload(CSwordBackend::OtherChange);
+        }
+    }
+}
+
+/** Refresh main window accelerators */
+void BibleTime::refreshBibleTimeAccel() {
+    CBTConfig::setupAccelSettings(CBTConfig::application, m_actionCollection);
+}
+
+void BibleTime::closeEvent(QCloseEvent *event) {
+    /*
+      Sequentially queries all open subwindows whether its fine to close them. If some sub-
+      window returns false, the querying is stopped and the close event is ignored. If all
+      subwindows return true, the close event is accepted.
+    */
+    Q_FOREACH(QMdiSubWindow *subWindow, m_mdi->subWindowList()) {
+        if (CDisplayWindow* window = dynamic_cast<CDisplayWindow*>(subWindow->widget())) {
+            if (!window->queryClose()) {
+                event->ignore();
+                return;
+            }
+        }
+    }
+    event->accept();
+}
+
+/** Restores the workspace if the flag for this is set in the config. */
+void BibleTime::restoreWorkspace() {
+    if (CProfile* p = m_profileMgr.startupProfile()) {
+        loadProfile(p);
+    }
+}
+
+/** Processes the commandline options given to BibleTime. */
+void BibleTime::processCommandline() {
+    QStringList args = qApp->QCoreApplication::arguments();
+
+    if (args.contains("--help") || args.contains("-h") || args.contains("/h") || args.contains("/?")) {
+        std::cout << "BibleTime" << std::endl << "--help (-h, /h, /?): Show this help message and exit"
+                  << std::endl << "--ignore-session: open a clean session" << std:: endl << "--open-default-bible <ref>: "
+                  << "Open the default Bible with the reference <ref>" << std::endl;
+        std::cout << "Some Qt arguments:" << std::endl << "-reverse: reverse the UI layout direction"
+                  << std::endl;
+        exit(0);
+        //printHelpAndExit();
+    }
+    if ( !CBTConfig::get(CBTConfig::crashedTwoTimes) &&
+            !args.contains("--ignore-session") ) {
+        restoreWorkspace();
+    }
+
+    if ( args.contains("--open-default-bible") &&
+            !CBTConfig::get(CBTConfig::crashedLastTime) &&
+            !CBTConfig::get(CBTConfig::crashedTwoTimes)) {
+        int index = args.indexOf("--open-default-bible");
+        QString bibleKey;
+        if (index >= 0 && (index + 1) < args.size()) {
+            bibleKey = args.at(index + 1);
+        }
+        CSwordModuleInfo* bible = CBTConfig::get(CBTConfig::standardBible);
+        if (bibleKey == "random") {
+            CSwordVerseKey vk(0);
+            const int maxIndex = 31100;
+            time_t seconds;
+            seconds = time (NULL);
+            srand(seconds);
+            int newIndex = rand() % maxIndex;
+            vk.setPosition(sword::TOP);
+            vk.Index(newIndex);
+            bibleKey = vk.key();
+        }
+        createReadDisplayWindow(bible, bibleKey);
+        m_mdi->myTileVertical();//we are sure only one window is open, which should be displayed fullscreen in the working area
+    }
+}
+
+bool BibleTime::event(QEvent* event) {
+    if (event->type() == QEvent::Close)
+        Search::CSearchDialog::closeDialog();
+    return QMainWindow::event(event);
+}
diff --git a/trunk/bibletime/src/gui/bibletime.h b/trunk/bibletime/src/gui/bibletime.h
new file mode 100644
index 0000000..bac0d69
--- /dev/null
+++ b/trunk/bibletime/src/gui/bibletime.h
@@ -0,0 +1,553 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2010 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BIBLETIME_H
+#define BIBLETIME_H
+
+#include <QMainWindow>
+
+#include <QList>
+#include "frontend/displaywindow/cdisplaywindow.h"
+#include "frontend/profile/cprofile.h"
+#include "frontend/profile/cprofilemgr.h"
+#include <QSignalMapper>
+#ifdef BT_DEBUG
+#include <QMutex>
+#endif
+
+
+namespace InfoDisplay {
+class CInfoDisplay;
+}
+class BtActionClass;
+class BtBookshelfDockWidget;
+class BtOpenWorkAction;
+class CBookmarkIndex;
+class CDisplayWindow;
+class CMDIArea;
+class CSwordModuleInfo;
+class QAction;
+class QLabel;
+class QMenu;
+class QToolBar;
+class QSplitter;
+class QSignalMapper;
+
+/**
+  * @page backend The structure of the backend
+  * <p>
+  * The backend implementation for Sword is called CSwordBackend, the classes we use
+  * to work with keys are called CSwordVerseKey and CSwordLDKey, both are derived from
+  * the class CSwordKey.
+  * The CSwordKey derived classes used for Sword do also inherit the classes
+  * VerseKey (CSwordVerseKey)
+  * and SWKey (CSwordLDKey).
+  * </p>
+  * <p>
+  * The classes used to handle all module based stuff are derived from CSwordModuleInfo.
+  * The module classes are: CSwordModuleInfo (for Sword modules),
+  * CSwordBibleModuleInfo (for bibles), CSwordCommentaryModuleInfo (for commentaries) and
+  * CSwordLexiconModuleInfo (for lexicons).
+  * Have a look at the class documentation of the mentioned classes to learn how the
+  * structure of them looks like and which class inherits which other class.
+  * </p>
+  * <p>
+  * The first objects which should be created in the application is the backend
+  * (for Sword the class is called CSwordBackend).
+  * Then create all the different module classes for the correct Sword modules.
+  * Have a look at
+  * BibleTime::initBackens() to see how it's done in BibleTime. at br
+  * Later you can work with them for example by using the CSwordKey and
+  * CSwordModuleInfo derived class.
+  * </p>
+  */
+
+/**
+  * @page frontend The structure of the frontend
+  *
+  * <p>
+  * The frontend contains the classes which interact with the user. For example the 
+  * display windows, the searchdialog or the other parts.
+  * </p><p>
+  * The display windows which provide functionality are CBibleReadWindow for
+  * Bibles, CBookReadWindow for books, CCommentaryReadWindow for commentaries and CLexiconReadWindow for
+  * lexicon and dictionaries.
+  * </p><p>
+  * 
+  * The class CDisplay is the class that various views with in the windows are derived. 
+  * </p><p>
+  *
+  * Another important part of the frontend are the keychoosers.
+  * They provide an interface to choose a key of a module.
+  * The interface for different module types is different.
+  * The base class is CKeyChooser which is the factory for the derived classes.
+  * Use the function CKeyChooser::createInstance to get the correct
+  * keychooser implementation for the desired module.<br/>
+  * </p><p>
+  * Some major toolbar widgets are CKeyChooser and BtDisplaySettingsButton.
+  * </p>
+  */
+
+/** @mainpage BibleTime - sourcecode documentation
+ * BibleTime main page.
+ * <p>This is the sourcecode documentation of BibleTime, a Bible study tool.
+ * <p>
+ * The main class of BibleTime is called @ref BibleTime, which is the main window
+ * and initializes all important parts at startup. 
+ * </p><p>
+ * BibleTime is divided in two major parts, the backend and the frontend.
+ * The text display windows belong to the @ref frontend.
+ * The backend is mainly a wrapper around Sword's classes to use Qt functionality
+ * to allow easy access to it's functionality and to have it in a (more or less :)
+ * object oriented structure.</p><br/>
+ * <p>
+ *       -Introduction to the frontend: @ref frontend.<br/>
+ *       -Introduction to the backend: @ref backend<br/>
+ * </p>
+ */
+
+/** BibleTime's main class.
+ * The main class of BibleTime. Here are the main widgets created.
+ *
+ * This is the main class of BibleTime! This class creates the GUI, the QAction objects
+ * and connects to some slots. Please insert the creation of actions in initActions,
+ * the creation of widgets into initView and the connect(...) calls into initConnections.
+ * Reading from a config file on creation time should go into readSettings(), saving into
+ * saveSettings().
+ * This is the general way of all BibleTime classes.
+ */
+class BibleTime : public QMainWindow {
+        friend class CDisplayWindow;
+        friend class BibleTimeDBusAdaptor;
+        Q_OBJECT
+
+    public:
+
+        BibleTime(QWidget *parent = 0, Qt::WindowFlags flags = 0);
+
+        ~BibleTime();
+
+        static inline BibleTime *instance() { return m_instance; }
+
+        /**
+        * Reads the settings from the configfile and sets the right properties.
+        */
+        void readSettings();
+        /**
+        * Saves the settings of this class
+        */
+        void saveSettings();
+        /**
+        * Restores the workspace if the flaf for this is set in the config.
+        */
+        void restoreWorkspace();
+        /**
+        * Apply the settings given by the profile p
+        */
+        void applyProfileSettings( Profile::CProfile* p );
+        /**
+        * Stores the settings of the mainwindow in the profile p
+        */
+        void storeProfileSettings( Profile::CProfile* p );
+        /**
+        *  Save the configuration dialog settings, don't open dialog
+        */
+        void saveConfigSettings();
+        /**
+        * Get pointer to Navigation toolbar
+        */
+        inline QToolBar *navToolBar() const {
+            return m_navToolBar;
+        }
+        /**
+        * Get pointer to Works toolbar
+        */
+        inline BtModuleChooserBar *worksToolBar() const {
+            return m_worksToolBar;
+        }
+        /**
+        * Get pointer to Tools toolbar
+        */
+        inline QToolBar *toolsToolBar() const {
+            return m_toolsToolBar;
+        }
+        /**
+        * Get pointer to Format toolbar
+        */
+        inline QToolBar *formatToolBar() const {
+            return m_formatToolBar;
+        }
+
+        /**
+          \returns a pointer to the info display.
+        */
+        inline InfoDisplay::CInfoDisplay *infoDisplay() const {
+            return m_infoDisplay;
+        }
+
+        /**
+        * Clears the actions of the MDI related toolbars
+        */
+        void clearMdiToolBars();
+
+        /**
+          Displays a dialog which asks the user an unlock key for the given module and tries
+          to unlock the module. If an invalid unlock key is given, a warning message is
+          issued and the user is again asked for the key.
+          \param[in] module The module to unlock.
+          \param[in] parent The parent widget for the unlock dialogs.
+          \returns whether the module was successfully unlocked.
+        */
+        static bool moduleUnlock(CSwordModuleInfo *module, QWidget *parent = 0);
+
+    public slots:
+        /**
+        * Opens the optionsdialog of BibleTime.
+        */
+        void slotSettingsOptions();
+        /**
+        * Opens the optionsdialog of BibleTime.
+        */
+        void slotSwordSetupDialog();
+        /**
+        * Opens the handbook.
+        */
+        void openOnlineHelp_Handbook();
+        /**
+        * Opens the bible study howto.
+        */
+        void openOnlineHelp_Howto();
+        /**
+        * Processes the commandline options given to BibleTime.
+        */
+        void processCommandline();
+        /**
+        * Creates QAction's that have keyboard shortcuts
+        */
+        static void insertKeyboardActions( BtActionCollection* const a );
+
+    protected: // Protected methods
+        /**
+        * Catch QMainWindow events
+        */
+        bool event(QEvent* event);
+        /**
+        * Create the main window menu and toolbar
+        */
+        void createMenuAndToolBar();
+        /**
+        * Initializes the sword.conf in the $HOME\Sword directory
+        */
+        void initSwordConfigFile();
+        /**
+        * Initializes the view of this widget
+        */
+        void initView();
+        /**
+        * Initializes the menubar of BibleTime.
+        */
+        void initMenubar();
+        /**
+        * Initializes the SIGNAL / SLOT connections
+        */
+        void initConnections();
+        /**
+        * Initializes the backend
+        */
+        void initBackends();
+        /**
+        * Initializes the action objects of the GUI
+        */
+        void initActions();
+        /**
+          Initializes the toolbars.
+        */
+        void initToolbars();
+        /**
+          Retranslates the UI.
+        */
+        void retranslateUi();
+        /**
+          Retranslates the UI actions.
+        */
+        static void retranslateUiActions(BtActionCollection* ac);
+        /**
+        * Initializes one action object
+        */
+        QAction* initAction(QAction* action, QString text, QString icon, QKeySequence accel,
+                            const QString& tooltip, const QString& actionName, const char* slot );
+        /**
+        * Refreshes all presenter supporting at least in of the features given as parameter.
+        */
+        void refreshDisplayWindows();
+        /**
+        * Refresh main window accelerators
+        */
+        void refreshBibleTimeAccel();
+
+        /**
+        * Reimplemented from QWidget.
+        */
+        void closeEvent(QCloseEvent *event);
+
+    protected slots:
+        /**
+         * Creates a new presenter in the MDI area according to the type of the module.
+         */
+        CDisplayWindow* createReadDisplayWindow(QList<CSwordModuleInfo*> modules, const QString& key);
+        CDisplayWindow* createReadDisplayWindow(CSwordModuleInfo* module, const QString& key = QString::null);
+        CDisplayWindow* createWriteDisplayWindow(CSwordModuleInfo* module, const QString& key, const CDisplayWindow::WriteWindowType& type);
+        CDisplayWindow* moduleEditPlain(CSwordModuleInfo *module);
+        CDisplayWindow* moduleEditHtml(CSwordModuleInfo *module);
+        void searchInModule(CSwordModuleInfo *module);
+        void slotModuleUnlock(CSwordModuleInfo *module);
+        void moduleAbout(CSwordModuleInfo *module);
+        void quit();
+
+        /**
+         * Is called when the window menu is about to show ;-)
+         */
+        void slotWindowMenuAboutToShow();
+        /**
+         * Is called when the open windows menu is about to show ;-)
+         */
+        void slotOpenWindowsMenuAboutToShow();
+        /**
+         * This slot is connected with the windowAutoTileVerticalAction object
+         */
+        void slotAutoTileVertical();
+        /**
+         * This slot is connected with the windowAutoTileHorizontalAction object
+         */
+        void slotAutoTileHorizontal();
+        /**
+         * This slot is connected with the windowAutoTileAction object
+         */
+        void slotAutoTile();
+        /**
+         * This slot is connected with the windowAutoTabbedAction object
+         */
+        void slotAutoTabbed();
+        /**
+         * This slot is connected with the windowAutoCascadeAction object
+         */
+        void slotAutoCascade();
+        void slotUpdateWindowArrangementActions( QAction* );
+
+        void slotCascade();
+        void slotTile();
+        void slotTileVertical();
+        void slotTileHorizontal();
+
+        void slotManualArrangementMode();
+
+        /**
+         * Shows/hides the main toolbar
+         */
+        void slotToggleMainToolbar();
+        void slotToggleToolsToolbar();
+        void slotToggleNavigatorToolbar();
+        void slotToggleWorksToolbar();
+        void slotToggleFormatToolbar();
+
+        void slotToggleToolBarsInEachWindow();
+        
+        /**
+        * Shows/hides the text window text area headers and sets
+        * configuration that newly opened windows don't user headers.
+        */
+        void slotToggleTextWindowHeader();
+
+        /**
+         * Used to set the active menu
+         */
+        void slotSetActiveSubWindow(QWidget* window);
+        /**
+        * Saves to the profile with the menu id ID
+        */
+        void saveProfile(QAction* action);
+        /**
+        * Saves the current settings into the currently activatred profile.
+        */
+        void saveProfile(Profile::CProfile* p);
+        /**
+        * Deletes the chosen session from the menu and from disk.
+        */
+        void deleteProfile(QAction* action);
+        /**
+        * Loads the profile with the menu id ID
+        */
+        void loadProfile(QAction* action);
+        /**
+        * Loads the profile with the menu ID id
+        */
+        void loadProfile(Profile::CProfile* p);
+        /**
+        * Toggles between normal and fullscreen mode.
+        */
+        void toggleFullscreen();
+        /**
+        * Is called when settings in the optionsdialog have been
+        * changed (ok or apply)
+        */
+        void slotSettingsChanged();
+
+        /**
+         * Called when search button is pressed
+         **/
+        void slotSearchModules();
+        /**
+         * Called for search default bible
+         **/
+        void slotSearchDefaultBible();
+        /**
+         Saves current settings into a new profile.
+        */
+        void saveToNewProfile();
+        /**
+        * Slot to refresh the save profile and load profile menus.
+        */
+        void refreshProfileMenus();
+
+        /**
+        * Open the About Dialog
+        */
+        void slotOpenAboutDialog();
+
+    signals:
+        void toggledTextWindowHeader(bool newState);
+        void toggledTextWindowNavigator(bool newState);
+        void toggledTextWindowToolButtons(bool newState);
+        void toggledTextWindowModuleChooser(bool newState);
+        void toggledTextWindowFormatToolbar(bool newState);
+
+    private:
+        static BibleTime *m_instance;
+
+        //  True if window was maximized before last toggle to full screen.
+        bool m_WindowWasMaximizedBeforeFullScreen;
+
+        // Docking widgets and their respective content widgets:
+        BtBookshelfDockWidget* m_bookshelfDock;
+        QDockWidget* m_bookmarksDock;
+        CBookmarkIndex* m_bookmarksPage;
+        QDockWidget* m_magDock;
+        InfoDisplay::CInfoDisplay* m_infoDisplay;
+
+        QToolBar* m_mainToolBar;
+        QToolBar* m_navToolBar;
+        BtModuleChooserBar* m_worksToolBar;
+        QToolBar* m_toolsToolBar;
+        QToolBar* m_formatToolBar;
+
+        // File menu:
+        QMenu *m_fileMenu;
+        BtOpenWorkAction *m_openWorkAction;
+        QAction *m_quitAction;
+
+        // View menu:
+        QMenu *m_viewMenu;
+        QAction* m_viewToolbarAction;
+        QAction *m_showBookshelfAction;
+        QAction *m_showBookmarksAction;
+        QAction *m_showMagAction;
+        QMenu *m_toolBarsMenu;
+        QAction *m_showTextAreaHeadersAction;
+        QAction *m_showTextWindowNavigationAction;
+        QAction *m_showTextWindowModuleChooserAction;
+        QAction *m_showTextWindowToolButtonsAction;
+        QAction *m_showFormatToolbarAction;
+        QAction *m_toolbarsInEachWindow;
+
+        // Search menu:
+        QMenu *m_searchMenu;
+        QAction *m_searchOpenWorksAction;
+        QAction *m_searchStandardBibleAction;
+
+        // Window menu:
+        QMenu *m_windowMenu;
+        QMenu *m_openWindowsMenu;
+        QAction *m_windowCascadeAction;
+        QAction *m_windowTileAction;
+        QAction *m_windowTileHorizontalAction;
+        QAction *m_windowTileVerticalAction;
+        QAction *m_windowManualModeAction;
+        QMenu *m_windowArrangementMenu;
+        QAction *m_windowAutoCascadeAction;
+        QAction *m_windowAutoTileAction;
+        QAction *m_windowAutoTabbedAction;
+        QAction *m_windowAutoTileVerticalAction;
+        QAction *m_windowAutoTileHorizontalAction;
+        QAction *m_windowCloseAction;
+        QAction *m_windowCloseAllAction;
+
+        // Settings menu:
+        QMenu *m_settingsMenu;
+        QAction *m_setPreferencesAction;
+        QAction *m_bookshelfManagerAction;
+
+        // Help menu:
+        QMenu *m_helpMenu;
+        QAction *m_openHandbookAction;
+        QAction *m_bibleStudyHowtoAction;
+        QAction *m_aboutBibleTimeAction;
+
+        BtActionCollection* m_actionCollection;
+
+        QMenu* m_windowSaveProfileMenu;
+        QAction* m_windowSaveToNewProfileAction;
+        QMenu* m_windowLoadProfileMenu;
+        QMenu* m_windowDeleteProfileMenu;
+        QAction* m_windowFullscreenAction;
+
+        /**
+         * Signal mapper to map windows to menu items.
+         */
+        QSignalMapper* m_windowMapper;
+        /// \todo remove?
+        // QList<QAction*> m_windowOpenWindowsList;
+
+        CMDIArea* m_mdi;
+
+        Profile::CProfileMgr m_profileMgr;
+
+
+    protected: //DBUS interface implementation
+        void closeAllModuleWindows();
+        void syncAllBibles(const QString& key);
+        void syncAllCommentaries(const QString& key);
+        void syncAllLexicons(const QString& key);
+        void syncAllVerseBasedModules(const QString& key);
+        void openWindow(const QString& moduleName, const QString& key);
+        void openDefaultBible(const QString& key);
+        QString getCurrentReference();
+        QStringList searchInModule(const QString& module, const QString& searchText);
+        QStringList searchInOpenModules(const QString& searchText);
+        QStringList searchInDefaultBible(const QString& searchText);
+        QStringList getModulesOfType(const QString& type);
+
+        // Helper function
+        void syncAllModulesByType(const CSwordModuleInfo::ModuleType type, const QString& key);
+
+    private:
+        void showOrHideToolBars();
+#ifdef BT_DEBUG
+        void deleteDebugWindow();
+    private slots:
+        void slotDebugWindowClosing();
+        void slotDebugTimeout();
+        void slotShowDebugWindow(bool);
+    private:
+        QAction *m_debugWidgetAction;
+        static QLabel *m_debugWindow;
+        static QMutex m_debugWindowLock;
+#endif
+};
+
+#endif


More information about the bt-devel mailing list