File indexing completed on 2024-12-08 04:33:28

0001 /*
0002 
0003  * SPDX-FileCopyrightText: 2016 Riccardo Iaconelli <riccardo@kde.org>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.0-or-later
0006  *
0007  */
0008 
0009 #include "ruqola.h"
0010 #include "accountmanager.h"
0011 #include "customemojiiconmanager.h"
0012 #include "managerdatapaths.h"
0013 #include "rocketchataccount.h"
0014 
0015 #include <KSharedConfig>
0016 
0017 #if HAVE_TEXT_AUTOCORRECTION_WIDGETS
0018 #include "textautocorrectioncore/textautocorrectionsettings.h"
0019 #include <TextAutoCorrectionCore/AutoCorrection>
0020 #endif
0021 
0022 static Ruqola *s_self = nullptr;
0023 
0024 Ruqola::Ruqola(QObject *parent)
0025     : QObject(parent)
0026 #if HAVE_TEXT_AUTOCORRECTION_WIDGETS
0027     , mAutoCorrection(new TextAutoCorrectionCore::AutoCorrection())
0028 #endif
0029     , mCustomEmojiIconManager(new CustomEmojiIconManager(this))
0030 {
0031     mDebug = !qEnvironmentVariableIsEmpty("RUQOLA_DEBUGGING");
0032     // Initialize paths
0033     (void)ManagerDataPaths::self();
0034     mAccountManager = new AccountManager(this);
0035 
0036 #if HAVE_TEXT_AUTOCORRECTION_WIDGETS
0037     TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setSharedConfig(KSharedConfig::openConfig());
0038     TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->load();
0039     mAutoCorrection->readConfig();
0040 #endif
0041 }
0042 
0043 Ruqola::~Ruqola()
0044 {
0045 #if HAVE_TEXT_AUTOCORRECTION_WIDGETS
0046     delete mAutoCorrection;
0047 #endif
0048 }
0049 
0050 Ruqola *Ruqola::self()
0051 {
0052     if (!s_self) {
0053         s_self = new Ruqola;
0054     }
0055     return s_self;
0056 }
0057 
0058 void Ruqola::destroy()
0059 {
0060     delete s_self;
0061     s_self = nullptr;
0062 }
0063 
0064 void Ruqola::openMessageUrl(const QString &url)
0065 {
0066     mAccountManager->openMessageUrl(url);
0067 }
0068 
0069 #if HAVE_TEXT_AUTOCORRECTION_WIDGETS
0070 TextAutoCorrectionCore::AutoCorrection *Ruqola::autoCorrection() const
0071 {
0072     return mAutoCorrection;
0073 }
0074 #endif
0075 
0076 CustomEmojiIconManager *Ruqola::customEmojiIconManager() const
0077 {
0078     return mCustomEmojiIconManager;
0079 }
0080 
0081 bool Ruqola::debug() const
0082 {
0083     return mDebug;
0084 }
0085 
0086 void Ruqola::setCurrentAccount(const QString &accountName)
0087 {
0088     mAccountManager->setCurrentAccount(accountName);
0089 }
0090 
0091 AccountManager *Ruqola::accountManager() const
0092 {
0093     return mAccountManager;
0094 }
0095 
0096 RocketChatAccount *Ruqola::rocketChatAccount() const
0097 {
0098     return mAccountManager->account();
0099 }
0100 
0101 #include "moc_ruqola.cpp"