diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 93c1f77..2e8ec92 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -1,5 +1,7 @@ find_program(SED sed) +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/resources.h.in" "resources.h") + add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/org.freedesktop.timedate1.service COMMAND ${SED} -e s|@LIBEXECDIR@|${CMAKE_INSTALL_FULL_LIBEXECDIR}| ${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.timedate1.service.in > ${PROJECT_BINARY_DIR}/org.freedesktop.timedate1.service MAIN_DEPENDENCY org.freedesktop.timedate1.service.in diff --git a/data/resources.h.in b/data/resources.h.in new file mode 100644 index 0000000..3885bf2 --- /dev/null +++ b/data/resources.h.in @@ -0,0 +1 @@ +#define DATADIR_INTERFACES "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_DATADIR@/dbus-1/interfaces" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c626a41..81bf237 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,7 +4,7 @@ pkg_check_modules(GDBUS REQUIRED gio-2.0 dbus-1 glibmm-2.4 giomm-2.4) add_executable(slack-timedate main.cpp timedate.cpp timedate.h ) -target_include_directories(slack-timedate PRIVATE ${GDBUS_INCLUDE_DIRS}) +target_include_directories(slack-timedate PRIVATE ${CMAKE_BINARY_DIR}/data ${GDBUS_INCLUDE_DIRS}) target_link_libraries(slack-timedate ${GDBUS_LIBRARIES}) install(TARGETS slack-timedate DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}) diff --git a/src/main.cpp b/src/main.cpp index bd6c0c0..f57f020 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,7 +30,8 @@ int main(int argc, char **argv) Gio::init(); auto timedate1 = std::make_unique(); - guint owner_id = Gio::DBus::own_name(Gio::DBus::BUS_TYPE_SYSTEM, BUS_NAME, + guint owner_id = Gio::DBus::own_name(Gio::DBus::BUS_TYPE_SYSTEM, + Glib::ustring(dlackware::timedate::bus_name.cbegin(), dlackware::timedate::bus_name.cend()), std::bind(&dlackware::timedate::timedate1::on_bus_acquired, timedate1.get(), std::placeholders::_1, std::placeholders::_2), Gio::DBus::SlotNameAcquired(), diff --git a/src/timedate.cpp b/src/timedate.cpp index a320384..b06cbcc 100644 --- a/src/timedate.cpp +++ b/src/timedate.cpp @@ -120,6 +120,9 @@ static void slack_get_property(Glib::VariantBase& result, const Glib::RefPtr& connection, const Glib::ustring& name) { Glib::RefPtr introspection_data; - try { - auto introspection_xml = Glib::file_get_contents(dlackware::timedate::introspection_xml); - + auto introspection_xml = Glib::file_get_contents( + (std::filesystem::path(DATADIR_INTERFACES) / dlackware::timedate::bus_name).concat(".xml") + ); introspection_data = Gio::DBus::NodeInfo::create_for_xml(introspection_xml); } catch (Glib::Error& slack_err) @@ -194,7 +197,7 @@ namespace dlackware::timedate { return nullptr; } - return Glib::ustring{ zone_copied_from.get() + strlen(zoneinfo_database) + 1 }; + return Glib::ustring{ zone_copied_from.get() + zoneinfo_database.size() + 1 }; } void set_timezone(const Glib::ustring& zone, bool) diff --git a/src/timedate.h b/src/timedate.h index 82336de..49883f9 100644 --- a/src/timedate.h +++ b/src/timedate.h @@ -20,17 +20,13 @@ #include #include #include - -#define BUS_NAME "org.freedesktop.timedate1" +#include "resources.h" namespace dlackware::timedate { constexpr const char *bus_path = "/org/freedesktop/timedate1"; - constexpr const char *zoneinfo_database = "/usr/share/zoneinfo"; - constexpr const char *introspection_xml = "/usr/share/dbus-1/interfaces/org.freedesktop.timedate1.xml"; - - constexpr const gint32 usec_per_sec = 1000000ULL; - constexpr const gint32 nsec_per_usec = 1000ULL; + constexpr const std::string_view bus_name = "org.freedesktop.timedate1"; + constexpr const std::string_view zoneinfo_database = "/usr/share/zoneinfo"; // Returns the system time zone. Glib::ustring timezone();