This commit is contained in:
parent
ed136d3b9a
commit
c6036e4d2d
@ -85,8 +85,9 @@ static void slack_method_call (GDBusConnection *connection, const gchar *sender,
|
||||
}
|
||||
else if (g_strcmp0(method_name, "ListTimezones") == 0)
|
||||
{
|
||||
auto return_value = Glib::Variant<std::vector<Glib::ustring>>::create({});
|
||||
auto return_tuple = Glib::Variant<std::vector<Glib::ustring>>::create_tuple({ return_value });
|
||||
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());
|
||||
}
|
||||
@ -165,6 +166,39 @@ int main(int argc, char **argv)
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
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;
|
||||
auto zoneinfo_path = std::filesystem::path(zoneinfo_database) / prefix;
|
||||
auto zoneinfo_directory = Glib::Dir(zoneinfo_path);
|
||||
|
||||
for (auto zoneinfo_entry : zoneinfo_directory)
|
||||
{
|
||||
auto entry_path = zoneinfo_path / zoneinfo_entry;
|
||||
|
||||
if (Glib::file_test(entry_path, is_directory))
|
||||
{
|
||||
list_timezones(prefix + zoneinfo_entry + "/", accumulator);
|
||||
}
|
||||
else if (Glib::file_test(entry_path, is_regular) && !entry_path.has_extension()
|
||||
&& zoneinfo_entry != "leapseconds")
|
||||
{
|
||||
accumulator.push_back(prefix + zoneinfo_entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Glib::Variant<std::vector<Glib::ustring>> list_timezones()
|
||||
{
|
||||
std::vector<Glib::ustring> result;
|
||||
|
||||
list_timezones("", result);
|
||||
return Glib::Variant<std::vector<Glib::ustring>>::create(result);
|
||||
}
|
||||
}
|
||||
|
||||
gchar *slack_get_timezone () {
|
||||
gchar *zone_copied_from, *zone;
|
||||
|
@ -59,6 +59,13 @@
|
||||
constexpr gint32 USEC_PER_SEC = 1000000ULL;
|
||||
constexpr gint32 NSEC_PER_USEC = 1000ULL;
|
||||
|
||||
namespace dlackware::timedate
|
||||
{
|
||||
constexpr const char *zoneinfo_database = "/usr/share/zoneinfo";
|
||||
|
||||
Glib::Variant<std::vector<Glib::ustring>> list_timezones();
|
||||
}
|
||||
|
||||
// Returns the system time zone
|
||||
gchar *slack_get_timezone ();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user