File indexing completed on 2024-06-23 05:45:41
0001 /* 0002 * Copyright 2020 Han Young <hanyoung@protonmail.com> 0003 * Copyright 2020-2021 Devin Lin <devin@kde.org> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "settingsmodel.h" 0009 0010 #include <KLocalizedString> 0011 0012 #include <QDebug> 0013 0014 SettingsModel::SettingsModel() 0015 : m_interface(new LocalKClockSettingsInterface(QStringLiteral("org.kde.kclockd"), QStringLiteral("/Settings"), QDBusConnection::sessionBus())) 0016 { 0017 m_timeFormat = m_interface->timeFormat(); 0018 0019 connect(m_interface, &LocalKClockSettingsInterface::timeFormatChanged, this, [this]() { 0020 QString timeFormat = m_interface->timeFormat(); 0021 0022 if (timeFormat != m_timeFormat) { 0023 m_timeFormat = timeFormat; 0024 Q_EMIT timeFormatChanged(); 0025 } 0026 }); 0027 } 0028 0029 SettingsModel *SettingsModel::instance() 0030 { 0031 static SettingsModel *singleton = new SettingsModel(); 0032 return singleton; 0033 } 0034 0035 QString SettingsModel::timeFormat() const 0036 { 0037 return m_timeFormat; 0038 } 0039 0040 void SettingsModel::setTimeFormat(QString timeFormat) 0041 { 0042 m_interface->setProperty("timeFormat", timeFormat); 0043 }