Handle ListTimezones errors
All checks were successful
Build / build (push) Successful in 19s

This commit is contained in:
Eugen Wissner 2024-06-02 14:57:09 +02:00
parent c6036e4d2d
commit 263d91efb5
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
3 changed files with 25 additions and 9 deletions

View File

@ -39,8 +39,16 @@ to get the list of time zones:
```sh
dbus-send --system --print-reply --type=method_call \
--dest=org.freedesktop.timedate1 \
/org/freedesktop/timedate1 \
org.freedesktop.timedate1.ListTimezones
/org/freedesktop/timedate1 org.freedesktop.timedate1.ListTimezones
```
To get a value of a property:
```sh
dbus-send --system --print-reply \
--dest=org.freedesktop.timedate1 \
/org/freedesktop/timedate1 org.freedesktop.DBus.Properties.Get \
string:org.freedesktop.timedate1 string:NTP
```
## Dependencies

View File

@ -84,13 +84,20 @@ static void slack_method_call (GDBusConnection *connection, const gchar *sender,
}
}
else if (g_strcmp0(method_name, "ListTimezones") == 0)
{
try
{
auto return_tuple = Glib::Variant<std::vector<Glib::ustring>>::create_tuple({
dlackware::timedate::list_timezones()
});
g_dbus_method_invocation_return_value(invocation, return_tuple.gobj());
}
catch (const std::exception& exception)
{
g_dbus_method_invocation_return_error(invocation, G_IO_ERROR, G_IO_ERROR_FAILED,
"List time zones: %s", exception.what());
}
}
}
static GVariant *slack_get_property (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *prop_name, GError **slack_err, gpointer user_data) {
@ -170,8 +177,8 @@ namespace dlackware::timedate
{
void list_timezones(const std::string& prefix, std::vector<Glib::ustring>& accumulator)
{
Glib::FileTest is_directory = Glib::FILE_TEST_IS_DIR;
Glib::FileTest is_regular = Glib::FILE_TEST_IS_REGULAR;
constexpr Glib::FileTest is_directory = Glib::FILE_TEST_IS_DIR;
constexpr Glib::FileTest is_regular = Glib::FILE_TEST_IS_REGULAR;
auto zoneinfo_path = std::filesystem::path(zoneinfo_database) / prefix;
auto zoneinfo_directory = Glib::Dir(zoneinfo_path);

View File

@ -63,6 +63,7 @@ namespace dlackware::timedate
{
constexpr const char *zoneinfo_database = "/usr/share/zoneinfo";
void list_timezones(const std::string& prefix, std::vector<Glib::ustring>& accumulator);
Glib::Variant<std::vector<Glib::ustring>> list_timezones();
}