Skip to content

Commit bacacad

Browse files
committed
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.
1 parent 1b50a53 commit bacacad

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/datetime/time.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Time::Time(QObject *parent)
3232
OrgFreedesktopTimedate1Interface iface(QStringLiteral("org.freedesktop.timedate1"),
3333
QStringLiteral("/org/freedesktop/timedate1"),
3434
QDBusConnection::systemBus());
35+
36+
m_canNTP = iface.canNTP();
3537
m_useNtp = iface.nTP();
3638
}
3739

@@ -40,6 +42,11 @@ bool Time::useNtp() const
4042
return m_useNtp;
4143
}
4244

45+
bool Time::canNTP() const
46+
{
47+
return m_canNTP;
48+
}
49+
4350
void Time::setUseNtp(bool enabled)
4451
{
4552
if (m_useNtp != enabled) {

src/datetime/time.h

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Time : public QObject
2929
{
3030
Q_OBJECT
3131
Q_PROPERTY(bool useNtp READ useNtp WRITE setUseNtp NOTIFY useNtpChanged)
32+
Q_PROPERTY(bool canNTP READ canNTP CONSTANT)
3233
Q_PROPERTY(QTime currentTime READ currentTime WRITE setCurrentTime NOTIFY currentTimeChanged)
3334
Q_PROPERTY(QDate currentDate READ currentDate WRITE setCurrentDate NOTIFY currentDateChanged)
3435
Q_PROPERTY(bool twentyFour READ twentyFour WRITE setTwentyFour NOTIFY twentyFourChanged)
@@ -37,6 +38,7 @@ class Time : public QObject
3738
explicit Time(QObject *parent = nullptr);
3839

3940
bool useNtp() const;
41+
bool canNTP() const;
4042
void setUseNtp(bool enabled);
4143

4244
Q_INVOKABLE void save();
@@ -57,6 +59,7 @@ class Time : public QObject
5759
void twentyFourChanged();
5860

5961
private:
62+
bool m_canNTP;
6063
bool m_useNtp;
6164
bool m_twentyFour;
6265
QTime m_currentTime;

src/qml/DateTime/Main.qml

+11
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,22 @@ ItemPage {
6464
Layout.fillHeight: true
6565
rightPadding: 0
6666
rightInset: 0
67+
checkable: time.canNTP
6768
checked: time.useNtp
6869
onCheckedChanged: time.useNtp = checked
6970
}
7071
}
7172

73+
Label {
74+
text: qsTr("Unable to use Auto Sync. Please ensure your NTP service is installed.")
75+
color: FishUI.Theme.disabledTextColor
76+
visible: !time.canNTP
77+
}
78+
}
79+
80+
RoundedItem {
81+
spacing: FishUI.Units.largeSpacing * 1.5
82+
7283
RowLayout {
7384
Label {
7485
text: qsTr("24-Hour Time")

0 commit comments

Comments
 (0)