Remove deprecated g_type_init

This commit is contained in:
Eugen Wissner 2024-04-19 10:14:53 +02:00
parent 75fd7cf0cc
commit 33819d2eb9
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
3 changed files with 45 additions and 42 deletions

View File

@ -7,7 +7,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(CMAKE_CXX_STANDARD 17)
find_package(PkgConfig)
pkg_check_modules(GDBUS REQUIRED gio-2.0 dbus-1)
pkg_check_modules(GDBUS REQUIRED gio-2.0 dbus-1 glibmm-2.4)
find_program(SED sed)
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/org.freedesktop.timedate1.service

View File

@ -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;
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;
rc_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
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");
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);
}
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;
}
/* 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;
}
}

View File

@ -17,6 +17,7 @@
*/
#include <dbus/dbus.h>
#include <glibmm.h>
#include <gio/gio.h>
#define BUS_NAME "org.freedesktop.timedate1"