File indexing completed on 2024-05-19 15:10:51
0001 /* 0002 SPDX-FileCopyrightText: 2017 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #include "kemoticonsglobal_p.h" 0008 #include <QDBusMessage> 0009 #include <KConfigGroup> 0010 #include <KSharedConfig> 0011 #include <QDBusConnection> 0012 #include "kemoticons_core_debug.h" 0013 0014 static const char s_dbusPath[] = "/KEmoticons"; 0015 static const char s_dbusInterface[] = "org.kde.kf5.KEmoticons"; 0016 static const char s_themeChangedSignal[] = "emoticonsThemeChanged"; 0017 static const char s_parseModeChangedSignal[] = "emoticonsParseModeChanged"; 0018 0019 KEmoticonsGlobal::KEmoticonsGlobal() 0020 { 0021 KConfigGroup config(KSharedConfig::openConfig(), "Emoticons"); 0022 m_themeName = config.readEntry("emoticonsTheme", "Breeze"); 0023 m_parseMode = static_cast<KEmoticonsTheme::ParseMode>(config.readEntry("parseMode", int(KEmoticonsTheme::RelaxedParse))); 0024 0025 QDBusConnection dbus = QDBusConnection::sessionBus(); 0026 dbus.connect(QString(), QString::fromLatin1(s_dbusPath), QString::fromLatin1(s_dbusInterface), QString::fromLatin1(s_themeChangedSignal), this, SLOT(slotEmoticonsThemeChanged(QString))); 0027 dbus.connect(QString(), QString::fromLatin1(s_dbusPath), QString::fromLatin1(s_dbusInterface), QString::fromLatin1(s_parseModeChangedSignal), this, SLOT(slotEmoticonsParseModeChanged(int))); 0028 } 0029 0030 void KEmoticonsGlobal::setThemeName(const QString &name) 0031 { 0032 m_themeName = name; 0033 0034 KConfigGroup config(KSharedConfig::openConfig(), "Emoticons"); 0035 config.writeEntry("emoticonsTheme", m_themeName, KConfigBase::Persistent | KConfigBase::Global); 0036 config.sync(); 0037 0038 // Inform running apps 0039 QDBusMessage message = QDBusMessage::createSignal(QString::fromLatin1(s_dbusPath), QString::fromLatin1(s_dbusInterface), QString::fromLatin1(s_themeChangedSignal)); 0040 message << name; 0041 if (!QDBusConnection::sessionBus().send(message)) { 0042 qCWarning(KEMOTICONS_CORE) << "Error sending dbus signal" << s_themeChangedSignal; 0043 } 0044 } 0045 0046 void KEmoticonsGlobal::setParseMode(KEmoticonsTheme::ParseMode mode) 0047 { 0048 m_parseMode = mode; 0049 0050 KConfigGroup config(KSharedConfig::openConfig(), "Emoticons"); 0051 config.writeEntry("parseMode", static_cast<int>(mode), KConfigBase::Persistent | KConfigBase::Global); 0052 config.sync(); 0053 0054 // Inform running apps 0055 QDBusMessage message = QDBusMessage::createSignal(QString::fromLatin1(s_dbusPath), QString::fromLatin1(s_dbusInterface), QString::fromLatin1(s_parseModeChangedSignal)); 0056 message << static_cast<int>(mode); 0057 if (!QDBusConnection::sessionBus().send(message)) { 0058 qCWarning(KEMOTICONS_CORE) << "Error sending dbus signal" << s_parseModeChangedSignal; 0059 } 0060 } 0061 0062 void KEmoticonsGlobal::slotEmoticonsThemeChanged(const QString &name) 0063 { 0064 m_themeName = name; 0065 } 0066 0067 void KEmoticonsGlobal::slotEmoticonsParseModeChanged(int mode) 0068 { 0069 m_parseMode = static_cast<KEmoticonsTheme::ParseMode>(mode); 0070 } 0071 0072 #include "moc_kemoticonsglobal_p.cpp"