diff options
Diffstat (limited to 'src/mobile/bibletimeapp.cpp')
-rw-r--r-- | src/mobile/bibletimeapp.cpp | 85 |
1 files changed, 46 insertions, 39 deletions
diff --git a/src/mobile/bibletimeapp.cpp b/src/mobile/bibletimeapp.cpp index f7801b8..707ea6c 100644 --- a/src/mobile/bibletimeapp.cpp +++ b/src/mobile/bibletimeapp.cpp @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2014 by the BibleTime developers. +* Copyright 1999-2016 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * @@ -18,21 +18,23 @@ #include "backend/managers/cswordbackend.h" #include "backend/managers/cdisplaytemplatemgr.h" #include "frontend/messagedialog.h" +#include "util/btassert.h" #include "util/cresmgr.h" -#include "util/geticon.h" #include "util/directory.h" BibleTimeApp::BibleTimeApp(int &argc, char **argv) : QGuiApplication(argc, argv) - , m_init(false) { + , m_init(false) + , m_debugMode(false) +{ setApplicationName("bibletime"); setApplicationVersion(BT_VERSION); } BibleTimeApp::~BibleTimeApp() { // Prevent writing to the log file before the directory cache is init: - if (!m_init || BtConfig::m_instance == 0) + if (!m_init || BtConfig::m_instance == nullptr) return; //we can set this safely now because we close now (hopyfully without crash) @@ -40,56 +42,61 @@ BibleTimeApp::~BibleTimeApp() { btConfig().setValue("state/crashedTwoTimes", false); delete CDisplayTemplateMgr::instance(); + CLanguageMgr::destroyInstance(); CSwordBackend::destroyInstance(); - util::clearIconCache(); BtConfig::destroyInstance(); } bool BibleTimeApp::initBtConfig() { - Q_ASSERT(m_init); + BT_ASSERT(m_init); - return BtConfig::initBtConfig(); + BtConfig::InitState const r = BtConfig::initBtConfig(); + if (r == BtConfig::INIT_OK) + return true; + if (r == BtConfig::INIT_NEED_UNIMPLEMENTED_FORWARD_MIGRATE) { + /// \todo Migrate from btConfigOldApi to BTCONFIG_API_VERSION + qWarning() << "BibleTime configuration migration is not yet implemented!!!"; + if (message::showWarning( + nullptr, + tr("Warning!"), + tr("Migration to the new configuration system is not yet " + "implemented. Proceeding might result in <b>loss of data" + "</b>. Please backup your configuration files before " + "you continue!<br/><br/>Do you want to continue? Press " + "\"No\" to quit BibleTime immediately."), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No) == QMessageBox::No) + return false; + } else { + BT_ASSERT(r == BtConfig::INIT_NEED_UNIMPLEMENTED_BACKWARD_MIGRATE); + if (message::showWarning( + nullptr, + tr("Error loading configuration!"), + tr("Failed to load BibleTime's configuration, because it " + "appears that the configuration file corresponds to a " + "newer version of BibleTime. This is likely caused by " + "BibleTime being downgraded. Loading the new " + "configuration file may result in <b>loss of data</b>." + "<br/><br/>Do you still want to try to load the new " + "configuration file? Press \"No\" to quit BibleTime " + "immediately."), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No) == QMessageBox::No) + return false; + } + BtConfig::forceMigrate(); + return true; } bool BibleTimeApp::initDisplayTemplateManager() { - Q_ASSERT(m_init); + BT_ASSERT(m_init); QString errorMessage; new CDisplayTemplateMgr(errorMessage); if (errorMessage.isNull()) return true; - message::showCritical(0, tr("Fatal error!"), errorMessage); + message::showCritical(nullptr, tr("Fatal error!"), errorMessage); return false; } - - -const QIcon & BibleTimeApp::getIcon(const QString & name) const { - QString plainName(name); - if (plainName.endsWith(".svg", Qt::CaseInsensitive)) - plainName.chop(4); - - const QMap<QString, QIcon>::const_iterator i = m_iconCache.find(plainName); - if (i != m_iconCache.end()) - return *i; - - const QString iconDir = util::directory::getIconDir().canonicalPath(); - QString iconFileName = iconDir + "/" + plainName + ".svg"; - if (QFile(iconFileName).exists()) - return *m_iconCache.insert(plainName, QIcon(iconFileName)); - - iconFileName = iconDir + "/" + plainName + ".png"; - if (QFile(iconFileName).exists()) - return *m_iconCache.insert(plainName, QIcon(iconFileName)); - - if (plainName != "default") { - qWarning() << "Cannot find icon file" << iconFileName - << ", using default icon."; - return getIcon("default"); - } - - qWarning() << "Cannot find default icon" << iconFileName - << ", using null icon."; - return m_nullIcon; -} |