File indexing completed on 2025-01-19 04:46:54

0001 /*
0002    SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "grantleeheaderstyleinterface.h"
0008 #include <GrantleeTheme/GrantleeThemeManager>
0009 #include <KToggleAction>
0010 #include <MessageViewer/HeaderStyle>
0011 #include <MessageViewer/HeaderStylePlugin>
0012 
0013 using namespace MessageViewer;
0014 GrantleeHeaderStyleInterface::GrantleeHeaderStyleInterface(MessageViewer::HeaderStylePlugin *plugin, QObject *parent)
0015     : MessageViewer::HeaderStyleInterface(plugin, parent)
0016 {
0017 }
0018 
0019 GrantleeHeaderStyleInterface::~GrantleeHeaderStyleInterface()
0020 {
0021     if (mThemeManager) {
0022         mThemeManager->setThemeMenu(nullptr);
0023         mThemeManager->setActionGroup(nullptr);
0024     }
0025 }
0026 
0027 void GrantleeHeaderStyleInterface::createAction(KActionMenu *menu, QActionGroup *actionGroup, KActionCollection *ac)
0028 {
0029     mThemeManager = new GrantleeTheme::ThemeManager(QStringLiteral("mail"),
0030                                                     QStringLiteral("header.desktop"),
0031                                                     ac,
0032                                                     QStringLiteral("messageviewer/themes/"),
0033                                                     QStringLiteral("messageviewer_header_themes.knsrc"),
0034                                                     this);
0035     connect(mThemeManager, &GrantleeTheme::ThemeManager::grantleeThemeSelected, this, &GrantleeHeaderStyleInterface::slotGrantleeHeaders);
0036     connect(mThemeManager, &GrantleeTheme::ThemeManager::updateThemes, this, &HeaderStyleInterface::styleUpdated);
0037 
0038     mThemeManager->setActionGroup(actionGroup);
0039     mThemeManager->setThemeMenu(menu);
0040     const QString themeName = mThemeManager->configuredThemeName();
0041     mHeaderStylePlugin->headerStyle()->setTheme(mThemeManager->theme(themeName));
0042     addActionToMenu(menu, actionGroup);
0043 }
0044 
0045 void GrantleeHeaderStyleInterface::activateAction()
0046 {
0047     KToggleAction *act = mThemeManager->actionForTheme();
0048     if (act) {
0049         act->setChecked(true);
0050     }
0051 }
0052 
0053 void GrantleeHeaderStyleInterface::slotGrantleeHeaders()
0054 {
0055     const QString themeName = mThemeManager->configuredThemeName();
0056     mHeaderStylePlugin->headerStyle()->setTheme(mThemeManager->theme(themeName));
0057     slotStyleChanged();
0058 }
0059 
0060 #include "moc_grantleeheaderstyleinterface.cpp"