diff options
| author | Eugen Wissner <belka@caraus.de> | 2024-04-19 10:14:53 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2024-04-19 10:14:53 +0200 |
| commit | 33819d2eb9b09bde8b72027adb5476eae68e1c74 (patch) | |
| tree | b492650ee83504215b85b618884f1670b5ea2209 /slack-timedate.cpp | |
| parent | 75fd7cf0ccb3682eb634c4a717e4c987b750f44f (diff) | |
| download | slack-timedate-33819d2eb9b09bde8b72027adb5476eae68e1c74.tar.gz | |
Remove deprecated g_type_init
Diffstat (limited to 'slack-timedate.cpp')
| -rw-r--r-- | slack-timedate.cpp | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/slack-timedate.cpp b/slack-timedate.cpp index 9c07ebe..607736f 100644 --- a/slack-timedate.cpp +++ b/slack-timedate.cpp @@ -16,6 +16,7 @@ * */ +#include <filesystem> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -117,18 +118,14 @@ static void on_timedate_lost (GDBusConnection *connection, const gchar *name, gp exit (1); } -gboolean timeout_callback (gpointer loop2quit) { - g_main_loop_quit ((GMainLoop *)loop2quit); - return FALSE; +gboolean timeout_callback (Glib::RefPtr<Glib::MainLoop> loop2quit) { + loop2quit->quit(); + return false; } -int main (int argc, char **argv) { - guint owner_id; - GMainLoop *loop; - - g_type_init (); - - owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM, +int main(int argc, char **argv) +{ + guint owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM, BUS_NAME, static_cast<GBusNameOwnerFlags>(G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | G_BUS_NAME_OWNER_FLAGS_REPLACE), on_timedate_acquired, @@ -136,10 +133,10 @@ int main (int argc, char **argv) { on_timedate_lost, NULL, NULL); + Glib::RefPtr<Glib::MainLoop> loop = Glib::MainLoop::create(false); - loop = g_main_loop_new (NULL, FALSE); - g_timeout_add_seconds (DEFAULT_EXIT_SEC, timeout_callback , loop); - g_main_loop_run (loop); + Glib::signal_timeout().connect_seconds(sigc::bind(&timeout_callback, loop), DEFAULT_EXIT_SEC); + loop->run(); g_bus_unown_name (owner_id); @@ -164,7 +161,8 @@ gboolean slack_set_timezone (gchar *zone) { GFile *etc_localtime, *localtime_link, *g_zone_file; zone_file = g_strconcat ("/usr/share/zoneinfo/", zone, NULL); - if (g_file_test (zone_file, G_FILE_TEST_IS_REGULAR)) { + if (Glib::file_test(zone_file, Glib::FILE_TEST_IS_REGULAR)) + { etc_localtime = g_file_new_for_path ("/etc/localtime"); localtime_link = g_file_new_for_path ("/etc/localtime-copied-from"); g_zone_file = g_file_new_for_path (zone_file); @@ -184,10 +182,10 @@ gboolean slack_set_timezone (gchar *zone) { g_object_unref (etc_localtime); g_object_unref (localtime_link); g_object_unref (g_zone_file); - } else { - return FALSE; + + return true; } - return TRUE; + return false; } gboolean slack_set_time(gint64 seconds_since_epoch, gboolean relative) @@ -237,32 +235,36 @@ gboolean slack_get_is_localtime () { return is_localtime; } -gboolean slack_get_ntp () { - if (g_file_test ("/etc/rc.d/rc.ntpd", G_FILE_TEST_IS_EXECUTABLE)) - return TRUE; - else return FALSE; +gboolean slack_get_ntp() +{ + return Glib::file_test("/etc/rc.d/rc.ntpd", Glib::FileTest::FILE_TEST_IS_EXECUTABLE); } -gboolean slack_set_ntp (gboolean xntp) { - mode_t rc_mode; - - rc_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; - - if (xntp) { - rc_mode |= S_IXUSR | S_IXGRP | S_IXOTH; - g_message ("Please don't forget to configure the NTP daemon"); - - /* It doesn't matter if fails. - * The ntpdate command is considered obsolete, but "orthodox" ntpd -g - * will fail if your system clock is off for more than half an hour. */ - g_spawn_command_line_async ("/usr/sbin/ntpdate pool.ntp.org", NULL); - } +gboolean slack_set_ntp(gboolean xntp) +{ + std::filesystem::perms rc_mode = std::filesystem::perms::owner_read | std::filesystem::perms::owner_write + | std::filesystem::perms::group_read | std::filesystem::perms::others_read; - if (g_file_test ("/etc/rc.d/rc.ntpd", G_FILE_TEST_IS_REGULAR)) { - if (chmod ("/etc/rc.d/rc.ntpd", rc_mode)) return FALSE; - else return TRUE; - } else { - g_error ("The NTP daemon isn't installed"); - return FALSE; - } + if (xntp) + { + rc_mode |= std::filesystem::perms::owner_exec + | std::filesystem::perms::group_exec | std::filesystem::perms::others_exec; + g_message("Please don't forget to configure the NTP daemon"); + + /* It doesn't matter if fails. + * The ntpdate command is considered obsolete, but "orthodox" ntpd -g + * will fail if your system clock is off for more than half an hour. */ + g_spawn_command_line_async("/usr/sbin/ntpdate pool.ntp.org", NULL); + } + if (Glib::file_test("/etc/rc.d/rc.ntpd", Glib::FileTest::FILE_TEST_IS_REGULAR)) + { + std::error_code ec; + std::filesystem::permissions("/etc/rc.d/rc.ntpd", rc_mode, ec); + return !ec; + } + else + { + g_error("The NTP daemon isn't installed"); + return false; + } } |
