File indexing completed on 2024-12-08 10:25:49

0001 /*
0002    SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "customemojiiconmanager.h"
0008 #include "emoticons/emojimanager.h"
0009 #include "rocketchataccount.h"
0010 
0011 CustomEmojiIconManager::CustomEmojiIconManager(QObject *parent)
0012     : TextEmoticonsCore::CustomEmojiIconManager{parent}
0013 {
0014 }
0015 
0016 CustomEmojiIconManager::~CustomEmojiIconManager()
0017 {
0018 }
0019 
0020 QIcon CustomEmojiIconManager::generateIcon(const QString &customIdentifier)
0021 {
0022     if (mCurrentRocketChatAccount) {
0023         const QString fileName = mCurrentRocketChatAccount->emojiManager()->customEmojiFileName(customIdentifier);
0024         //        qDebug() << " mCurrentRocketChatAccount " << mCurrentRocketChatAccount->accountName();
0025         //        qDebug() << " fileName " << fileName << "customIdentifier " << customIdentifier;
0026         if (!fileName.isEmpty()) {
0027             const QUrl emojiUrl = mCurrentRocketChatAccount->attachmentUrlFromLocalCache(fileName);
0028             //            qDebug() << " emojiUrl " << emojiUrl;
0029             if (!emojiUrl.isEmpty()) {
0030                 const QIcon icon(emojiUrl.toLocalFile());
0031                 return icon;
0032             }
0033         }
0034     }
0035     return {};
0036 }
0037 
0038 void CustomEmojiIconManager::setCurrentRocketChatAccount(RocketChatAccount *currentRocketChatAccount)
0039 {
0040     mCurrentRocketChatAccount = currentRocketChatAccount;
0041 }
0042 
0043 RocketChatAccount *CustomEmojiIconManager::currentRocketChatAccount() const
0044 {
0045     return mCurrentRocketChatAccount;
0046 }
0047 
0048 QString CustomEmojiIconManager::fileName(const QString &customIdentifier)
0049 {
0050     const QString fileName = mCurrentRocketChatAccount->emojiManager()->customEmojiFileName(customIdentifier);
0051     if (!fileName.isEmpty()) {
0052         const QUrl emojiUrl = mCurrentRocketChatAccount->attachmentUrlFromLocalCache(fileName);
0053         return emojiUrl.toLocalFile();
0054     }
0055     return {};
0056 }
0057 
0058 #include "moc_customemojiiconmanager.cpp"