Skip to content

Commit

Permalink
feat(datetime): Check availability of Auto Sync and indicate when it …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
reionwong committed Aug 1, 2024
1 parent 1b50a53 commit bacacad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/datetime/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/datetime/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -37,6 +38,7 @@ class Time : public QObject
explicit Time(QObject *parent = nullptr);

bool useNtp() const;
bool canNTP() const;
void setUseNtp(bool enabled);

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

private:
bool m_canNTP;
bool m_useNtp;
bool m_twentyFour;
QTime m_currentTime;
Expand Down
11 changes: 11 additions & 0 deletions src/qml/DateTime/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit bacacad

Please sign in to comment.