diff options
author | Roberto C. Sanchez <roberto@connexer.com> | 2014-10-21 22:48:33 -0400 |
---|---|---|
committer | Roberto C. Sanchez <roberto@connexer.com> | 2014-10-21 22:48:33 -0400 |
commit | 4885bfcef4d89cf0cb391e00af617b9fd19c9cbb (patch) | |
tree | e8ba8579bd76a1b277231202ca6579eb19c1ab4b /src/main.cpp | |
parent | 294b5ec5834affa57641475946b8d2aeca53c577 (diff) |
Imported Upstream version 2.5
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 87 |
1 files changed, 64 insertions, 23 deletions
diff --git a/src/main.cpp b/src/main.cpp index f265ad7..3064522 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,6 +20,7 @@ #include <QVariant> #include "backend/bookshelfmodel/btbookshelftreemodel.h" #include "backend/config/cbtconfig.h" +#include "backend/managers/cswordbackend.h" #include "bibletime.h" #include "bibletime_dbus_adaptor.h" #include "bibletimeapp.h" @@ -33,28 +34,60 @@ #endif +namespace { + bool showDebugMessages; +#ifdef Q_WS_WIN + +FILE *out_fd = 0; +#define DEBUG_STREAM (out_fd != 0 ? out_fd :\ + out_fd = fopen(QDir::homePath().append("/BibleTime Debug.txt").toLocal8Bit().data(),"w")) +#define CLOSE_DEBUG_STREAM { if (out_fd != 0) fclose(out_fd); } + +#else + +#define DEBUG_STREAM (stderr) +#define CLOSE_DEBUG_STREAM + +#endif + +} // anonymous namespace + + void myMessageOutput( QtMsgType type, const char *msg ) { //we use this messagehandler to switch debugging off in final releases + FILE* outFd = 0; switch (type) { case QtDebugMsg: if (showDebugMessages) { //only show messages if they are enabled! - fprintf( stderr, "(BibleTime %s) Debug: %s\n", BT_VERSION, msg ); + outFd = DEBUG_STREAM; + if (outFd != 0) + fprintf(outFd, "(BibleTime " BT_VERSION ") Debug: %s\n", msg); } break; case QtWarningMsg: - //if (showDebugMessages) //comment out for releases so users don't get our debug warnings - fprintf( stderr, "(BibleTime %s) WARNING: %s\n", BT_VERSION, msg ); +#ifndef QT_NO_DEBUG // don't show in release builds so users don't get our debug warnings + outFd = DEBUG_STREAM; + if (outFd != 0) + fprintf(outFd, "(BibleTime " BT_VERSION ") WARNING: %s\n", msg); +#endif break; case QtFatalMsg: case QtCriticalMsg: - fprintf( stderr, "(BibleTime %s) _FATAL_: %s\nPlease report this bug! (http://www.bibletime.info/development_help.html)", BT_VERSION, msg ); + outFd = DEBUG_STREAM; + if (outFd != 0) + fprintf(outFd, + "(BibleTime " BT_VERSION ") _FATAL_: %s\nPlease report this bug! " + "(http://www.bibletime.info/development_help.html)", + msg); abort(); // dump core on purpose } } void registerMetaTypes() { + qRegisterMetaType<CSwordBackend::FilterOptions>(); + qRegisterMetaType<CSwordBackend::DisplayOptions>(); qRegisterMetaTypeStreamOperators<BtBookshelfTreeModel::Grouping>("BtBookshelfTreeModel::Grouping"); } @@ -63,7 +96,20 @@ void registerMetaTypes() { int main(int argc, char* argv[]) { namespace DU = util::directory; -// qInstallMsgHandler( myMessageOutput ); + BibleTimeApp app(argc, argv); //for QApplication + app.setApplicationName("bibletime"); + app.setApplicationVersion(BT_VERSION); + + showDebugMessages = QCoreApplication::arguments().contains("--debug"); + +#ifdef Q_WS_WIN + // Use the default Qt message handler if --debug is not specified + // This works with Visual Studio debugger Output Window + if (showDebugMessages) + qInstallMsgHandler( myMessageOutput ); +#else + qInstallMsgHandler( myMessageOutput ); +#endif #ifdef BT_ENABLE_TESTING if (QString(argv[1]) == QString("--run-tests")) { @@ -77,18 +123,14 @@ int main(int argc, char* argv[]) { command line argument handling. */ - BibleTimeApp app(argc, argv); //for QApplication - app.setApplicationName("bibletime"); - app.setApplicationVersion(BT_VERSION); - #ifdef Q_WS_WIN - // On Windows, add a path for Qt plugins to be loaded from + // On Windows, add a path for Qt plugins to be loaded from app.addLibraryPath(app.applicationDirPath() + "/plugins"); - // Must set HOME var on Windows - QString homeDir(getenv("APPDATA")); - _putenv_s("HOME", qPrintable(homeDir)); + // Must set HOME var on Windows + QString homeDir(getenv("APPDATA")); + _putenv_s("HOME", qPrintable(homeDir)); #endif @@ -100,14 +142,14 @@ int main(int argc, char* argv[]) { } #ifdef Q_WS_WIN - // change directory to the Sword or .sword directory in the $HOME dir so that - // the sword.conf is found. It points to the sword/locales.d directory - QString homeSwordDir = util::directory::getUserHomeDir().absolutePath(); - QDir dir; - dir.setCurrent(homeSwordDir); + // change directory to the Sword or .sword directory in the $HOME dir so that + // the sword.conf is found. It points to the sword/locales.d directory + QString homeSwordDir = util::directory::getUserHomeDir().absolutePath(); + QDir dir; + dir.setCurrent(homeSwordDir); #endif - // This is needed for languagemgr language names to work, they use \uxxxx escape sequences in string literals + // This is needed for languagemgr language names to work, they use \uxxxx escape sequences in string literals QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); //first install QT's own translations QTranslator qtTranslator; @@ -118,9 +160,6 @@ int main(int argc, char* argv[]) { BibleTimeTranslator.load( QString("bibletime_ui_").append(QLocale::system().name()), DU::getLocaleDir().canonicalPath()); app.installTranslator(&BibleTimeTranslator); - // This is the QT4 version, will only work if main App is QApplication - // A binary option (on / off) - showDebugMessages = QCoreApplication::arguments().contains("--debug"); app.setProperty("--debug", QVariant(showDebugMessages)); //Migrate configuration data, if neccessary @@ -148,6 +187,8 @@ int main(int argc, char* argv[]) { QDBusConnection::sessionBus().registerObject("/BibleTime", &bibleTime); #endif - return app.exec(); + int r = app.exec(); + CLOSE_DEBUG_STREAM; + return r; } |