File indexing completed on 2024-05-05 05:36:41
0001 /* 0002 0003 SPDX-FileCopyrightText: 2011-2015 Sebastian Kügler <sebas@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef TIMESETTINGS_H 0009 #define TIMESETTINGS_H 0010 0011 #include <QDate> 0012 #include <QIcon> 0013 #include <QObject> 0014 #include <QStringListModel> 0015 #include <QTime> 0016 #include <QVariant> 0017 0018 #include <KConfigGroup> 0019 #include <KSharedConfig> 0020 0021 #include <KQuickConfigModule> 0022 0023 #include <QCoroQmlTask> 0024 #include <QCoroTask> 0025 0026 #include "timezonemodel.h" 0027 0028 // #include "settingsmodule.h" 0029 0030 class TimeSettingsPrivate; 0031 0032 /** 0033 * @class TimeSettings A class to manage time and date related settings. This class serves two functions: 0034 * - Provide a plugin implementation 0035 * - Provide a settings module 0036 * This is done from one class in order to simplify the code. You can export any QObject-based 0037 * class through qmlRegisterType(), however. 0038 */ 0039 class TimeSettings : public KQuickConfigModule 0040 { 0041 Q_OBJECT 0042 0043 Q_PROPERTY(QString timeFormat READ timeFormat WRITE setTimeFormat NOTIFY timeFormatChanged) 0044 Q_PROPERTY(bool twentyFour READ twentyFour WRITE setTwentyFour NOTIFY twentyFourChanged) 0045 Q_PROPERTY(QString timeZone READ timeZone WRITE setTimeZone NOTIFY timeZoneChanged) 0046 Q_PROPERTY(TimeZoneFilterProxy *timeZonesModel READ timeZonesModel WRITE setTimeZonesModel NOTIFY timeZonesModelChanged) 0047 Q_PROPERTY(QTime currentTime READ currentTime WRITE setCurrentTime NOTIFY currentTimeChanged) 0048 Q_PROPERTY(QDate currentDate READ currentDate WRITE setCurrentDate NOTIFY currentDateChanged) 0049 Q_PROPERTY(bool useNtp READ useNtp WRITE setUseNtp NOTIFY useNtpChanged) 0050 Q_PROPERTY(QString currentTimeText READ currentTimeText NOTIFY currentTimeTextChanged) 0051 Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged) 0052 0053 public: 0054 TimeSettings(QObject *parent, const KPluginMetaData &metaData); 0055 0056 QString currentTimeText(); 0057 QTime currentTime() const; 0058 void setCurrentTime(const QTime &time); 0059 0060 QDate currentDate() const; 0061 void setCurrentDate(const QDate &date); 0062 0063 bool useNtp() const; 0064 void setUseNtp(bool ntp); 0065 0066 QString timeFormat(); 0067 QString timeZone(); 0068 TimeZoneFilterProxy *timeZonesModel(); 0069 bool twentyFour(); 0070 0071 QString errorString(); 0072 0073 public Q_SLOTS: 0074 void setTimeZone(const QString &timezone); 0075 void setTimeZonesModel(TimeZoneFilterProxy *timezones); 0076 void setTimeFormat(const QString &timeFormat); 0077 void setTwentyFour(bool t); 0078 void timeout(); 0079 void saveTime(); 0080 void notify(); 0081 void saveTimeZone(const QString &newtimezone); 0082 0083 Q_SIGNALS: 0084 void currentTimeTextChanged(); 0085 void currentTimeChanged(); 0086 void currentDateChanged(); 0087 void twentyFourChanged(); 0088 void timeFormatChanged(); 0089 void timeZoneChanged(); 0090 void timeZonesChanged(); 0091 void timeZonesModelChanged(); 0092 void useNtpChanged(); 0093 void errorStringChanged(); 0094 0095 protected: 0096 QString findNtpUtility(); 0097 0098 private: 0099 QString m_timeFormat; 0100 QString m_timezone; 0101 TimeZoneFilterProxy *m_timeZonesModel; 0102 QString m_timeZoneFilter; 0103 QString m_currentTimeText; 0104 QTime m_currentTime; 0105 QDate m_currentDate; 0106 bool m_useNtp; 0107 QString m_errorString; 0108 0109 void initSettings(); 0110 void initTimeZones(); 0111 0112 KSharedConfig::Ptr m_localeConfig; 0113 KConfigGroup m_localeSettings; 0114 }; 0115 0116 #endif // TIMESETTINGS_H