feat(datetime): Check availability of Auto Sync and indicate when it is not available

If systemd-timesyncd (Debian package name) is not installed on the user's computer,
set the option as unavailable and display a line of prompt text.
main
reion 2 years ago
parent 1b50a530f0
commit bacacad6a4

@ -32,6 +32,8 @@ Time::Time(QObject *parent)
OrgFreedesktopTimedate1Interface iface(QStringLiteral("org.freedesktop.timedate1"),
QStringLiteral("/org/freedesktop/timedate1"),
QDBusConnection::systemBus());
m_canNTP = iface.canNTP();
m_useNtp = iface.nTP();
}
@ -40,6 +42,11 @@ bool Time::useNtp() const
return m_useNtp;
}
bool Time::canNTP() const
{
return m_canNTP;
}
void Time::setUseNtp(bool enabled)
{
if (m_useNtp != enabled) {

@ -29,6 +29,7 @@ class Time : public QObject
{
Q_OBJECT
Q_PROPERTY(bool useNtp READ useNtp WRITE setUseNtp NOTIFY useNtpChanged)
Q_PROPERTY(bool canNTP READ canNTP CONSTANT)
Q_PROPERTY(QTime currentTime READ currentTime WRITE setCurrentTime NOTIFY currentTimeChanged)
Q_PROPERTY(QDate currentDate READ currentDate WRITE setCurrentDate NOTIFY currentDateChanged)
Q_PROPERTY(bool twentyFour READ twentyFour WRITE setTwentyFour NOTIFY twentyFourChanged)
@ -37,6 +38,7 @@ public:
explicit Time(QObject *parent = nullptr);
bool useNtp() const;
bool canNTP() const;
void setUseNtp(bool enabled);
Q_INVOKABLE void save();
@ -57,6 +59,7 @@ signals:
void twentyFourChanged();
private:
bool m_canNTP;
bool m_useNtp;
bool m_twentyFour;
QTime m_currentTime;

@ -64,11 +64,22 @@ ItemPage {
Layout.fillHeight: true
rightPadding: 0
rightInset: 0
checkable: time.canNTP
checked: time.useNtp
onCheckedChanged: time.useNtp = checked
}
}
Label {
text: qsTr("Unable to use Auto Sync. Please ensure your NTP service is installed.")
color: FishUI.Theme.disabledTextColor
visible: !time.canNTP
}
}
RoundedItem {
spacing: FishUI.Units.largeSpacing * 1.5
RowLayout {
Label {
text: qsTr("24-Hour Time")

Loading…
Cancel
Save