29 #include <QMessageBox>
34 #if defined(Q_OS_WIN) || defined(Q_OS_MAC)
35 #include <QTextStream>
40 #include "../backend/config/btconfig.h"
41 #include "../backend/managers/cswordbackend.h"
42 #include "../backend/managers/cdisplaytemplatemgr.h"
43 #include "../util/btassert.h"
44 #include "../util/bticons.h"
45 #if defined(Q_OS_WIN) || defined(Q_OS_MAC)
46 #include "../util/directory.h"
52 #pragma GCC diagnostic push
53 #pragma GCC diagnostic ignored "-Wextra-semi"
55 #include "localemgr.h"
58 #pragma GCC diagnostic pop
61 class QMessageLogContext;
68 QMessageLogContext
const &,
71 QByteArray msg =
message.toLatin1();
72 #define MY_OUTPUT_LITERAL(literal) \
73 debugStream->write(literal, sizeof(literal) - 1u)
76 if (
btApp->debugMode()) {
99 "https://github.com/bibletime/bibletime/issues\n");
106 "https://github.com/bibletime/bibletime/issues\n");
112 #undef MY_OUTPUT_LITERAL
120 , m_debugMode(qgetenv(
"BIBLETIME_DEBUG") == QByteArrayLiteral(
"1"))
123 setApplicationName(QStringLiteral(
"bibletime"));
124 setApplicationVersion(BT_VERSION);
127 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
128 this->setAttribute(Qt::AA_UseHighDpiPixmaps);
133 addLibraryPath(applicationDirPath() + QStringLiteral(
"/plugins"));
137 std::array<wchar_t, 4096u> homeDir;
138 GetEnvironmentVariable(TEXT(
"APPDATA"), homeDir.data(), homeDir.size());
139 SetEnvironmentVariable(TEXT(
"HOME"), homeDir.data());
148 std::make_unique<QFile>(
149 QDir::home().filePath(
150 QStringLiteral(
"/BibleTime Debug.txt")));
185 qWarning() <<
"BibleTime configuration migration is not yet implemented!!!";
189 tr(
"Migration to the new configuration system is not yet "
190 "implemented. Proceeding might result in <b>loss of data"
191 "</b>. Please backup your configuration files before "
192 "you continue!<br/><br/>Do you want to continue? Press "
193 "\"No\" to quit BibleTime immediately."),
194 QMessageBox::Yes | QMessageBox::No,
195 QMessageBox::No) == QMessageBox::No)
201 tr(
"Error loading configuration!"),
202 tr(
"Failed to load BibleTime's configuration, because it "
203 "appears that the configuration file corresponds to a "
204 "newer version of BibleTime. This is likely caused by "
205 "BibleTime being downgraded. Loading the new "
206 "configuration file may result in <b>loss of data</b>."
207 "<br/><br/>Do you still want to try to load the new "
208 "configuration file? Press \"No\" to quit BibleTime "
210 QMessageBox::Yes | QMessageBox::No,
211 QMessageBox::No) == QMessageBox::No)
225 auto const lightDarkMode =
226 btConfig().
value<
int>(QStringLiteral(
"GUI/lightDarkMode"), 0);
227 if (lightDarkMode == LightDarkMode::systemDefault)
230 if (lightDarkMode == LightDarkMode::dark) {
231 p.setColor(QPalette::WindowText,QColor(0xfc, 0xfc, 0xfc));
232 p.setColor(QPalette::Button,QColor(0x31, 0x36, 0x3b));
233 p.setColor(QPalette::Light,QColor(0x18, 0x1b, 0x1d));
234 p.setColor(QPalette::Midlight,QColor(0x25, 0x29, 0x2c));
235 p.setColor(QPalette::Dark,QColor(0x62, 0x6c, 0x76));
236 p.setColor(QPalette::Mid,QColor(0x41, 0x48, 0x4e));
238 p.setColor(QPalette::BrightText,QColor(0xff, 0xff, 0xff));
239 p.setColor(QPalette::ButtonText,QColor(0xfc, 0xfc, 0xfc));
240 p.setColor(QPalette::Base,QColor(0x1b, 0x1e, 0x20));
241 p.setColor(QPalette::Window,QColor(0x2a, 0x2e, 0x32));
242 p.setColor(QPalette::Shadow,QColor(0x76, 0x76, 0x76));
243 p.setColor(QPalette::Highlight,QColor(0x3d, 0xae, 0xe9));
244 p.setColor(QPalette::HighlightedText,QColor(0xfc, 0xfc, 0xfc));
245 p.setColor(QPalette::Link,QColor(0x1d, 0x99, 0xf3));
246 p.setColor(QPalette::LinkVisited,QColor(0x9b, 0x59, 0xb6));
248 p.setColor(QPalette::WindowText,QColor(0x23, 0x26, 0x29));
249 p.setColor(QPalette::Button,QColor(0xf7, 0xf7, 0xf7));
250 p.setColor(QPalette::Light,QColor(0x0, 0x0, 0x0));
251 p.setColor(QPalette::Midlight,QColor(0x0, 0x0, 0x0));
252 p.setColor(QPalette::Dark,QColor(0x7b, 0x7b, 0x7b));
253 p.setColor(QPalette::Mid,QColor(0xa5, 0xa5, 0xa5));
255 p.setColor(QPalette::BrightText,QColor(0xff, 0xff, 0xff));
256 p.setColor(QPalette::ButtonText,QColor(0x23, 0x26, 0x29));
257 p.setColor(QPalette::Base,QColor(0xff, 0xff, 0xff));
258 p.setColor(QPalette::Window,QColor(0xef, 0xf0, 0xf1));
259 p.setColor(QPalette::Shadow,QColor(0x76, 0x76, 0x76));
260 p.setColor(QPalette::Highlight,QColor(0x3d, 0xae, 0xe9));
261 p.setColor(QPalette::HighlightedText,QColor(0xff, 0xff, 0xff));
262 p.setColor(QPalette::Link,QColor(0x29, 0x80, 0xb9));
263 p.setColor(QPalette::LinkVisited,QColor(0x9b, 0x59, 0xb6));
271 QString errorMessage;
273 if (errorMessage.isNull())
287 #if defined(Q_OS_WIN) || defined(Q_OS_MAC)
289 QStringLiteral(
"sword.conf")));
290 if (file.exists() || !file.open(QIODevice::WriteOnly |
QIODevice::Text))
292 QTextStream out(&file);
294 out <<
"[Install]\n";
295 #if defined(Q_OS_WIN)
296 out <<
"DataPath=" << QDir::toNativeSeparators(util::directory::getSharedSwordDir().absolutePath()) <<
"\n";
297 out <<
"LocalePath=" << QDir::toNativeSeparators(util::directory::getApplicationSwordDir().absolutePath()) <<
"\n";
298 #elif defined(Q_OS_MAC)
304 sword::SWLog::getSystemLog()->setLogLevel(
btApp->debugMode()
305 ? sword::SWLog::LOG_DEBUG
306 : sword::SWLog::LOG_ERROR);
310 qDebug() <<
"Using sword locales dir: " << util::directory::getSwordLocalesDir().absolutePath().toUtf8();
311 sword::LocaleMgr::setSystemLocaleMgr(
new sword::LocaleMgr(util::directory::getSwordLocalesDir().absolutePath().toUtf8()));
#define MY_OUTPUT_LITERAL(literal)
BtConfig & btConfig()
This is a shortchand for BtConfig::getInstance().
bool initDisplayTemplateManager()
std::optional< CSwordBackend > m_backend
BibleTimeApp(int &argc, char **argv)
void initLightDarkPalette()
T value(QString const &key, T const &defaultValue=T()) const
Returns the settings value for the given global key.
void setValue(QString const &key, T const &value)
Sets a value for a key.
static InitState initBtConfig()
static void destroyInstance()
static void forceMigrate()
static BtConfig * m_instance
singleton instance
@ INIT_NEED_UNIMPLEMENTED_FORWARD_MIGRATE
@ INIT_NEED_UNIMPLEMENTED_BACKWARD_MIGRATE
static void resetLanguage()
static CDisplayTemplateMgr * instance()
QStringList r(content.left(bodyIndex))
void myMessageOutput(QtMsgType type, QMessageLogContext const &, QString const &message)
std::unique_ptr< QFile > debugStream
QMessageBox::StandardButton showCritical(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QMessageBox::StandardButton showWarning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
const QDir & getUserHomeSwordDir()