application: Use the GcalContext internally

Most was left as it is, such as the "manager" property.
This commit is contained in:
Georges Basile Stavracas Neto
2019-04-24 12:55:20 -03:00
parent 9a13fb5c2a
commit beeecdf6b3
2 changed files with 52 additions and 29 deletions
+49 -29
View File
@@ -42,8 +42,6 @@ struct _GcalApplication
GtkWidget *window; GtkWidget *window;
GcalManager *manager;
GtkCssProvider *provider; GtkCssProvider *provider;
GtkCssProvider *colors_provider; GtkCssProvider *colors_provider;
@@ -57,7 +55,7 @@ struct _GcalApplication
GcalShellSearchProvider *search_provider; GcalShellSearchProvider *search_provider;
GcalNightLightMonitor *night_light_monitor; GcalNightLightMonitor *night_light_monitor;
GcalClock *clock; GcalContext *context;
}; };
static void gcal_application_launch_search (GSimpleAction *search, static void gcal_application_launch_search (GSimpleAction *search,
@@ -119,7 +117,7 @@ static const GActionEntry gcal_app_entries[] = {
enum enum
{ {
PROP_0, PROP_0,
PROP_CLOCK, PROP_CONTEXT,
PROP_MANAGER, PROP_MANAGER,
PROP_TIME_FORMAT, PROP_TIME_FORMAT,
PROP_WEATHER_SERVICE, PROP_WEATHER_SERVICE,
@@ -134,6 +132,7 @@ process_sources (GcalApplication *self)
g_autoptr (GError) error = NULL; g_autoptr (GError) error = NULL;
g_autofree gchar *new_css_data = NULL; g_autofree gchar *new_css_data = NULL;
g_auto (GStrv) new_css_snippets = NULL; g_auto (GStrv) new_css_snippets = NULL;
GcalManager *manager;
GList *sources, *l; GList *sources, *l;
ESource *source; ESource *source;
GQuark color_id; GQuark color_id;
@@ -141,8 +140,8 @@ process_sources (GcalApplication *self)
gint arr_length; gint arr_length;
gint i = 0; gint i = 0;
manager = gcal_context_get_manager (self->context);
sources = gcal_manager_get_sources_connected (self->manager); sources = gcal_manager_get_sources_connected (manager);
arr_length = g_list_length (sources); arr_length = g_list_length (sources);
new_css_snippets = g_new0 (gchar*, arr_length + 2); new_css_snippets = g_new0 (gchar*, arr_length + 2);
for (l = sources; l != NULL; l = g_list_next (l), i++) for (l = sources; l != NULL; l = g_list_next (l), i++)
@@ -227,10 +226,9 @@ gcal_application_finalize (GObject *object)
g_clear_pointer (&self->initial_date, g_free); g_clear_pointer (&self->initial_date, g_free);
g_clear_pointer (&self->uuid, g_free); g_clear_pointer (&self->uuid, g_free);
g_clear_object (&self->context);
g_clear_object (&self->colors_provider); g_clear_object (&self->colors_provider);
g_clear_object (&self->clock);
g_clear_object (&self->desktop_settings); g_clear_object (&self->desktop_settings);
g_clear_object (&self->manager);
g_clear_object (&self->night_light_monitor); g_clear_object (&self->night_light_monitor);
g_clear_object (&self->provider); g_clear_object (&self->provider);
g_clear_object (&self->search_provider); g_clear_object (&self->search_provider);
@@ -251,12 +249,12 @@ gcal_application_get_property (GObject *object,
switch (property_id) switch (property_id)
{ {
case PROP_CLOCK: case PROP_CONTEXT:
g_value_set_object (value, self->clock); g_value_set_object (value, self->context);
break; break;
case PROP_MANAGER: case PROP_MANAGER:
g_value_set_object (value, self->manager); g_value_set_object (value, gcal_context_get_manager (self->context));
break; break;
case PROP_TIME_FORMAT: case PROP_TIME_FORMAT:
@@ -280,10 +278,12 @@ static void
gcal_application_activate (GApplication *application) gcal_application_activate (GApplication *application)
{ {
GcalApplication *self; GcalApplication *self;
GcalManager *manager;
GCAL_ENTRY; GCAL_ENTRY;
self = GCAL_APPLICATION (application); self = GCAL_APPLICATION (application);
manager = gcal_context_get_manager (self->context);
if (!self->provider) if (!self->provider)
load_css_provider (self); load_css_provider (self);
@@ -296,7 +296,7 @@ gcal_application_activate (GApplication *application)
} }
if (!self->night_light_monitor) if (!self->night_light_monitor)
self->night_light_monitor = gcal_night_light_monitor_new (self->manager); self->night_light_monitor = gcal_night_light_monitor_new (manager);
if (!self->window) if (!self->window)
{ {
@@ -304,7 +304,7 @@ gcal_application_activate (GApplication *application)
{ {
icaltimezone *tz; icaltimezone *tz;
tz = gcal_manager_get_system_timezone (self->manager); tz = gcal_manager_get_system_timezone (manager);
self->initial_date = g_new0 (icaltimetype, 1); self->initial_date = g_new0 (icaltimetype, 1);
*self->initial_date = icaltime_current_time_with_zone (tz); *self->initial_date = icaltime_current_time_with_zone (tz);
@@ -313,7 +313,7 @@ gcal_application_activate (GApplication *application)
self->window = g_object_new (GCAL_TYPE_WINDOW, self->window = g_object_new (GCAL_TYPE_WINDOW,
"application", self, "application", self,
"manager", self->manager, "manager", manager,
"active-date", self->initial_date, "active-date", self->initial_date,
"weather-service", self->weather_service, "weather-service", self->weather_service,
"time-format", self->time_format, "time-format", self->time_format,
@@ -372,7 +372,7 @@ gcal_application_startup (GApplication *app)
load_time_format (self); load_time_format (self);
/* Startup the manager */ /* Startup the manager */
gcal_manager_startup (self->manager); gcal_manager_startup (gcal_context_get_manager (self->context));
/* We're assuming the application is called as a service only by the shell search system */ /* We're assuming the application is called as a service only by the shell search system */
if ((g_application_get_flags (app) & G_APPLICATION_IS_SERVICE) != 0) if ((g_application_get_flags (app) & G_APPLICATION_IS_SERVICE) != 0)
@@ -421,12 +421,13 @@ gcal_application_command_line (GApplication *app,
if (e_time_parse_date_and_time (date, &result) == E_TIME_PARSE_OK) if (e_time_parse_date_and_time (date, &result) == E_TIME_PARSE_OK)
{ {
GcalManager *manager = gcal_context_get_manager (self->context);
if (!self->initial_date) if (!self->initial_date)
self->initial_date = g_new0 (icaltimetype, 1); self->initial_date = g_new0 (icaltimetype, 1);
*self->initial_date = tm_to_icaltimetype (&result, FALSE); *self->initial_date = tm_to_icaltimetype (&result, FALSE);
*self->initial_date = icaltime_set_timezone (self->initial_date, *self->initial_date = icaltime_set_timezone (self->initial_date,
gcal_manager_get_system_timezone (self->manager)); gcal_manager_get_system_timezone (manager));
} }
g_variant_unref (option); g_variant_unref (option);
@@ -516,11 +517,11 @@ gcal_application_class_init (GcalApplicationClass *klass)
application_class->dbus_register = gcal_application_dbus_register; application_class->dbus_register = gcal_application_dbus_register;
application_class->dbus_unregister = gcal_application_dbus_unregister; application_class->dbus_unregister = gcal_application_dbus_unregister;
properties[PROP_CLOCK] = g_param_spec_object ("clock", properties[PROP_CONTEXT] = g_param_spec_object ("context",
"Clock", "Context",
"The internal clock of Calendar", "Context",
GCAL_TYPE_CLOCK, GCAL_TYPE_CONTEXT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
properties[PROP_MANAGER] = g_param_spec_object ("manager", properties[PROP_MANAGER] = g_param_spec_object ("manager",
"The manager object", "The manager object",
@@ -547,14 +548,17 @@ gcal_application_class_init (GcalApplicationClass *klass)
static void static void
gcal_application_init (GcalApplication *self) gcal_application_init (GcalApplication *self)
{ {
GcalManager *manager;
g_application_add_main_option_entries (G_APPLICATION (self), gcal_application_goptions); g_application_add_main_option_entries (G_APPLICATION (self), gcal_application_goptions);
self->clock = gcal_clock_new (); self->context = gcal_context_new ();
self->manager = gcal_manager_new ();
g_signal_connect_swapped (self->manager, "source-added", G_CALLBACK (process_sources), self);
g_signal_connect_swapped (self->manager, "source-changed", G_CALLBACK (process_sources), self);
self->search_provider = gcal_shell_search_provider_new (self->manager); manager = gcal_context_get_manager (self->context);
g_signal_connect_swapped (manager, "source-added", G_CALLBACK (process_sources), self);
g_signal_connect_swapped (manager, "source-changed", G_CALLBACK (process_sources), self);
self->search_provider = gcal_shell_search_provider_new (manager);
} }
static void static void
@@ -563,7 +567,7 @@ gcal_application_sync (GSimpleAction *sync,
gpointer app) gpointer app)
{ {
GcalApplication *self = GCAL_APPLICATION (app); GcalApplication *self = GCAL_APPLICATION (app);
gcal_manager_refresh (self->manager); gcal_manager_refresh (gcal_context_get_manager (self->context));
gcal_weather_service_update (self->weather_service); gcal_weather_service_update (self->weather_service);
} }
@@ -686,6 +690,22 @@ gcal_application_new (void)
NULL); NULL);
} }
/**
* gcal_application_get_context:
* @self: a #GcalApplication
*
* Retrieves the #GcalContext of the application.
*
* Returns: (transfer none): a #GcalContext
*/
GcalContext*
gcal_application_get_context (GcalApplication *self)
{
g_return_val_if_fail (GCAL_IS_APPLICATION (self), NULL);
return self->context;
}
/** /**
* gcal_application_get_manager: * gcal_application_get_manager:
* @self: a #GcalApplication * @self: a #GcalApplication
@@ -699,7 +719,7 @@ gcal_application_get_manager (GcalApplication *self)
{ {
g_return_val_if_fail (GCAL_IS_APPLICATION (self), NULL); g_return_val_if_fail (GCAL_IS_APPLICATION (self), NULL);
return self->manager; return gcal_context_get_manager (self->context);
} }
/** /**
@@ -743,5 +763,5 @@ gcal_application_get_clock (GcalApplication *self)
{ {
g_return_val_if_fail (GCAL_IS_APPLICATION (self), NULL); g_return_val_if_fail (GCAL_IS_APPLICATION (self), NULL);
return self->clock; return gcal_context_get_clock (self->context);
} }
+3
View File
@@ -21,6 +21,7 @@
#define _GCAL_APPLICATION_H_ #define _GCAL_APPLICATION_H_
#include "gcal-clock.h" #include "gcal-clock.h"
#include "gcal-context.h"
#include "gcal-weather-service.h" #include "gcal-weather-service.h"
#include "gcal-manager.h" #include "gcal-manager.h"
@@ -34,6 +35,8 @@ G_DECLARE_FINAL_TYPE (GcalApplication, gcal_application, GCAL, APPLICATION, GtkA
GcalApplication* gcal_application_new (void); GcalApplication* gcal_application_new (void);
GcalContext* gcal_application_get_context (GcalApplication *self);
GcalManager* gcal_application_get_manager (GcalApplication *self); GcalManager* gcal_application_get_manager (GcalApplication *self);
GcalWeatherService* gcal_application_get_weather_service (GcalApplication *self); GcalWeatherService* gcal_application_get_weather_service (GcalApplication *self);