/* TimeMonitor.c generated by valac 0.56.19, the Vala compiler
 * generated from TimeMonitor.vala, do not modify */

/*
 * Copyright © 2023 Alain M. (https://github.com/alainm23/planify)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * Authored by: Alain M. <alainmh23@gmail.com>
 */

#include <glib-object.h>
#include <glib.h>
#include "planify.h"
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <gio/gio.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define SERVICES_TYPE_TIME_MONITOR (services_time_monitor_get_type ())
#define SERVICES_TIME_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SERVICES_TYPE_TIME_MONITOR, ServicesTimeMonitor))
#define SERVICES_TIME_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SERVICES_TYPE_TIME_MONITOR, ServicesTimeMonitorClass))
#define SERVICES_IS_TIME_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SERVICES_TYPE_TIME_MONITOR))
#define SERVICES_IS_TIME_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SERVICES_TYPE_TIME_MONITOR))
#define SERVICES_TIME_MONITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SERVICES_TYPE_TIME_MONITOR, ServicesTimeMonitorClass))

typedef struct _ServicesTimeMonitor ServicesTimeMonitor;
typedef struct _ServicesTimeMonitorClass ServicesTimeMonitorClass;
typedef struct _ServicesTimeMonitorPrivate ServicesTimeMonitorPrivate;
enum  {
	SERVICES_TIME_MONITOR_0_PROPERTY,
	SERVICES_TIME_MONITOR_NUM_PROPERTIES
};
static GParamSpec* services_time_monitor_properties[SERVICES_TIME_MONITOR_NUM_PROPERTIES];
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

#define SERVICES_TYPE_NOTIFICATION (services_notification_get_type ())
#define SERVICES_NOTIFICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SERVICES_TYPE_NOTIFICATION, ServicesNotification))
#define SERVICES_NOTIFICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SERVICES_TYPE_NOTIFICATION, ServicesNotificationClass))
#define SERVICES_IS_NOTIFICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SERVICES_TYPE_NOTIFICATION))
#define SERVICES_IS_NOTIFICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SERVICES_TYPE_NOTIFICATION))
#define SERVICES_NOTIFICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SERVICES_TYPE_NOTIFICATION, ServicesNotificationClass))

typedef struct _ServicesNotification ServicesNotification;
typedef struct _ServicesNotificationClass ServicesNotificationClass;

struct _ServicesTimeMonitor {
	GObject parent_instance;
	ServicesTimeMonitorPrivate * priv;
};

struct _ServicesTimeMonitorClass {
	GObjectClass parent_class;
};

struct _ServicesTimeMonitorPrivate {
	GDateTime* last_registered_date;
	guint midnight_timeout_id;
};

static gint ServicesTimeMonitor_private_offset;
static gpointer services_time_monitor_parent_class = NULL;
static ServicesTimeMonitor* services_time_monitor__instance;
static ServicesTimeMonitor* services_time_monitor__instance = NULL;

VALA_EXTERN GType services_time_monitor_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ServicesTimeMonitor, g_object_unref)
VALA_EXTERN ServicesTimeMonitor* services_time_monitor_get_default (void);
VALA_EXTERN ServicesTimeMonitor* services_time_monitor_new (void);
VALA_EXTERN ServicesTimeMonitor* services_time_monitor_construct (GType object_type);
VALA_EXTERN void services_time_monitor_init_timeout (ServicesTimeMonitor* self);
static void services_time_monitor_schedule_midnight_check (ServicesTimeMonitor* self);
static void services_time_monitor_listen_for_system_resume (ServicesTimeMonitor* self);
static gboolean __lambda957_ (ServicesTimeMonitor* self);
static void services_time_monitor_check_day_change (ServicesTimeMonitor* self);
static gboolean ___lambda957__gsource_func (gpointer self);
static void ____lambda958_ (ServicesTimeMonitor* self,
                     GDBusConnection* conn,
                     const gchar* sender,
                     const gchar* path,
                     const gchar* iface,
                     const gchar* signal_name,
                     GVariant* parameters);
static void _____lambda958__gd_bus_signal_callback (GDBusConnection* connection,
                                             const gchar* sender_name,
                                             const gchar* object_path,
                                             const gchar* interface_name,
                                             const gchar* signal_name,
                                             GVariant* parameters,
                                             gpointer self);
static void ____lambda959_ (ServicesTimeMonitor* self,
                     GDBusConnection* conn,
                     const gchar* sender,
                     const gchar* path,
                     const gchar* iface,
                     const gchar* signal_name,
                     GVariant* parameters);
static void _____lambda959__gd_bus_signal_callback (GDBusConnection* connection,
                                             const gchar* sender_name,
                                             const gchar* object_path,
                                             const gchar* interface_name,
                                             const gchar* signal_name,
                                             GVariant* parameters,
                                             gpointer self);
VALA_EXTERN GType services_notification_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ServicesNotification, g_object_unref)
VALA_EXTERN ServicesNotification* services_notification_get_default (void);
VALA_EXTERN void services_notification_regresh (ServicesNotification* self);
static void services_time_monitor_finalize (GObject * obj);
static GType services_time_monitor_get_type_once (void);

static inline gpointer
services_time_monitor_get_instance_private (ServicesTimeMonitor* self)
{
	return G_STRUCT_MEMBER_P (self, ServicesTimeMonitor_private_offset);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

ServicesTimeMonitor*
services_time_monitor_get_default (void)
{
	ServicesTimeMonitor* _tmp0_;
	ServicesTimeMonitor* _tmp2_;
	ServicesTimeMonitor* _tmp3_;
	ServicesTimeMonitor* result;
	_tmp0_ = services_time_monitor__instance;
	if (_tmp0_ == NULL) {
		ServicesTimeMonitor* _tmp1_;
		_tmp1_ = services_time_monitor_new ();
		_g_object_unref0 (services_time_monitor__instance);
		services_time_monitor__instance = _tmp1_;
	}
	_tmp2_ = services_time_monitor__instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

void
services_time_monitor_init_timeout (ServicesTimeMonitor* self)
{
	GDateTime* _tmp0_;
	ServicesLogService* _tmp1_;
	ServicesLogService* _tmp2_;
	GDateTime* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_date_time_new_now_local ();
	_g_date_time_unref0 (self->priv->last_registered_date);
	self->priv->last_registered_date = _tmp0_;
	_tmp1_ = services_log_service_get_default ();
	_tmp2_ = _tmp1_;
	_tmp3_ = self->priv->last_registered_date;
	_tmp4_ = g_date_time_format (_tmp3_, "%Y-%m-%d");
	_tmp5_ = _tmp4_;
	_tmp6_ = g_strdup_printf ("Initialized, tracking date: %s", _tmp5_);
	_tmp7_ = _tmp6_;
	services_log_service_info (_tmp2_, "TimeMonitor", _tmp7_);
	_g_free0 (_tmp7_);
	_g_free0 (_tmp5_);
	_g_object_unref0 (_tmp2_);
	services_time_monitor_schedule_midnight_check (self);
	services_time_monitor_listen_for_system_resume (self);
}

static gboolean
__lambda957_ (ServicesTimeMonitor* self)
{
	gboolean result;
	self->priv->midnight_timeout_id = (guint) 0;
	services_time_monitor_check_day_change (self);
	services_time_monitor_schedule_midnight_check (self);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda957__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda957_ ((ServicesTimeMonitor*) self);
	return result;
}

static void
services_time_monitor_schedule_midnight_check (ServicesTimeMonitor* self)
{
	GDateTime* now = NULL;
	GDateTime* _tmp0_;
	GDateTime* tomorrow = NULL;
	GDateTime* _tmp1_;
	GDateTime* midnight = NULL;
	GDateTime* _tmp2_;
	gint seconds = 0;
	ServicesLogService* _tmp3_;
	ServicesLogService* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	g_return_if_fail (self != NULL);
	if (self->priv->midnight_timeout_id != ((guint) 0)) {
		g_source_remove (self->priv->midnight_timeout_id);
		self->priv->midnight_timeout_id = (guint) 0;
	}
	_tmp0_ = g_date_time_new_now_local ();
	now = _tmp0_;
	_tmp1_ = g_date_time_add_days (now, 1);
	tomorrow = _tmp1_;
	_tmp2_ = g_date_time_new_local (g_date_time_get_year (tomorrow), g_date_time_get_month (tomorrow), g_date_time_get_day_of_month (tomorrow), 0, 0, (gdouble) 0);
	midnight = _tmp2_;
	seconds = (gint) (g_date_time_difference (midnight, now) / G_TIME_SPAN_SECOND);
	_tmp3_ = services_log_service_get_default ();
	_tmp4_ = _tmp3_;
	_tmp5_ = g_strdup_printf ("Next day check scheduled in %d seconds", seconds);
	_tmp6_ = _tmp5_;
	services_log_service_info (_tmp4_, "TimeMonitor", _tmp6_);
	_g_free0 (_tmp6_);
	_g_object_unref0 (_tmp4_);
	self->priv->midnight_timeout_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) seconds, ___lambda957__gsource_func, g_object_ref (self), g_object_unref);
	_g_date_time_unref0 (midnight);
	_g_date_time_unref0 (tomorrow);
	_g_date_time_unref0 (now);
}

static void
____lambda958_ (ServicesTimeMonitor* self,
                GDBusConnection* conn,
                const gchar* sender,
                const gchar* path,
                const gchar* iface,
                const gchar* signal_name,
                GVariant* parameters)
{
	gboolean going_to_sleep = FALSE;
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (conn != NULL);
	g_return_if_fail (path != NULL);
	g_return_if_fail (iface != NULL);
	g_return_if_fail (signal_name != NULL);
	g_return_if_fail (parameters != NULL);
	g_variant_get (parameters, "(b)", &_tmp0_, NULL);
	going_to_sleep = _tmp0_;
	if (going_to_sleep) {
		ServicesLogService* _tmp1_;
		ServicesLogService* _tmp2_;
		_tmp1_ = services_log_service_get_default ();
		_tmp2_ = _tmp1_;
		services_log_service_info (_tmp2_, "TimeMonitor", "System going to sleep");
		_g_object_unref0 (_tmp2_);
	} else {
		ServicesLogService* _tmp3_;
		ServicesLogService* _tmp4_;
		_tmp3_ = services_log_service_get_default ();
		_tmp4_ = _tmp3_;
		services_log_service_info (_tmp4_, "TimeMonitor", "System resumed from sleep (logind), checking day change");
		_g_object_unref0 (_tmp4_);
		services_time_monitor_check_day_change (self);
		services_time_monitor_schedule_midnight_check (self);
	}
}

static void
_____lambda958__gd_bus_signal_callback (GDBusConnection* connection,
                                        const gchar* sender_name,
                                        const gchar* object_path,
                                        const gchar* interface_name,
                                        const gchar* signal_name,
                                        GVariant* parameters,
                                        gpointer self)
{
	____lambda958_ ((ServicesTimeMonitor*) self, connection, sender_name, object_path, interface_name, signal_name, parameters);
}

static void
____lambda959_ (ServicesTimeMonitor* self,
                GDBusConnection* conn,
                const gchar* sender,
                const gchar* path,
                const gchar* iface,
                const gchar* signal_name,
                GVariant* parameters)
{
	ServicesLogService* _tmp0_;
	ServicesLogService* _tmp1_;
	g_return_if_fail (conn != NULL);
	g_return_if_fail (path != NULL);
	g_return_if_fail (iface != NULL);
	g_return_if_fail (signal_name != NULL);
	g_return_if_fail (parameters != NULL);
	_tmp0_ = services_log_service_get_default ();
	_tmp1_ = _tmp0_;
	services_log_service_info (_tmp1_, "TimeMonitor", "Screen woke up (ScreenSaver), checking day change");
	_g_object_unref0 (_tmp1_);
	services_time_monitor_check_day_change (self);
	services_time_monitor_schedule_midnight_check (self);
}

static void
_____lambda959__gd_bus_signal_callback (GDBusConnection* connection,
                                        const gchar* sender_name,
                                        const gchar* object_path,
                                        const gchar* interface_name,
                                        const gchar* signal_name,
                                        GVariant* parameters,
                                        gpointer self)
{
	____lambda959_ ((ServicesTimeMonitor*) self, connection, sender_name, object_path, interface_name, signal_name, parameters);
}

static void
services_time_monitor_listen_for_system_resume (ServicesTimeMonitor* self)
{
	Util* _tmp0_;
	Util* _tmp1_;
	gboolean _tmp2_;
	Util* _tmp13_;
	Util* _tmp14_;
	gboolean _tmp15_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = util_get_default ();
	_tmp1_ = _tmp0_;
	_tmp2_ = !util_is_flatpak (_tmp1_);
	_g_object_unref0 (_tmp1_);
	if (_tmp2_) {
		{
			GDBusConnection* system_bus = NULL;
			GDBusConnection* _tmp3_;
			GDBusConnection* _tmp4_;
			ServicesLogService* _tmp5_;
			ServicesLogService* _tmp6_;
			_tmp3_ = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &_inner_error0_);
			system_bus = _tmp3_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp4_ = system_bus;
			g_dbus_connection_signal_subscribe (_tmp4_, "org.freedesktop.login1", "org.freedesktop.login1.Manager", "PrepareForSleep", "/org/freedesktop/login1", NULL, G_DBUS_SIGNAL_FLAGS_NONE, _____lambda958__gd_bus_signal_callback, g_object_ref (self), g_object_unref);
			_tmp5_ = services_log_service_get_default ();
			_tmp6_ = _tmp5_;
			services_log_service_info (_tmp6_, "TimeMonitor", "Subscribed to logind PrepareForSleep signal");
			_g_object_unref0 (_tmp6_);
			_g_object_unref0 (system_bus);
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			ServicesLogService* _tmp7_;
			ServicesLogService* _tmp8_;
			GError* _tmp9_;
			const gchar* _tmp10_;
			gchar* _tmp11_;
			gchar* _tmp12_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp7_ = services_log_service_get_default ();
			_tmp8_ = _tmp7_;
			_tmp9_ = e;
			_tmp10_ = _tmp9_->message;
			_tmp11_ = g_strdup_printf ("Could not subscribe to logind: %s", _tmp10_);
			_tmp12_ = _tmp11_;
			services_log_service_warn (_tmp8_, "TimeMonitor", _tmp12_);
			_g_free0 (_tmp12_);
			_g_object_unref0 (_tmp8_);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
	}
	_tmp13_ = util_get_default ();
	_tmp14_ = _tmp13_;
	_tmp15_ = util_is_flatpak (_tmp14_);
	_g_object_unref0 (_tmp14_);
	if (_tmp15_) {
		{
			GDBusConnection* session_bus = NULL;
			GDBusConnection* _tmp16_;
			GDBusConnection* _tmp17_;
			ServicesLogService* _tmp18_;
			ServicesLogService* _tmp19_;
			_tmp16_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_);
			session_bus = _tmp16_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch1_g_error;
			}
			_tmp17_ = session_bus;
			g_dbus_connection_signal_subscribe (_tmp17_, "org.gnome.ScreenSaver", "org.gnome.ScreenSaver", "WakeUpScreen", "/org/gnome/ScreenSaver", NULL, G_DBUS_SIGNAL_FLAGS_NONE, _____lambda959__gd_bus_signal_callback, g_object_ref (self), g_object_unref);
			_tmp18_ = services_log_service_get_default ();
			_tmp19_ = _tmp18_;
			services_log_service_info (_tmp19_, "TimeMonitor", "Subscribed to ScreenSaver WakeUpScreen signal");
			_g_object_unref0 (_tmp19_);
			_g_object_unref0 (session_bus);
		}
		goto __finally1;
		__catch1_g_error:
		{
			GError* e = NULL;
			ServicesLogService* _tmp20_;
			ServicesLogService* _tmp21_;
			GError* _tmp22_;
			const gchar* _tmp23_;
			gchar* _tmp24_;
			gchar* _tmp25_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp20_ = services_log_service_get_default ();
			_tmp21_ = _tmp20_;
			_tmp22_ = e;
			_tmp23_ = _tmp22_->message;
			_tmp24_ = g_strdup_printf ("Could not subscribe to ScreenSaver: %s", _tmp23_);
			_tmp25_ = _tmp24_;
			services_log_service_warn (_tmp21_, "TimeMonitor", _tmp25_);
			_g_free0 (_tmp25_);
			_g_object_unref0 (_tmp21_);
			_g_error_free0 (e);
		}
		__finally1:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
	}
}

static gpointer
_g_date_time_ref0 (gpointer self)
{
	return self ? g_date_time_ref (self) : NULL;
}

static void
services_time_monitor_check_day_change (ServicesTimeMonitor* self)
{
	GDateTime* now = NULL;
	GDateTime* _tmp0_;
	ServicesLogService* _tmp1_;
	ServicesLogService* _tmp2_;
	GDateTime* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GDateTime* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gboolean _tmp11_ = FALSE;
	gboolean _tmp12_ = FALSE;
	GDateTime* _tmp13_;
	GDateTime* _tmp14_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_date_time_new_now_local ();
	now = _tmp0_;
	_tmp1_ = services_log_service_get_default ();
	_tmp2_ = _tmp1_;
	_tmp3_ = self->priv->last_registered_date;
	_tmp4_ = g_date_time_format (_tmp3_, "%Y-%m-%d");
	_tmp5_ = _tmp4_;
	_tmp6_ = now;
	_tmp7_ = g_date_time_format (_tmp6_, "%Y-%m-%d");
	_tmp8_ = _tmp7_;
	_tmp9_ = g_strdup_printf ("Checking day change: last=%s now=%s", _tmp5_, _tmp8_);
	_tmp10_ = _tmp9_;
	services_log_service_debug (_tmp2_, "TimeMonitor", _tmp10_);
	_g_free0 (_tmp10_);
	_g_free0 (_tmp8_);
	_g_free0 (_tmp5_);
	_g_object_unref0 (_tmp2_);
	_tmp13_ = now;
	_tmp14_ = self->priv->last_registered_date;
	if (g_date_time_get_day_of_month (_tmp13_) != g_date_time_get_day_of_month (_tmp14_)) {
		_tmp12_ = TRUE;
	} else {
		GDateTime* _tmp15_;
		GDateTime* _tmp16_;
		_tmp15_ = now;
		_tmp16_ = self->priv->last_registered_date;
		_tmp12_ = g_date_time_get_month (_tmp15_) != g_date_time_get_month (_tmp16_);
	}
	if (_tmp12_) {
		_tmp11_ = TRUE;
	} else {
		GDateTime* _tmp17_;
		GDateTime* _tmp18_;
		_tmp17_ = now;
		_tmp18_ = self->priv->last_registered_date;
		_tmp11_ = g_date_time_get_year (_tmp17_) != g_date_time_get_year (_tmp18_);
	}
	if (_tmp11_) {
		ServicesLogService* _tmp19_;
		ServicesLogService* _tmp20_;
		GDateTime* _tmp21_;
		gchar* _tmp22_;
		gchar* _tmp23_;
		GDateTime* _tmp24_;
		gchar* _tmp25_;
		gchar* _tmp26_;
		gchar* _tmp27_;
		gchar* _tmp28_;
		ServicesEventBus* _tmp29_;
		ServicesEventBus* _tmp30_;
		ServicesNotification* _tmp31_;
		ServicesNotification* _tmp32_;
		GDateTime* _tmp33_;
		GDateTime* _tmp34_;
		_tmp19_ = services_log_service_get_default ();
		_tmp20_ = _tmp19_;
		_tmp21_ = self->priv->last_registered_date;
		_tmp22_ = g_date_time_format (_tmp21_, "%Y-%m-%d");
		_tmp23_ = _tmp22_;
		_tmp24_ = now;
		_tmp25_ = g_date_time_format (_tmp24_, "%Y-%m-%d");
		_tmp26_ = _tmp25_;
		_tmp27_ = g_strdup_printf ("Day changed from %s to %s", _tmp23_, _tmp26_);
		_tmp28_ = _tmp27_;
		services_log_service_info (_tmp20_, "TimeMonitor", _tmp28_);
		_g_free0 (_tmp28_);
		_g_free0 (_tmp26_);
		_g_free0 (_tmp23_);
		_g_object_unref0 (_tmp20_);
		_tmp29_ = services_event_bus_get_default ();
		_tmp30_ = _tmp29_;
		g_signal_emit_by_name (_tmp30_, "day-changed");
		_g_object_unref0 (_tmp30_);
		_tmp31_ = services_notification_get_default ();
		_tmp32_ = _tmp31_;
		services_notification_regresh (_tmp32_);
		_g_object_unref0 (_tmp32_);
		_tmp33_ = now;
		_tmp34_ = _g_date_time_ref0 (_tmp33_);
		_g_date_time_unref0 (self->priv->last_registered_date);
		self->priv->last_registered_date = _tmp34_;
	}
	_g_date_time_unref0 (now);
}

ServicesTimeMonitor*
services_time_monitor_construct (GType object_type)
{
	ServicesTimeMonitor * self = NULL;
	self = (ServicesTimeMonitor*) g_object_new (object_type, NULL);
	return self;
}

ServicesTimeMonitor*
services_time_monitor_new (void)
{
	return services_time_monitor_construct (SERVICES_TYPE_TIME_MONITOR);
}

static void
services_time_monitor_class_init (ServicesTimeMonitorClass * klass,
                                  gpointer klass_data)
{
	services_time_monitor_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ServicesTimeMonitor_private_offset);
	G_OBJECT_CLASS (klass)->finalize = services_time_monitor_finalize;
}

static void
services_time_monitor_instance_init (ServicesTimeMonitor * self,
                                     gpointer klass)
{
	self->priv = services_time_monitor_get_instance_private (self);
	self->priv->midnight_timeout_id = (guint) 0;
}

static void
services_time_monitor_finalize (GObject * obj)
{
	ServicesTimeMonitor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SERVICES_TYPE_TIME_MONITOR, ServicesTimeMonitor);
	_g_date_time_unref0 (self->priv->last_registered_date);
	G_OBJECT_CLASS (services_time_monitor_parent_class)->finalize (obj);
}

static GType
services_time_monitor_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ServicesTimeMonitorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) services_time_monitor_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ServicesTimeMonitor), 0, (GInstanceInitFunc) services_time_monitor_instance_init, NULL };
	GType services_time_monitor_type_id;
	services_time_monitor_type_id = g_type_register_static (G_TYPE_OBJECT, "ServicesTimeMonitor", &g_define_type_info, 0);
	ServicesTimeMonitor_private_offset = g_type_add_instance_private (services_time_monitor_type_id, sizeof (ServicesTimeMonitorPrivate));
	return services_time_monitor_type_id;
}

GType
services_time_monitor_get_type (void)
{
	static volatile gsize services_time_monitor_type_id__once = 0;
	if (g_once_init_enter (&services_time_monitor_type_id__once)) {
		GType services_time_monitor_type_id;
		services_time_monitor_type_id = services_time_monitor_get_type_once ();
		g_once_init_leave (&services_time_monitor_type_id__once, services_time_monitor_type_id);
	}
	return services_time_monitor_type_id__once;
}

