File indexing completed on 2024-05-12 05:38:17
0001 /* 0002 SPDX-FileCopyrightText: 2015 Martin Klapetek <mklapetek@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "holidayeventshelperplugin.h" 0008 0009 #include <QDebug> 0010 #include <qqml.h> 0011 0012 #include <KConfigGroup> 0013 #include <KSharedConfig> 0014 0015 class QmlConfigHelper : public QObject 0016 { 0017 Q_OBJECT 0018 Q_PROPERTY(QStringList selectedRegions READ selectedRegions NOTIFY selectedRegionsChanged) 0019 0020 public: 0021 explicit QmlConfigHelper(QObject *parent = nullptr) 0022 : QObject(parent) 0023 { 0024 KSharedConfig::Ptr config = KSharedConfig::openConfig(QStringLiteral("plasma_calendar_holiday_regions")); 0025 m_configGroup = config->group(QStringLiteral("General")); 0026 m_regions = m_configGroup.readEntry("selectedRegions", QStringList()); 0027 } 0028 0029 QStringList selectedRegions() const 0030 { 0031 return m_regions; 0032 } 0033 0034 Q_INVOKABLE void saveConfig() 0035 { 0036 m_configGroup.writeEntry("selectedRegions", m_regions, KConfig::Notify); 0037 m_configGroup.sync(); 0038 } 0039 0040 Q_INVOKABLE void addRegion(const QString ®ion) 0041 { 0042 if (!m_regions.contains(region)) { 0043 m_regions.append(region); 0044 Q_EMIT selectedRegionsChanged(); 0045 } 0046 } 0047 0048 Q_INVOKABLE void removeRegion(const QString ®ion) 0049 { 0050 if (m_regions.removeOne(region)) { 0051 Q_EMIT selectedRegionsChanged(); 0052 } 0053 } 0054 0055 Q_SIGNALS: 0056 void selectedRegionsChanged(); 0057 0058 private: 0059 QStringList m_regions; 0060 KConfigGroup m_configGroup; 0061 }; 0062 0063 void HolidayEventsHelperPlugin::registerTypes(const char *uri) 0064 { 0065 qmlRegisterType<QmlConfigHelper>(uri, 1, 0, "QmlConfigHelper"); 0066 } 0067 0068 #include "holidayeventshelperplugin.moc"